GNU Radio Manual and C++ API Reference  3.7.4
The Free & Open Software Radio Ecosystem
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
volk_32f_binary_slicer_32i.h
Go to the documentation of this file.
1 #ifndef INCLUDED_volk_32f_binary_slicer_32f_H
2 #define INCLUDED_volk_32f_binary_slicer_32f_H
3 
4 
5 #ifdef LV_HAVE_GENERIC
6 /*!
7  \brief Returns integer 1 if float input is greater than or equal to 0, 1 otherwise
8  \param cVector The int output (either 0 or 1)
9  \param aVector The float input
10  \param num_points The number of values in aVector and stored into cVector
11 */
12 static inline void volk_32f_binary_slicer_32i_generic(int* cVector, const float* aVector, unsigned int num_points){
13  int* cPtr = cVector;
14  const float* aPtr = aVector;
15  unsigned int number = 0;
16 
17  for(number = 0; number < num_points; number++){
18  if( *aPtr++ >= 0) {
19  *cPtr++ = 1;
20  }
21  else {
22  *cPtr++ = 0;
23  }
24  }
25 }
26 #endif /* LV_HAVE_GENERIC */
27 
28 
29 #ifdef LV_HAVE_GENERIC
30 /*!
31  \brief Returns integer 1 if float input is greater than or equal to 0, 1 otherwise
32  \param cVector The int output (either 0 or 1)
33  \param aVector The float input
34  \param num_points The number of values in aVector and stored into cVector
35 */
36 static inline void volk_32f_binary_slicer_32i_generic_branchless(int* cVector, const float* aVector, unsigned int num_points){
37  int* cPtr = cVector;
38  const float* aPtr = aVector;
39  unsigned int number = 0;
40 
41  for(number = 0; number < num_points; number++){
42  *cPtr++ = (*aPtr++ >= 0);
43  }
44 }
45 #endif /* LV_HAVE_GENERIC */
46 
47 
48 #ifdef LV_HAVE_SSE2
49 #include <emmintrin.h>
50 /*!
51  \brief Returns integer 1 if float input is greater than or equal to 0, 1 otherwise
52  \param cVector The int output (either 0 or 1)
53  \param aVector The float input
54  \param num_points The number of values in aVector and stored into cVector
55 */
56 static inline void volk_32f_binary_slicer_32i_a_sse2(int* cVector, const float* aVector, unsigned int num_points){
57  int* cPtr = cVector;
58  const float* aPtr = aVector;
59  unsigned int number = 0;
60 
61  unsigned int quarter_points = num_points / 4;
62  __m128 a_val, res_f;
63  __m128i res_i, binary_i;
64  __m128 zero_val;
65  zero_val = _mm_set1_ps (0.0f);
66 
67  for(number = 0; number < quarter_points; number++){
68  a_val = _mm_load_ps(aPtr);
69 
70  res_f = _mm_cmpge_ps (a_val, zero_val);
71  res_i = _mm_cvtps_epi32 (res_f);
72  binary_i = _mm_srli_epi32 (res_i, 31);
73 
74 
75  _mm_store_si128((__m128i*)cPtr, binary_i);
76 
77 
78  cPtr += 4;
79  aPtr += 4;
80  }
81 
82  for(number = quarter_points * 4; number < num_points; number++){
83  if( *aPtr++ >= 0) {
84  *cPtr++ = 1;
85  }
86  else {
87  *cPtr++ = 0;
88  }
89  }
90 }
91 #endif /* LV_HAVE_SSE2 */
92 
93 
94 #ifdef LV_HAVE_AVX
95 #include <immintrin.h>
96 /*!
97  \brief Returns integer 1 if float input is greater than or equal to 0, 1 otherwise
98  \param cVector The int output (either 0 or 1)
99  \param aVector The float input
100  \param num_points The number of values in aVector and stored into cVector
101 */
102 static inline void volk_32f_binary_slicer_32i_a_avx(int* cVector, const float* aVector, unsigned int num_points){
103  int* cPtr = cVector;
104  const float* aPtr = aVector;
105  unsigned int number = 0;
106 
107  unsigned int quarter_points = num_points / 8;
108  __m256 a_val, res_f, binary_f;
109  __m256i binary_i;
110  __m256 zero_val, one_val;
111  zero_val = _mm256_set1_ps (0.0f);
112  one_val = _mm256_set1_ps (1.0f);
113 
114  for(number = 0; number < quarter_points; number++){
115  a_val = _mm256_load_ps(aPtr);
116 
117  res_f = _mm256_cmp_ps (a_val, zero_val, 13);
118  binary_f = _mm256_and_ps (res_f, one_val);
119  binary_i = _mm256_cvtps_epi32(binary_f);
120 
121 
122 
123  _mm256_store_si256((__m256i *)cPtr, binary_i);
124 
125 
126  cPtr += 8;
127  aPtr += 8;
128  }
129 
130  for(number = quarter_points * 8; number < num_points; number++){
131  if( *aPtr++ >= 0) {
132  *cPtr++ = 1;
133  }
134  else {
135  *cPtr++ = 0;
136  }
137  }
138 }
139 #endif /* LV_HAVE_SSE2 */
140 
141 
142 #ifdef LV_HAVE_SSE2
143 #include <emmintrin.h>
144 /*!
145  \brief Returns integer 1 if float input is greater than or equal to 0, 1 otherwise
146  \param cVector The int output (either 0 or 1)
147  \param aVector The float input
148  \param num_points The number of values in aVector and stored into cVector
149 */
150 static inline void volk_32f_binary_slicer_32i_u_sse2(int* cVector, const float* aVector, unsigned int num_points){
151  int* cPtr = cVector;
152  const float* aPtr = aVector;
153  unsigned int number = 0;
154 
155  unsigned int quarter_points = num_points / 4;
156  __m128 a_val, res_f;
157  __m128i res_i, binary_i;
158  __m128 zero_val;
159  zero_val = _mm_set1_ps (0.0f);
160 
161  for(number = 0; number < quarter_points; number++){
162  a_val = _mm_loadu_ps(aPtr);
163 
164  res_f = _mm_cmpge_ps (a_val, zero_val);
165  res_i = _mm_cvtps_epi32 (res_f);
166  binary_i = _mm_srli_epi32 (res_i, 31);
167 
168 
169  _mm_storeu_si128((__m128i*)cPtr, binary_i);
170 
171 
172  cPtr += 4;
173  aPtr += 4;
174  }
175 
176  for(number = quarter_points * 4; number < num_points; number++){
177  if( *aPtr++ >= 0) {
178  *cPtr++ = 1;
179  }
180  else {
181  *cPtr++ = 0;
182  }
183  }
184 }
185 #endif /* LV_HAVE_SSE2 */
186 
187 
188 #ifdef LV_HAVE_AVX
189 #include <immintrin.h>
190 /*!
191  \brief Returns integer 1 if float input is greater than or equal to 0, 1 otherwise
192  \param cVector The int output (either 0 or 1)
193  \param aVector The float input
194  \param num_points The number of values in aVector and stored into cVector
195 */
196 static inline void volk_32f_binary_slicer_32i_u_avx(int* cVector, const float* aVector, unsigned int num_points){
197  int* cPtr = cVector;
198  const float* aPtr = aVector;
199  unsigned int number = 0;
200 
201  unsigned int quarter_points = num_points / 8;
202  __m256 a_val, res_f, binary_f;
203  __m256i binary_i;
204  __m256 zero_val, one_val;
205  zero_val = _mm256_set1_ps (0.0f);
206  one_val = _mm256_set1_ps (1.0f);
207 
208  for(number = 0; number < quarter_points; number++){
209  a_val = _mm256_loadu_ps(aPtr);
210 
211  res_f = _mm256_cmp_ps (a_val, zero_val, 13);
212  binary_f = _mm256_and_ps (res_f, one_val);
213  binary_i = _mm256_cvtps_epi32(binary_f);
214 
215 
216 
217  _mm256_storeu_si256((__m256i*)cPtr, binary_i);
218 
219 
220  cPtr += 8;
221  aPtr += 8;
222  }
223 
224  for(number = quarter_points * 8; number < num_points; number++){
225  if( *aPtr++ >= 0) {
226  *cPtr++ = 1;
227  }
228  else {
229  *cPtr++ = 0;
230  }
231  }
232 }
233 #endif /* LV_HAVE_SSE2 */
234 
235 
236 
237 #endif /* INCLUDED_volk_32f_binary_slicer_32f_H */