GNU Radio 3.6.2 C++ API
volk_32fc_magnitude_squared_32f_u.h
Go to the documentation of this file.
1 #ifndef INCLUDED_volk_32fc_magnitude_squared_32f_u_H
2 #define INCLUDED_volk_32fc_magnitude_squared_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 squared 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_squared_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  _mm_storeu_ps(magnitudeVectorPtr, result);
37  magnitudeVectorPtr += 4;
38  }
39 
40  number = quarterPoints * 4;
41  for(; number < num_points; number++){
42  float val1Real = *complexVectorPtr++;
43  float val1Imag = *complexVectorPtr++;
44  *magnitudeVectorPtr++ = (val1Real * val1Real) + (val1Imag * val1Imag);
45  }
46 }
47 #endif /* LV_HAVE_SSE3 */
48 
49 #ifdef LV_HAVE_SSE
50 #include <xmmintrin.h>
51  /*!
52  \brief Calculates the magnitude squared of the complexVector and stores the results in the magnitudeVector
53  \param complexVector The vector containing the complex input values
54  \param magnitudeVector The vector containing the real output values
55  \param num_points The number of complex values in complexVector to be calculated and stored into cVector
56  */
57 static inline void volk_32fc_magnitude_squared_32f_u_sse(float* magnitudeVector, const lv_32fc_t* complexVector, unsigned int num_points){
58  unsigned int number = 0;
59  const unsigned int quarterPoints = num_points / 4;
60 
61  const float* complexVectorPtr = (float*)complexVector;
62  float* magnitudeVectorPtr = magnitudeVector;
63 
64  __m128 cplxValue1, cplxValue2, iValue, qValue, result;
65  for(;number < quarterPoints; number++){
66  cplxValue1 = _mm_loadu_ps(complexVectorPtr);
67  complexVectorPtr += 4;
68 
69  cplxValue2 = _mm_loadu_ps(complexVectorPtr);
70  complexVectorPtr += 4;
71 
72  // Arrange in i1i2i3i4 format
73  iValue = _mm_shuffle_ps(cplxValue1, cplxValue2, _MM_SHUFFLE(2,0,2,0));
74  // Arrange in q1q2q3q4 format
75  qValue = _mm_shuffle_ps(cplxValue1, cplxValue2, _MM_SHUFFLE(3,1,3,1));
76 
77  iValue = _mm_mul_ps(iValue, iValue); // Square the I values
78  qValue = _mm_mul_ps(qValue, qValue); // Square the Q Values
79 
80  result = _mm_add_ps(iValue, qValue); // Add the I2 and Q2 values
81 
82  _mm_storeu_ps(magnitudeVectorPtr, result);
83  magnitudeVectorPtr += 4;
84  }
85 
86  number = quarterPoints * 4;
87  for(; number < num_points; number++){
88  float val1Real = *complexVectorPtr++;
89  float val1Imag = *complexVectorPtr++;
90  *magnitudeVectorPtr++ = (val1Real * val1Real) + (val1Imag * val1Imag);
91  }
92 }
93 #endif /* LV_HAVE_SSE */
94 
95 #ifdef LV_HAVE_GENERIC
96  /*!
97  \brief Calculates the magnitude squared of the complexVector and stores the results in the magnitudeVector
98  \param complexVector The vector containing the complex input values
99  \param magnitudeVector The vector containing the real output values
100  \param num_points The number of complex values in complexVector to be calculated and stored into cVector
101  */
102 static inline void volk_32fc_magnitude_squared_32f_u_generic(float* magnitudeVector, const lv_32fc_t* complexVector, unsigned int num_points){
103  const float* complexVectorPtr = (float*)complexVector;
104  float* magnitudeVectorPtr = magnitudeVector;
105  unsigned int number = 0;
106  for(number = 0; number < num_points; number++){
107  const float real = *complexVectorPtr++;
108  const float imag = *complexVectorPtr++;
109  *magnitudeVectorPtr++ = (real*real) + (imag*imag);
110  }
111 }
112 #endif /* LV_HAVE_GENERIC */
113 
114 #endif /* INCLUDED_volk_32fc_magnitude_32f_u_H */