GNU Radio C++ API
volk_32f_s32f_convert_16i_a.h
Go to the documentation of this file.
1 #ifndef INCLUDED_volk_32f_s32f_convert_16i_a_H
2 #define INCLUDED_volk_32f_s32f_convert_16i_a_H
3 
4 #include <volk/volk_common.h>
5 #include <inttypes.h>
6 #include <stdio.h>
7 
8 #ifdef LV_HAVE_SSE2
9 #include <emmintrin.h>
10  /*!
11  \brief Multiplies each point in the input buffer by the scalar value, then converts the result into a 16 bit integer value
12  \param inputVector The floating point input data buffer
13  \param outputVector The 16 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_16i_a_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_load_ps(inputVectorPtr); inputVectorPtr += 4;
30  inputVal2 = _mm_load_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_store_si128((__m128i*)outputVectorPtr, intInputVal1);
38  outputVectorPtr += 8;
39  }
40 
41  number = eighthPoints * 8;
42  for(; number < num_points; number++){
43  *outputVectorPtr++ = (int16_t)(*inputVectorPtr++ * 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  */
57 static inline void volk_32f_s32f_convert_16i_a_sse(int16_t* outputVector, const float* inputVector, const float scalar, unsigned int num_points){
58  unsigned int number = 0;
59 
60  const unsigned int quarterPoints = num_points / 4;
61 
62  const float* inputVectorPtr = (const float*)inputVector;
63  int16_t* outputVectorPtr = outputVector;
64  __m128 vScalar = _mm_set_ps1(scalar);
65  __m128 ret;
66 
67  __VOLK_ATTR_ALIGNED(16) float outputFloatBuffer[4];
68 
69  for(;number < quarterPoints; number++){
70  ret = _mm_load_ps(inputVectorPtr);
71  inputVectorPtr += 4;
72 
73  ret = _mm_mul_ps(ret, vScalar);
74 
75  _mm_store_ps(outputFloatBuffer, ret);
76  *outputVectorPtr++ = (int16_t)(outputFloatBuffer[0]);
77  *outputVectorPtr++ = (int16_t)(outputFloatBuffer[1]);
78  *outputVectorPtr++ = (int16_t)(outputFloatBuffer[2]);
79  *outputVectorPtr++ = (int16_t)(outputFloatBuffer[3]);
80  }
81 
82  number = quarterPoints * 4;
83  for(; number < num_points; number++){
84  *outputVectorPtr++ = (int16_t)(*inputVectorPtr++ * scalar);
85  }
86 }
87 #endif /* LV_HAVE_SSE */
88 
89 #ifdef LV_HAVE_GENERIC
90  /*!
91  \brief Multiplies each point in the input buffer by the scalar value, then converts the result into a 16 bit integer value
92  \param inputVector The floating point input data buffer
93  \param outputVector The 16 bit output data buffer
94  \param scalar The value multiplied against each point in the input buffer
95  \param num_points The number of data values to be converted
96  */
97 static inline void volk_32f_s32f_convert_16i_a_generic(int16_t* outputVector, const float* inputVector, const float scalar, unsigned int num_points){
98  int16_t* outputVectorPtr = outputVector;
99  const float* inputVectorPtr = inputVector;
100  unsigned int number = 0;
101 
102  for(number = 0; number < num_points; number++){
103  *outputVectorPtr++ = ((int16_t)(*inputVectorPtr++ * scalar));
104  }
105 }
106 #endif /* LV_HAVE_GENERIC */
107 
108 
109 
110 
111 #endif /* INCLUDED_volk_32f_s32f_convert_16i_a_H */