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