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