GNU Radio 3.6.1 C++ API
volk_32f_s32f_convert_32i_u.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_u_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 */