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