GNU Radio C++ API
volk_32f_s32f_convert_8i_u.h
Go to the documentation of this file.
1 #ifndef INCLUDED_volk_32f_s32f_convert_8i_u_H
2 #define INCLUDED_volk_32f_s32f_convert_8i_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 8 bit integer value
11  \param inputVector The floating point input data buffer
12  \param outputVector The 8 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_8i_u_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_loadu_ps(inputVectorPtr); inputVectorPtr += 4;
30  inputVal2 = _mm_loadu_ps(inputVectorPtr); inputVectorPtr += 4;
31  inputVal3 = _mm_loadu_ps(inputVectorPtr); inputVectorPtr += 4;
32  inputVal4 = _mm_loadu_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_storeu_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  \note Input buffer does NOT need to be properly aligned
64  */
65 static inline void volk_32f_s32f_convert_8i_u_sse(int8_t* outputVector, const float* inputVector, const float scalar, unsigned int num_points){
66  unsigned int number = 0;
67 
68  const unsigned int quarterPoints = num_points / 4;
69 
70  const float* inputVectorPtr = (const float*)inputVector;
71  int8_t* outputVectorPtr = outputVector;
72  __m128 vScalar = _mm_set_ps1(scalar);
73  __m128 ret;
74 
75  __VOLK_ATTR_ALIGNED(16) float outputFloatBuffer[4];
76 
77  for(;number < quarterPoints; number++){
78  ret = _mm_loadu_ps(inputVectorPtr);
79  inputVectorPtr += 4;
80 
81  ret = _mm_mul_ps(ret, vScalar);
82 
83  _mm_store_ps(outputFloatBuffer, ret);
84  *outputVectorPtr++ = (int8_t)(outputFloatBuffer[0]);
85  *outputVectorPtr++ = (int8_t)(outputFloatBuffer[1]);
86  *outputVectorPtr++ = (int8_t)(outputFloatBuffer[2]);
87  *outputVectorPtr++ = (int8_t)(outputFloatBuffer[3]);
88  }
89 
90  number = quarterPoints * 4;
91  for(; number < num_points; number++){
92  outputVector[number] = (int8_t)(inputVector[number] * scalar);
93  }
94 }
95 #endif /* LV_HAVE_SSE */
96 
97 #ifdef LV_HAVE_GENERIC
98  /*!
99  \brief Multiplies each point in the input buffer by the scalar value, then converts the result into a 8 bit integer value
100  \param inputVector The floating point input data buffer
101  \param outputVector The 8 bit output data buffer
102  \param scalar The value multiplied against each point in the input buffer
103  \param num_points The number of data values to be converted
104  \note Input buffer does NOT need to be properly aligned
105  */
106 static inline void volk_32f_s32f_convert_8i_u_generic(int8_t* outputVector, const float* inputVector, const float scalar, unsigned int num_points){
107  int8_t* outputVectorPtr = outputVector;
108  const float* inputVectorPtr = inputVector;
109  unsigned int number = 0;
110 
111  for(number = 0; number < num_points; number++){
112  *outputVectorPtr++ = ((int8_t)(*inputVectorPtr++ * scalar));
113  }
114 }
115 #endif /* LV_HAVE_GENERIC */
116 
117 
118 
119 
120 #endif /* INCLUDED_volk_32f_s32f_convert_8i_u_H */