GNU Radio Manual and C++ API Reference  3.7.4.1
The Free & Open Software Radio Ecosystem
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
volk_32f_s32f_convert_32i.h
Go to the documentation of this file.
1 #ifndef INCLUDED_volk_32f_s32f_convert_32i_u_H
2 #define INCLUDED_volk_32f_s32f_convert_32i_u_H
3 
4 #include <inttypes.h>
5 #include <stdio.h>
6 
7 #ifdef LV_HAVE_SSE2
8 #include <emmintrin.h>
9  /*!
10  \brief Multiplies each point in the input buffer by the scalar value, then converts the result into a 32 bit integer value
11  \param inputVector The floating point input data buffer
12  \param outputVector The 32 bit output data buffer
13  \param scalar The value multiplied against each point in the input buffer
14  \param num_points The number of data values to be converted
15  \note Input buffer does NOT need to be properly aligned
16  */
17 static inline void volk_32f_s32f_convert_32i_u_sse2(int32_t* outputVector, const float* inputVector, const float scalar, unsigned int num_points){
18  unsigned int number = 0;
19 
20  const unsigned int quarterPoints = num_points / 4;
21 
22  const float* inputVectorPtr = (const float*)inputVector;
23  int32_t* outputVectorPtr = outputVector;
24 
25  float min_val = -2147483647;
26  float max_val = 2147483647;
27  float r;
28 
29  __m128 vScalar = _mm_set_ps1(scalar);
30  __m128 inputVal1;
31  __m128i intInputVal1;
32  __m128 vmin_val = _mm_set_ps1(min_val);
33  __m128 vmax_val = _mm_set_ps1(max_val);
34 
35  for(;number < quarterPoints; number++){
36  inputVal1 = _mm_loadu_ps(inputVectorPtr); inputVectorPtr += 4;
37 
38  inputVal1 = _mm_max_ps(_mm_min_ps(_mm_mul_ps(inputVal1, vScalar), vmax_val), vmin_val);
39  intInputVal1 = _mm_cvtps_epi32(inputVal1);
40 
41  _mm_storeu_si128((__m128i*)outputVectorPtr, intInputVal1);
42  outputVectorPtr += 4;
43  }
44 
45  number = quarterPoints * 4;
46  for(; number < num_points; number++){
47  r = inputVector[number] * scalar;
48  if(r > max_val)
49  r = max_val;
50  else if(r < min_val)
51  r = min_val;
52  outputVector[number] = (int32_t)(r);
53  }
54 }
55 #endif /* LV_HAVE_SSE2 */
56 
57 #ifdef LV_HAVE_SSE
58 #include <xmmintrin.h>
59  /*!
60  \brief Multiplies each point in the input buffer by the scalar value, then converts the result into a 32 bit integer value
61  \param inputVector The floating point input data buffer
62  \param outputVector The 32 bit output data buffer
63  \param scalar The value multiplied against each point in the input buffer
64  \param num_points The number of data values to be converted
65  \note Input buffer does NOT need to be properly aligned
66  */
67 static inline void volk_32f_s32f_convert_32i_u_sse(int32_t* outputVector, const float* inputVector, const float scalar, unsigned int num_points){
68  unsigned int number = 0;
69 
70  const unsigned int quarterPoints = num_points / 4;
71 
72  const float* inputVectorPtr = (const float*)inputVector;
73  int32_t* outputVectorPtr = outputVector;
74 
75  float min_val = -2147483647;
76  float max_val = 2147483647;
77  float r;
78 
79  __m128 vScalar = _mm_set_ps1(scalar);
80  __m128 ret;
81  __m128 vmin_val = _mm_set_ps1(min_val);
82  __m128 vmax_val = _mm_set_ps1(max_val);
83 
84  __VOLK_ATTR_ALIGNED(16) float outputFloatBuffer[4];
85 
86  for(;number < quarterPoints; number++){
87  ret = _mm_loadu_ps(inputVectorPtr);
88  inputVectorPtr += 4;
89 
90  ret = _mm_max_ps(_mm_min_ps(_mm_mul_ps(ret, vScalar), vmax_val), vmin_val);
91 
92  _mm_store_ps(outputFloatBuffer, ret);
93  *outputVectorPtr++ = (int32_t)(outputFloatBuffer[0]);
94  *outputVectorPtr++ = (int32_t)(outputFloatBuffer[1]);
95  *outputVectorPtr++ = (int32_t)(outputFloatBuffer[2]);
96  *outputVectorPtr++ = (int32_t)(outputFloatBuffer[3]);
97  }
98 
99  number = quarterPoints * 4;
100  for(; number < num_points; number++){
101  r = inputVector[number] * scalar;
102  if(r > max_val)
103  r = max_val;
104  else if(r < min_val)
105  r = min_val;
106  outputVector[number] = (int32_t)(r);
107  }
108 }
109 #endif /* LV_HAVE_SSE */
110 
111 #ifdef LV_HAVE_GENERIC
112  /*!
113  \brief Multiplies each point in the input buffer by the scalar value, then converts the result into a 32 bit integer value
114  \param inputVector The floating point input data buffer
115  \param outputVector The 32 bit output data buffer
116  \param scalar The value multiplied against each point in the input buffer
117  \param num_points The number of data values to be converted
118  \note Input buffer does NOT need to be properly aligned
119  */
120 static inline void volk_32f_s32f_convert_32i_generic(int32_t* outputVector, const float* inputVector, const float scalar, unsigned int num_points){
121  int32_t* outputVectorPtr = outputVector;
122  const float* inputVectorPtr = inputVector;
123  unsigned int number = 0;
124  float min_val = -2147483647;
125  float max_val = 2147483647;
126  float r;
127 
128  for(number = 0; number < num_points; number++){
129  r = *inputVectorPtr++ * scalar;
130  if(r > max_val)
131  r = max_val;
132  else if(r < min_val)
133  r = min_val;
134  *outputVectorPtr++ = (int32_t)(r);
135  }
136 }
137 #endif /* LV_HAVE_GENERIC */
138 
139 
140 
141 
142 #endif /* INCLUDED_volk_32f_s32f_convert_32i_u_H */
143 #ifndef INCLUDED_volk_32f_s32f_convert_32i_a_H
144 #define INCLUDED_volk_32f_s32f_convert_32i_a_H
145 
146 #include <volk/volk_common.h>
147 #include <inttypes.h>
148 #include <stdio.h>
149 
150 #ifdef LV_HAVE_AVX
151 #include <immintrin.h>
152  /*!
153  \brief Multiplies each point in the input buffer by the scalar value, then converts the result into a 32 bit integer value
154  \param inputVector The floating point input data buffer
155  \param outputVector The 32 bit output data buffer
156  \param scalar The value multiplied against each point in the input buffer
157  \param num_points The number of data values to be converted
158  */
159 static inline void volk_32f_s32f_convert_32i_a_avx(int32_t* outputVector, const float* inputVector, const float scalar, unsigned int num_points){
160  unsigned int number = 0;
161 
162  const unsigned int eighthPoints = num_points / 8;
163 
164  const float* inputVectorPtr = (const float*)inputVector;
165  int32_t* outputVectorPtr = outputVector;
166 
167  float min_val = -2147483647;
168  float max_val = 2147483647;
169  float r;
170 
171  __m256 vScalar = _mm256_set1_ps(scalar);
172  __m256 inputVal1;
173  __m256i intInputVal1;
174  __m256 vmin_val = _mm256_set1_ps(min_val);
175  __m256 vmax_val = _mm256_set1_ps(max_val);
176 
177  for(;number < eighthPoints; number++){
178  inputVal1 = _mm256_load_ps(inputVectorPtr); inputVectorPtr += 8;
179 
180  inputVal1 = _mm256_max_ps(_mm256_min_ps(_mm256_mul_ps(inputVal1, vScalar), vmax_val), vmin_val);
181  intInputVal1 = _mm256_cvtps_epi32(inputVal1);
182 
183  _mm256_store_si256((__m256i*)outputVectorPtr, intInputVal1);
184  outputVectorPtr += 8;
185  }
186 
187  number = eighthPoints * 8;
188  for(; number < num_points; number++){
189  r = inputVector[number] * scalar;
190  if(r > max_val)
191  r = max_val;
192  else if(r < min_val)
193  r = min_val;
194  outputVector[number] = (int32_t)(r);
195  }
196 }
197 #endif /* LV_HAVE_AVX */
198 
199 #ifdef LV_HAVE_SSE2
200 #include <emmintrin.h>
201  /*!
202  \brief Multiplies each point in the input buffer by the scalar value, then converts the result into a 32 bit integer value
203  \param inputVector The floating point input data buffer
204  \param outputVector The 32 bit output data buffer
205  \param scalar The value multiplied against each point in the input buffer
206  \param num_points The number of data values to be converted
207  */
208 static inline void volk_32f_s32f_convert_32i_a_sse2(int32_t* outputVector, const float* inputVector, const float scalar, unsigned int num_points){
209  unsigned int number = 0;
210 
211  const unsigned int quarterPoints = num_points / 4;
212 
213  const float* inputVectorPtr = (const float*)inputVector;
214  int32_t* outputVectorPtr = outputVector;
215 
216  float min_val = -2147483647;
217  float max_val = 2147483647;
218  float r;
219 
220  __m128 vScalar = _mm_set_ps1(scalar);
221  __m128 inputVal1;
222  __m128i intInputVal1;
223  __m128 vmin_val = _mm_set_ps1(min_val);
224  __m128 vmax_val = _mm_set_ps1(max_val);
225 
226  for(;number < quarterPoints; number++){
227  inputVal1 = _mm_load_ps(inputVectorPtr); inputVectorPtr += 4;
228 
229  inputVal1 = _mm_max_ps(_mm_min_ps(_mm_mul_ps(inputVal1, vScalar), vmax_val), vmin_val);
230  intInputVal1 = _mm_cvtps_epi32(inputVal1);
231 
232  _mm_store_si128((__m128i*)outputVectorPtr, intInputVal1);
233  outputVectorPtr += 4;
234  }
235 
236  number = quarterPoints * 4;
237  for(; number < num_points; number++){
238  r = inputVector[number] * scalar;
239  if(r > max_val)
240  r = max_val;
241  else if(r < min_val)
242  r = min_val;
243  outputVector[number] = (int32_t)(r);
244  }
245 }
246 #endif /* LV_HAVE_SSE2 */
247 
248 #ifdef LV_HAVE_SSE
249 #include <xmmintrin.h>
250  /*!
251  \brief Multiplies each point in the input buffer by the scalar value, then converts the result into a 32 bit integer value
252  \param inputVector The floating point input data buffer
253  \param outputVector The 32 bit output data buffer
254  \param scalar The value multiplied against each point in the input buffer
255  \param num_points The number of data values to be converted
256  */
257 static inline void volk_32f_s32f_convert_32i_a_sse(int32_t* outputVector, const float* inputVector, const float scalar, unsigned int num_points){
258  unsigned int number = 0;
259 
260  const unsigned int quarterPoints = num_points / 4;
261 
262  const float* inputVectorPtr = (const float*)inputVector;
263  int32_t* outputVectorPtr = outputVector;
264 
265  float min_val = -2147483647;
266  float max_val = 2147483647;
267  float r;
268 
269  __m128 vScalar = _mm_set_ps1(scalar);
270  __m128 ret;
271  __m128 vmin_val = _mm_set_ps1(min_val);
272  __m128 vmax_val = _mm_set_ps1(max_val);
273 
274  __VOLK_ATTR_ALIGNED(16) float outputFloatBuffer[4];
275 
276  for(;number < quarterPoints; number++){
277  ret = _mm_load_ps(inputVectorPtr);
278  inputVectorPtr += 4;
279 
280  ret = _mm_max_ps(_mm_min_ps(_mm_mul_ps(ret, vScalar), vmax_val), vmin_val);
281 
282  _mm_store_ps(outputFloatBuffer, ret);
283  *outputVectorPtr++ = (int32_t)(outputFloatBuffer[0]);
284  *outputVectorPtr++ = (int32_t)(outputFloatBuffer[1]);
285  *outputVectorPtr++ = (int32_t)(outputFloatBuffer[2]);
286  *outputVectorPtr++ = (int32_t)(outputFloatBuffer[3]);
287  }
288 
289  number = quarterPoints * 4;
290  for(; number < num_points; number++){
291  r = inputVector[number] * scalar;
292  if(r > max_val)
293  r = max_val;
294  else if(r < min_val)
295  r = min_val;
296  outputVector[number] = (int32_t)(r);
297  }
298 }
299 #endif /* LV_HAVE_SSE */
300 
301 #ifdef LV_HAVE_GENERIC
302  /*!
303  \brief Multiplies each point in the input buffer by the scalar value, then converts the result into a 32 bit integer value
304  \param inputVector The floating point input data buffer
305  \param outputVector The 32 bit output data buffer
306  \param scalar The value multiplied against each point in the input buffer
307  \param num_points The number of data values to be converted
308  */
309 static inline void volk_32f_s32f_convert_32i_a_generic(int32_t* outputVector, const float* inputVector, const float scalar, unsigned int num_points){
310  int32_t* outputVectorPtr = outputVector;
311  const float* inputVectorPtr = inputVector;
312  unsigned int number = 0;
313  float min_val = -2147483647;
314  float max_val = 2147483647;
315  float r;
316 
317  for(number = 0; number < num_points; number++){
318  r = *inputVectorPtr++ * scalar;
319  if(r > max_val)
320  r = max_val;
321  else if(r < min_val)
322  r = min_val;
323  *outputVectorPtr++ = (int32_t)(r);
324  }
325 }
326 #endif /* LV_HAVE_GENERIC */
327 
328 
329 
330 
331 #endif /* INCLUDED_volk_32f_s32f_convert_32i_a_H */
#define __VOLK_ATTR_ALIGNED(x)
Definition: volk_common.h:27
signed int int32_t
Definition: stdint.h:77