Vector Optimized Library of Kernels  3.1.2
Architecture-tuned implementations of math kernels
volk_32fc_s32f_deinterleave_real_16i.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 VOLK
6  *
7  * SPDX-License-Identifier: LGPL-3.0-or-later
8  */
9 
60 #ifndef INCLUDED_volk_32fc_s32f_deinterleave_real_16i_a_H
61 #define INCLUDED_volk_32fc_s32f_deinterleave_real_16i_a_H
62 
63 #include <inttypes.h>
64 #include <stdio.h>
65 #include <volk/volk_common.h>
66 
67 
68 #ifdef LV_HAVE_AVX2
69 #include <immintrin.h>
70 
71 static inline void
72 volk_32fc_s32f_deinterleave_real_16i_a_avx2(int16_t* iBuffer,
73  const lv_32fc_t* complexVector,
74  const float scalar,
75  unsigned int num_points)
76 {
77  unsigned int number = 0;
78  const unsigned int eighthPoints = num_points / 8;
79 
80  const float* complexVectorPtr = (float*)complexVector;
81  int16_t* iBufferPtr = iBuffer;
82 
83  __m256 vScalar = _mm256_set1_ps(scalar);
84 
85  __m256 cplxValue1, cplxValue2, iValue;
86  __m256i a;
87  __m128i b;
88 
89  __m256i idx = _mm256_set_epi32(3, 3, 3, 3, 5, 1, 4, 0);
90 
91  for (; number < eighthPoints; number++) {
92  cplxValue1 = _mm256_load_ps(complexVectorPtr);
93  complexVectorPtr += 8;
94 
95  cplxValue2 = _mm256_load_ps(complexVectorPtr);
96  complexVectorPtr += 8;
97 
98  // Arrange in i1i2i3i4 format
99  iValue = _mm256_shuffle_ps(cplxValue1, cplxValue2, _MM_SHUFFLE(2, 0, 2, 0));
100 
101  iValue = _mm256_mul_ps(iValue, vScalar);
102 
103  a = _mm256_cvtps_epi32(iValue);
104  a = _mm256_packs_epi32(a, a);
105  a = _mm256_permutevar8x32_epi32(a, idx);
106  b = _mm256_extracti128_si256(a, 0);
107 
108  _mm_store_si128((__m128i*)iBufferPtr, b);
109  iBufferPtr += 8;
110  }
111 
112  number = eighthPoints * 8;
113  iBufferPtr = &iBuffer[number];
114  for (; number < num_points; number++) {
115  *iBufferPtr++ = (int16_t)rintf(*complexVectorPtr++ * scalar);
116  complexVectorPtr++;
117  }
118 }
119 
120 
121 #endif /* LV_HAVE_AVX2 */
122 
123 #ifdef LV_HAVE_SSE
124 #include <xmmintrin.h>
125 
126 static inline void
128  const lv_32fc_t* complexVector,
129  const float scalar,
130  unsigned int num_points)
131 {
132  unsigned int number = 0;
133  const unsigned int quarterPoints = num_points / 4;
134 
135  const float* complexVectorPtr = (float*)complexVector;
136  int16_t* iBufferPtr = iBuffer;
137 
138  __m128 vScalar = _mm_set_ps1(scalar);
139 
140  __m128 cplxValue1, cplxValue2, iValue;
141 
142  __VOLK_ATTR_ALIGNED(16) float floatBuffer[4];
143 
144  for (; number < quarterPoints; number++) {
145  cplxValue1 = _mm_load_ps(complexVectorPtr);
146  complexVectorPtr += 4;
147 
148  cplxValue2 = _mm_load_ps(complexVectorPtr);
149  complexVectorPtr += 4;
150 
151  // Arrange in i1i2i3i4 format
152  iValue = _mm_shuffle_ps(cplxValue1, cplxValue2, _MM_SHUFFLE(2, 0, 2, 0));
153 
154  iValue = _mm_mul_ps(iValue, vScalar);
155 
156  _mm_store_ps(floatBuffer, iValue);
157  *iBufferPtr++ = (int16_t)rintf(floatBuffer[0]);
158  *iBufferPtr++ = (int16_t)rintf(floatBuffer[1]);
159  *iBufferPtr++ = (int16_t)rintf(floatBuffer[2]);
160  *iBufferPtr++ = (int16_t)rintf(floatBuffer[3]);
161  }
162 
163  number = quarterPoints * 4;
164  iBufferPtr = &iBuffer[number];
165  for (; number < num_points; number++) {
166  *iBufferPtr++ = (int16_t)rintf(*complexVectorPtr++ * scalar);
167  complexVectorPtr++;
168  }
169 }
170 
171 #endif /* LV_HAVE_SSE */
172 
173 
174 #ifdef LV_HAVE_GENERIC
175 
176 static inline void
178  const lv_32fc_t* complexVector,
179  const float scalar,
180  unsigned int num_points)
181 {
182  const float* complexVectorPtr = (float*)complexVector;
183  int16_t* iBufferPtr = iBuffer;
184  unsigned int number = 0;
185  for (number = 0; number < num_points; number++) {
186  *iBufferPtr++ = (int16_t)rintf(*complexVectorPtr++ * scalar);
187  complexVectorPtr++;
188  }
189 }
190 
191 #endif /* LV_HAVE_GENERIC */
192 
193 #endif /* INCLUDED_volk_32fc_s32f_deinterleave_real_16i_a_H */
194 
195 #ifndef INCLUDED_volk_32fc_s32f_deinterleave_real_16i_u_H
196 #define INCLUDED_volk_32fc_s32f_deinterleave_real_16i_u_H
197 
198 #include <inttypes.h>
199 #include <stdio.h>
200 #include <volk/volk_common.h>
201 
202 #ifdef LV_HAVE_AVX2
203 #include <immintrin.h>
204 
205 static inline void
206 volk_32fc_s32f_deinterleave_real_16i_u_avx2(int16_t* iBuffer,
207  const lv_32fc_t* complexVector,
208  const float scalar,
209  unsigned int num_points)
210 {
211  unsigned int number = 0;
212  const unsigned int eighthPoints = num_points / 8;
213 
214  const float* complexVectorPtr = (float*)complexVector;
215  int16_t* iBufferPtr = iBuffer;
216 
217  __m256 vScalar = _mm256_set1_ps(scalar);
218 
219  __m256 cplxValue1, cplxValue2, iValue;
220  __m256i a;
221  __m128i b;
222 
223  __m256i idx = _mm256_set_epi32(3, 3, 3, 3, 5, 1, 4, 0);
224 
225  for (; number < eighthPoints; number++) {
226  cplxValue1 = _mm256_loadu_ps(complexVectorPtr);
227  complexVectorPtr += 8;
228 
229  cplxValue2 = _mm256_loadu_ps(complexVectorPtr);
230  complexVectorPtr += 8;
231 
232  // Arrange in i1i2i3i4 format
233  iValue = _mm256_shuffle_ps(cplxValue1, cplxValue2, _MM_SHUFFLE(2, 0, 2, 0));
234 
235  iValue = _mm256_mul_ps(iValue, vScalar);
236 
237  a = _mm256_cvtps_epi32(iValue);
238  a = _mm256_packs_epi32(a, a);
239  a = _mm256_permutevar8x32_epi32(a, idx);
240  b = _mm256_extracti128_si256(a, 0);
241 
242  _mm_storeu_si128((__m128i*)iBufferPtr, b);
243  iBufferPtr += 8;
244  }
245 
246  number = eighthPoints * 8;
247  iBufferPtr = &iBuffer[number];
248  for (; number < num_points; number++) {
249  *iBufferPtr++ = (int16_t)rintf(*complexVectorPtr++ * scalar);
250  complexVectorPtr++;
251  }
252 }
253 
254 #endif /* LV_HAVE_AVX2 */
255 
256 #endif /* INCLUDED_volk_32fc_s32f_deinterleave_real_16i_u_H */
static void volk_32fc_s32f_deinterleave_real_16i_a_sse(int16_t *iBuffer, const lv_32fc_t *complexVector, const float scalar, unsigned int num_points)
Definition: volk_32fc_s32f_deinterleave_real_16i.h:127
static float rintf(float x)
Definition: config.h:45
static void volk_32fc_s32f_deinterleave_real_16i_generic(int16_t *iBuffer, const lv_32fc_t *complexVector, const float scalar, unsigned int num_points)
Definition: volk_32fc_s32f_deinterleave_real_16i.h:177
#define __VOLK_ATTR_ALIGNED(x)
Definition: volk_common.h:62
float complex lv_32fc_t
Definition: volk_complex.h:74