GNU Radio 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  __m128 vScalar = _mm_set_ps1(scalar);
25  __m128 inputVal1;
26  __m128i intInputVal1;
27 
28  for(;number < quarterPoints; number++){
29  inputVal1 = _mm_loadu_ps(inputVectorPtr); inputVectorPtr += 4;
30 
31  intInputVal1 = _mm_cvtps_epi32(_mm_mul_ps(inputVal1, vScalar));
32 
33  _mm_storeu_si128((__m128i*)outputVectorPtr, intInputVal1);
34  outputVectorPtr += 4;
35  }
36 
37  number = quarterPoints * 4;
38  for(; number < num_points; number++){
39  outputVector[number] = (int32_t)(inputVector[number] * scalar);
40  }
41 }
42 #endif /* LV_HAVE_SSE2 */
43 
44 #ifdef LV_HAVE_SSE
45 #include <xmmintrin.h>
46  /*!
47  \brief Multiplies each point in the input buffer by the scalar value, then converts the result into a 32 bit integer value
48  \param inputVector The floating point input data buffer
49  \param outputVector The 32 bit output data buffer
50  \param scalar The value multiplied against each point in the input buffer
51  \param num_points The number of data values to be converted
52  \note Input buffer does NOT need to be properly aligned
53  */
54 static inline void volk_32f_s32f_convert_32i_u_sse(int32_t* outputVector, const float* inputVector, const float scalar, unsigned int num_points){
55  unsigned int number = 0;
56 
57  const unsigned int quarterPoints = num_points / 4;
58 
59  const float* inputVectorPtr = (const float*)inputVector;
60  int32_t* outputVectorPtr = outputVector;
61  __m128 vScalar = _mm_set_ps1(scalar);
62  __m128 ret;
63 
64  __VOLK_ATTR_ALIGNED(16) float outputFloatBuffer[4];
65 
66  for(;number < quarterPoints; number++){
67  ret = _mm_loadu_ps(inputVectorPtr);
68  inputVectorPtr += 4;
69 
70  ret = _mm_mul_ps(ret, vScalar);
71 
72  _mm_store_ps(outputFloatBuffer, ret);
73  *outputVectorPtr++ = (int32_t)(outputFloatBuffer[0]);
74  *outputVectorPtr++ = (int32_t)(outputFloatBuffer[1]);
75  *outputVectorPtr++ = (int32_t)(outputFloatBuffer[2]);
76  *outputVectorPtr++ = (int32_t)(outputFloatBuffer[3]);
77  }
78 
79  number = quarterPoints * 4;
80  for(; number < num_points; number++){
81  outputVector[number] = (int32_t)(inputVector[number] * scalar);
82  }
83 }
84 #endif /* LV_HAVE_SSE */
85 
86 #ifdef LV_HAVE_GENERIC
87  /*!
88  \brief Multiplies each point in the input buffer by the scalar value, then converts the result into a 32 bit integer value
89  \param inputVector The floating point input data buffer
90  \param outputVector The 32 bit output data buffer
91  \param scalar The value multiplied against each point in the input buffer
92  \param num_points The number of data values to be converted
93  \note Input buffer does NOT need to be properly aligned
94  */
95 static inline void volk_32f_s32f_convert_32i_u_generic(int32_t* outputVector, const float* inputVector, const float scalar, unsigned int num_points){
96  int32_t* outputVectorPtr = outputVector;
97  const float* inputVectorPtr = inputVector;
98  unsigned int number = 0;
99 
100  for(number = 0; number < num_points; number++){
101  *outputVectorPtr++ = ((int32_t)(*inputVectorPtr++ * scalar));
102  }
103 }
104 #endif /* LV_HAVE_GENERIC */
105 
106 
107 
108 
109 #endif /* INCLUDED_volk_32f_s32f_convert_32i_u_H */