GNU Radio 3.5.3.2 C++ API
volk_32f_s32f_convert_32i_a.h
Go to the documentation of this file.
1 #ifndef INCLUDED_volk_32f_s32f_convert_32i_a_H
2 #define INCLUDED_volk_32f_s32f_convert_32i_a_H
3 
4 #include <volk/volk_common.h>
5 #include <inttypes.h>
6 #include <stdio.h>
7 
8 #ifdef LV_HAVE_AVX
9 #include <immintrin.h>
10  /*!
11  \brief Multiplies each point in the input buffer by the scalar value, then converts the result into a 32 bit integer value
12  \param inputVector The floating point input data buffer
13  \param outputVector The 32 bit output data buffer
14  \param scalar The value multiplied against each point in the input buffer
15  \param num_points The number of data values to be converted
16  */
17 static inline void volk_32f_s32f_convert_32i_a_avx(int32_t* outputVector, const float* inputVector, const float scalar, unsigned int num_points){
18  unsigned int number = 0;
19 
20  const unsigned int eighthPoints = num_points / 8;
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  __m256 vScalar = _mm256_set1_ps(scalar);
30  __m256 inputVal1;
31  __m256i intInputVal1;
32  __m256 vmin_val = _mm256_set1_ps(min_val);
33  __m256 vmax_val = _mm256_set1_ps(max_val);
34 
35  for(;number < eighthPoints; number++){
36  inputVal1 = _mm256_load_ps(inputVectorPtr); inputVectorPtr += 8;
37 
38  inputVal1 = _mm256_max_ps(_mm256_min_ps(_mm256_mul_ps(inputVal1, vScalar), vmax_val), vmin_val);
39  intInputVal1 = _mm256_cvtps_epi32(inputVal1);
40 
41  _mm256_store_si256((__m256i*)outputVectorPtr, intInputVal1);
42  outputVectorPtr += 8;
43  }
44 
45  number = eighthPoints * 8;
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_AVX */
56 
57 #ifdef LV_HAVE_SSE2
58 #include <emmintrin.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  */
66 static inline void volk_32f_s32f_convert_32i_a_sse2(int32_t* outputVector, const float* inputVector, const float scalar, unsigned int num_points){
67  unsigned int number = 0;
68 
69  const unsigned int quarterPoints = num_points / 4;
70 
71  const float* inputVectorPtr = (const float*)inputVector;
72  int32_t* outputVectorPtr = outputVector;
73 
74  float min_val = -2147483647;
75  float max_val = 2147483647;
76  float r;
77 
78  __m128 vScalar = _mm_set_ps1(scalar);
79  __m128 inputVal1;
80  __m128i intInputVal1;
81  __m128 vmin_val = _mm_set_ps1(min_val);
82  __m128 vmax_val = _mm_set_ps1(max_val);
83 
84  for(;number < quarterPoints; number++){
85  inputVal1 = _mm_load_ps(inputVectorPtr); inputVectorPtr += 4;
86 
87  inputVal1 = _mm_max_ps(_mm_min_ps(_mm_mul_ps(inputVal1, vScalar), vmax_val), vmin_val);
88  intInputVal1 = _mm_cvtps_epi32(inputVal1);
89 
90  _mm_store_si128((__m128i*)outputVectorPtr, intInputVal1);
91  outputVectorPtr += 4;
92  }
93 
94  number = quarterPoints * 4;
95  for(; number < num_points; number++){
96  r = inputVector[number] * scalar;
97  if(r > max_val)
98  r = max_val;
99  else if(r < min_val)
100  r = min_val;
101  outputVector[number] = (int32_t)(r);
102  }
103 }
104 #endif /* LV_HAVE_SSE2 */
105 
106 #ifdef LV_HAVE_SSE
107 #include <xmmintrin.h>
108  /*!
109  \brief Multiplies each point in the input buffer by the scalar value, then converts the result into a 32 bit integer value
110  \param inputVector The floating point input data buffer
111  \param outputVector The 32 bit output data buffer
112  \param scalar The value multiplied against each point in the input buffer
113  \param num_points The number of data values to be converted
114  */
115 static inline void volk_32f_s32f_convert_32i_a_sse(int32_t* outputVector, const float* inputVector, const float scalar, unsigned int num_points){
116  unsigned int number = 0;
117 
118  const unsigned int quarterPoints = num_points / 4;
119 
120  const float* inputVectorPtr = (const float*)inputVector;
121  int32_t* outputVectorPtr = outputVector;
122 
123  float min_val = -2147483647;
124  float max_val = 2147483647;
125  float r;
126 
127  __m128 vScalar = _mm_set_ps1(scalar);
128  __m128 ret;
129  __m128 vmin_val = _mm_set_ps1(min_val);
130  __m128 vmax_val = _mm_set_ps1(max_val);
131 
132  __VOLK_ATTR_ALIGNED(16) float outputFloatBuffer[4];
133 
134  for(;number < quarterPoints; number++){
135  ret = _mm_load_ps(inputVectorPtr);
136  inputVectorPtr += 4;
137 
138  ret = _mm_max_ps(_mm_min_ps(_mm_mul_ps(ret, vScalar), vmax_val), vmin_val);
139 
140  _mm_store_ps(outputFloatBuffer, ret);
141  *outputVectorPtr++ = (int32_t)(outputFloatBuffer[0]);
142  *outputVectorPtr++ = (int32_t)(outputFloatBuffer[1]);
143  *outputVectorPtr++ = (int32_t)(outputFloatBuffer[2]);
144  *outputVectorPtr++ = (int32_t)(outputFloatBuffer[3]);
145  }
146 
147  number = quarterPoints * 4;
148  for(; number < num_points; number++){
149  r = inputVector[number] * scalar;
150  if(r > max_val)
151  r = max_val;
152  else if(r < min_val)
153  r = min_val;
154  outputVector[number] = (int32_t)(r);
155  }
156 }
157 #endif /* LV_HAVE_SSE */
158 
159 #ifdef LV_HAVE_GENERIC
160  /*!
161  \brief Multiplies each point in the input buffer by the scalar value, then converts the result into a 32 bit integer value
162  \param inputVector The floating point input data buffer
163  \param outputVector The 32 bit output data buffer
164  \param scalar The value multiplied against each point in the input buffer
165  \param num_points The number of data values to be converted
166  */
167 static inline void volk_32f_s32f_convert_32i_a_generic(int32_t* outputVector, const float* inputVector, const float scalar, unsigned int num_points){
168  int32_t* outputVectorPtr = outputVector;
169  const float* inputVectorPtr = inputVector;
170  unsigned int number = 0;
171  float min_val = -2147483647;
172  float max_val = 2147483647;
173  float r;
174 
175  for(number = 0; number < num_points; number++){
176  r = *inputVectorPtr++ * scalar;
177  if(r > max_val)
178  r = max_val;
179  else if(r < min_val)
180  r = min_val;
181  *outputVectorPtr++ = (int32_t)(r);
182  }
183 }
184 #endif /* LV_HAVE_GENERIC */
185 
186 
187 
188 
189 #endif /* INCLUDED_volk_32f_s32f_convert_32i_a_H */