gr-baz Package
volk_32fc_magnitude_32f_u.h
Go to the documentation of this file.
1 #ifndef INCLUDED_volk_32fc_magnitude_32f_u_H
2 #define INCLUDED_volk_32fc_magnitude_32f_u_H
3 
4 #include <inttypes.h>
5 #include <stdio.h>
6 #include <math.h>
7 
8 #ifdef LV_HAVE_SSE3
9 #include <pmmintrin.h>
10  /*!
11  \brief Calculates the magnitude of the complexVector and stores the results in the magnitudeVector
12  \param complexVector The vector containing the complex input values
13  \param magnitudeVector The vector containing the real output values
14  \param num_points The number of complex values in complexVector to be calculated and stored into cVector
15  */
16 static inline void volk_32fc_magnitude_32f_u_sse3(float* magnitudeVector, const lv_32fc_t* complexVector, unsigned int num_points){
17  unsigned int number = 0;
18  const unsigned int quarterPoints = num_points / 4;
19 
20  const float* complexVectorPtr = (float*)complexVector;
21  float* magnitudeVectorPtr = magnitudeVector;
22 
23  __m128 cplxValue1, cplxValue2, result;
24  for(;number < quarterPoints; number++){
25  cplxValue1 = _mm_loadu_ps(complexVectorPtr);
26  complexVectorPtr += 4;
27 
28  cplxValue2 = _mm_loadu_ps(complexVectorPtr);
29  complexVectorPtr += 4;
30 
31  cplxValue1 = _mm_mul_ps(cplxValue1, cplxValue1); // Square the values
32  cplxValue2 = _mm_mul_ps(cplxValue2, cplxValue2); // Square the Values
33 
34  result = _mm_hadd_ps(cplxValue1, cplxValue2); // Add the I2 and Q2 values
35 
36  result = _mm_sqrt_ps(result);
37 
38  _mm_storeu_ps(magnitudeVectorPtr, result);
39  magnitudeVectorPtr += 4;
40  }
41 
42  number = quarterPoints * 4;
43  for(; number < num_points; number++){
44  float val1Real = *complexVectorPtr++;
45  float val1Imag = *complexVectorPtr++;
46  *magnitudeVectorPtr++ = sqrtf((val1Real * val1Real) + (val1Imag * val1Imag));
47  }
48 }
49 #endif /* LV_HAVE_SSE3 */
50 
51 #ifdef LV_HAVE_SSE
52 #include <xmmintrin.h>
53  /*!
54  \brief Calculates the magnitude of the complexVector and stores the results in the magnitudeVector
55  \param complexVector The vector containing the complex input values
56  \param magnitudeVector The vector containing the real output values
57  \param num_points The number of complex values in complexVector to be calculated and stored into cVector
58  */
59 static inline void volk_32fc_magnitude_32f_u_sse(float* magnitudeVector, const lv_32fc_t* complexVector, unsigned int num_points){
60  unsigned int number = 0;
61  const unsigned int quarterPoints = num_points / 4;
62 
63  const float* complexVectorPtr = (float*)complexVector;
64  float* magnitudeVectorPtr = magnitudeVector;
65 
66  __m128 cplxValue1, cplxValue2, iValue, qValue, result;
67  for(;number < quarterPoints; number++){
68  cplxValue1 = _mm_loadu_ps(complexVectorPtr);
69  complexVectorPtr += 4;
70 
71  cplxValue2 = _mm_loadu_ps(complexVectorPtr);
72  complexVectorPtr += 4;
73 
74  // Arrange in i1i2i3i4 format
75  iValue = _mm_shuffle_ps(cplxValue1, cplxValue2, _MM_SHUFFLE(2,0,2,0));
76  // Arrange in q1q2q3q4 format
77  qValue = _mm_shuffle_ps(cplxValue1, cplxValue2, _MM_SHUFFLE(3,1,3,1));
78 
79  iValue = _mm_mul_ps(iValue, iValue); // Square the I values
80  qValue = _mm_mul_ps(qValue, qValue); // Square the Q Values
81 
82  result = _mm_add_ps(iValue, qValue); // Add the I2 and Q2 values
83 
84  result = _mm_sqrt_ps(result);
85 
86  _mm_storeu_ps(magnitudeVectorPtr, result);
87  magnitudeVectorPtr += 4;
88  }
89 
90  number = quarterPoints * 4;
91  for(; number < num_points; number++){
92  float val1Real = *complexVectorPtr++;
93  float val1Imag = *complexVectorPtr++;
94  *magnitudeVectorPtr++ = sqrtf((val1Real * val1Real) + (val1Imag * val1Imag));
95  }
96 }
97 #endif /* LV_HAVE_SSE */
98 
99 #ifdef LV_HAVE_GENERIC
100  /*!
101  \brief Calculates the magnitude of the complexVector and stores the results in the magnitudeVector
102  \param complexVector The vector containing the complex input values
103  \param magnitudeVector The vector containing the real output values
104  \param num_points The number of complex values in complexVector to be calculated and stored into cVector
105  */
106 static inline void volk_32fc_magnitude_32f_u_generic(float* magnitudeVector, const lv_32fc_t* complexVector, unsigned int num_points){
107  const float* complexVectorPtr = (float*)complexVector;
108  float* magnitudeVectorPtr = magnitudeVector;
109  unsigned int number = 0;
110  for(number = 0; number < num_points; number++){
111  const float real = *complexVectorPtr++;
112  const float imag = *complexVectorPtr++;
113  *magnitudeVectorPtr++ = sqrtf((real*real) + (imag*imag));
114  }
115 }
116 #endif /* LV_HAVE_GENERIC */
117 
118 #endif /* INCLUDED_volk_32fc_magnitude_32f_u_H */