GNU Radio Manual and C++ API Reference  3.7.7
The Free & Open Software Radio Ecosystem
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
volk_32fc_deinterleave_32f_x2.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2012, 2014 Free Software Foundation, Inc.
4  *
5  * This file is part of GNU Radio
6  *
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  *
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with GNU Radio; see the file COPYING. If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 /*!
24  * \page volk_32fc_deinterleave_32f_x2
25  *
26  * \b Overview
27  *
28  * Deinterleaves the complex floating point vector into I & Q vector
29  * data.
30  *
31  * <b>Dispatcher Prototype</b>
32  * \code
33  * void volk_32fc_deinterleave_32f_x2(float* iBuffer, float* qBuffer, const lv_32fc_t* complexVector, unsigned int num_points)
34  * \endcode
35  *
36  * \b Inputs
37  * \li complexVector: The complex input vector.
38  * \li num_points: The number of complex data values to be deinterleaved.
39  *
40  * \b Outputs
41  * \li iBuffer: The I buffer output data.
42  * \li qBuffer: The Q buffer output data.
43  *
44  * \b Example
45  * Generate complex numbers around the top half of the unit circle and
46  * deinterleave in to real and imaginary buffers.
47  * \code
48  * int N = 10;
49  * unsigned int alignment = volk_get_alignment();
50  * lv_32fc_t* in = (lv_32fc_t*)volk_malloc(sizeof(lv_32fc_t)*N, alignment);
51  * float* re = (float*)volk_malloc(sizeof(float)*N, alignment);
52  * float* im = (float*)volk_malloc(sizeof(float)*N, alignment);
53  *
54  * for(unsigned int ii = 0; ii < N; ++ii){
55  * float real = 2.f * ((float)ii / (float)N) - 1.f;
56  * float imag = std::sqrt(1.f - real * real);
57  * in[ii] = lv_cmake(real, imag);
58  * }
59  *
60  * volk_32fc_deinterleave_32f_x2(re, im, in, N);
61  *
62  * printf(" re | im\n");
63  * for(unsigned int ii = 0; ii < N; ++ii){
64  * printf("out(%i) = %+.1f | %+.1f\n", ii, re[ii], im[ii]);
65  * }
66  *
67  * volk_free(in);
68  * volk_free(re);
69  * volk_free(im);
70  * \endcode
71  */
72 
73 #ifndef INCLUDED_volk_32fc_deinterleave_32f_x2_a_H
74 #define INCLUDED_volk_32fc_deinterleave_32f_x2_a_H
75 
76 #include <inttypes.h>
77 #include <stdio.h>
78 
79 #ifdef LV_HAVE_AVX
80 #include <immintrin.h>
81 static inline void
82 volk_32fc_deinterleave_32f_x2_a_avx(float* iBuffer, float* qBuffer, const lv_32fc_t* complexVector,
83  unsigned int num_points)
84 {
85  const float* complexVectorPtr = (float*)complexVector;
86  float* iBufferPtr = iBuffer;
87  float* qBufferPtr = qBuffer;
88 
89  unsigned int number = 0;
90  // Mask for real and imaginary parts
91  const unsigned int eighthPoints = num_points / 8;
92  __m256 cplxValue1, cplxValue2, complex1, complex2, iValue, qValue;
93  for(;number < eighthPoints; number++){
94  cplxValue1 = _mm256_load_ps(complexVectorPtr);
95  complexVectorPtr += 8;
96 
97  cplxValue2 = _mm256_load_ps(complexVectorPtr);
98  complexVectorPtr += 8;
99 
100  complex1 = _mm256_permute2f128_ps(cplxValue1, cplxValue2, 0x20);
101  complex2 = _mm256_permute2f128_ps(cplxValue1, cplxValue2, 0x31);
102 
103  // Arrange in i1i2i3i4 format
104  iValue = _mm256_shuffle_ps(complex1, complex2, 0x88);
105  // Arrange in q1q2q3q4 format
106  qValue = _mm256_shuffle_ps(complex1, complex2, 0xdd);
107 
108  _mm256_store_ps(iBufferPtr, iValue);
109  _mm256_store_ps(qBufferPtr, qValue);
110 
111  iBufferPtr += 8;
112  qBufferPtr += 8;
113  }
114 
115  number = eighthPoints * 8;
116  for(; number < num_points; number++){
117  *iBufferPtr++ = *complexVectorPtr++;
118  *qBufferPtr++ = *complexVectorPtr++;
119  }
120 }
121 #endif /* LV_HAVE_AVX */
122 
123 #ifdef LV_HAVE_SSE
124 #include <xmmintrin.h>
125 
126 static inline void
127 volk_32fc_deinterleave_32f_x2_a_sse(float* iBuffer, float* qBuffer, const lv_32fc_t* complexVector,
128  unsigned int num_points)
129 {
130  const float* complexVectorPtr = (float*)complexVector;
131  float* iBufferPtr = iBuffer;
132  float* qBufferPtr = qBuffer;
133 
134  unsigned int number = 0;
135  const unsigned int quarterPoints = num_points / 4;
136  __m128 cplxValue1, cplxValue2, iValue, qValue;
137  for(;number < quarterPoints; number++){
138  cplxValue1 = _mm_load_ps(complexVectorPtr);
139  complexVectorPtr += 4;
140 
141  cplxValue2 = _mm_load_ps(complexVectorPtr);
142  complexVectorPtr += 4;
143 
144  // Arrange in i1i2i3i4 format
145  iValue = _mm_shuffle_ps(cplxValue1, cplxValue2, _MM_SHUFFLE(2,0,2,0));
146  // Arrange in q1q2q3q4 format
147  qValue = _mm_shuffle_ps(cplxValue1, cplxValue2, _MM_SHUFFLE(3,1,3,1));
148 
149  _mm_store_ps(iBufferPtr, iValue);
150  _mm_store_ps(qBufferPtr, qValue);
151 
152  iBufferPtr += 4;
153  qBufferPtr += 4;
154  }
155 
156  number = quarterPoints * 4;
157  for(; number < num_points; number++){
158  *iBufferPtr++ = *complexVectorPtr++;
159  *qBufferPtr++ = *complexVectorPtr++;
160  }
161 }
162 #endif /* LV_HAVE_SSE */
163 
164 
165 #ifdef LV_HAVE_NEON
166 #include <arm_neon.h>
167 
168 static inline void
169 volk_32fc_deinterleave_32f_x2_neon(float* iBuffer, float* qBuffer, const lv_32fc_t* complexVector,
170  unsigned int num_points)
171 {
172  unsigned int number = 0;
173  unsigned int quarter_points = num_points / 4;
174  const float* complexVectorPtr = (float*)complexVector;
175  float* iBufferPtr = iBuffer;
176  float* qBufferPtr = qBuffer;
177  float32x4x2_t complexInput;
178 
179  for(number = 0; number < quarter_points; number++){
180  complexInput = vld2q_f32(complexVectorPtr);
181  vst1q_f32( iBufferPtr, complexInput.val[0] );
182  vst1q_f32( qBufferPtr, complexInput.val[1] );
183  complexVectorPtr += 8;
184  iBufferPtr += 4;
185  qBufferPtr += 4;
186  }
187 
188  for(number = quarter_points*4; number < num_points; number++){
189  *iBufferPtr++ = *complexVectorPtr++;
190  *qBufferPtr++ = *complexVectorPtr++;
191  }
192 }
193 #endif /* LV_HAVE_NEON */
194 
195 
196 #ifdef LV_HAVE_GENERIC
197 
198 static inline void
199 volk_32fc_deinterleave_32f_x2_generic(float* iBuffer, float* qBuffer, const lv_32fc_t* complexVector,
200  unsigned int num_points)
201 {
202  const float* complexVectorPtr = (float*)complexVector;
203  float* iBufferPtr = iBuffer;
204  float* qBufferPtr = qBuffer;
205  unsigned int number;
206  for(number = 0; number < num_points; number++){
207  *iBufferPtr++ = *complexVectorPtr++;
208  *qBufferPtr++ = *complexVectorPtr++;
209  }
210 }
211 #endif /* LV_HAVE_GENERIC */
212 
213 #endif /* INCLUDED_volk_32fc_deinterleave_32f_x2_a_H */
float complex lv_32fc_t
Definition: volk_complex.h:56