GNU Radio Manual and C++ API Reference  3.7.6.1
The Free & Open Software Radio Ecosystem
volk_32f_sqrt_32f.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2014 Free Software Foundation, Inc.
4  *
5  * This file is part of GNU Radio
6  *
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  *
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with GNU Radio; see the file COPYING. If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 #ifndef INCLUDED_volk_32f_sqrt_32f_a_H
24 #define INCLUDED_volk_32f_sqrt_32f_a_H
25 
26 #include <inttypes.h>
27 #include <stdio.h>
28 #include <math.h>
29 
30 #ifdef LV_HAVE_SSE
31 #include <xmmintrin.h>
32 /*!
33  \brief Sqrts the two input vectors and store their results in the third vector
34  \param cVector The vector where the results will be stored
35  \param aVector One of the vectors to be sqrted
36  \param num_points The number of values in aVector and bVector to be sqrted together and stored into cVector
37 */
38 static inline void volk_32f_sqrt_32f_a_sse(float* cVector, const float* aVector, unsigned int num_points){
39  unsigned int number = 0;
40  const unsigned int quarterPoints = num_points / 4;
41 
42  float* cPtr = cVector;
43  const float* aPtr = aVector;
44 
45  __m128 aVal, cVal;
46  for(;number < quarterPoints; number++){
47 
48  aVal = _mm_load_ps(aPtr);
49 
50  cVal = _mm_sqrt_ps(aVal);
51 
52  _mm_store_ps(cPtr,cVal); // Store the results back into the C container
53 
54  aPtr += 4;
55  cPtr += 4;
56  }
57 
58  number = quarterPoints * 4;
59  for(;number < num_points; number++){
60  *cPtr++ = sqrtf(*aPtr++);
61  }
62 }
63 #endif /* LV_HAVE_SSE */
64 
65 #ifdef LV_HAVE_NEON
66 #include <arm_neon.h>
67 
68 /*!
69  \brief Sqrts the two input vectors and store their results in the third vector
70  \param cVector The vector where the results will be stored
71  \param aVector One of the vectors to be sqrted
72  \param num_points The number of values in aVector and bVector to be sqrted together and stored into cVector
73 */
74 static inline void volk_32f_sqrt_32f_neon(float* cVector, const float* aVector, unsigned int num_points){
75  float* cPtr = cVector;
76  const float* aPtr = aVector;
77  unsigned int number = 0;
78  unsigned int quarter_points = num_points / 4;
79  float32x4_t in_vec, out_vec;
80 
81  for(number = 0; number < quarter_points; number++){
82  in_vec = vld1q_f32(aPtr);
83  // note that armv8 has vsqrt_f32 which will be much better
84  out_vec = vrecpeq_f32(vrsqrteq_f32(in_vec) );
85  vst1q_f32(cPtr, out_vec);
86  aPtr += 4;
87  cPtr += 4;
88  }
89 
90  for(number = quarter_points * 4; number < num_points; number++){
91  *cPtr++ = sqrtf(*aPtr++);
92  }
93 }
94 #endif /* LV_HAVE_NEON */
95 
96 #ifdef LV_HAVE_GENERIC
97 /*!
98  \brief Sqrts the two input vectors and store their results in the third vector
99  \param cVector The vector where the results will be stored
100  \param aVector One of the vectors to be sqrted
101  \param num_points The number of values in aVector and bVector to be sqrted together and stored into cVector
102 */
103 static inline void volk_32f_sqrt_32f_generic(float* cVector, const float* aVector, unsigned int num_points){
104  float* cPtr = cVector;
105  const float* aPtr = aVector;
106  unsigned int number = 0;
107 
108  for(number = 0; number < num_points; number++){
109  *cPtr++ = sqrtf(*aPtr++);
110  }
111 }
112 #endif /* LV_HAVE_GENERIC */
113 
114 #ifdef LV_HAVE_ORC
115 extern void volk_32f_sqrt_32f_a_orc_impl(float *, const float*, unsigned int);
116 /*!
117  \brief Sqrts the two input vectors and store their results in the third vector
118  \param cVector The vector where the results will be stored
119  \param aVector One of the vectors to be sqrted
120  \param num_points The number of values in aVector and bVector to be sqrted together and stored into cVector
121 */
122 static inline void volk_32f_sqrt_32f_u_orc(float* cVector, const float* aVector, unsigned int num_points){
123  volk_32f_sqrt_32f_a_orc_impl(cVector, aVector, num_points);
124 }
125 
126 #endif /* LV_HAVE_ORC */
127 
128 
129 
130 #endif /* INCLUDED_volk_32f_sqrt_32f_a_H */