Vector Optimized Library of Kernels  2.0
Architecture-tuned implementations of math kernels
volk_32f_s32f_32f_fm_detect_32f.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2012, 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 
56 #ifndef INCLUDED_volk_32f_s32f_32f_fm_detect_32f_a_H
57 #define INCLUDED_volk_32f_s32f_32f_fm_detect_32f_a_H
58 
59 #include <inttypes.h>
60 #include <stdio.h>
61 
62 #ifdef LV_HAVE_AVX
63 #include <immintrin.h>
64 
65 static inline void volk_32f_s32f_32f_fm_detect_32f_a_avx(float* outputVector, const float* inputVector, const float bound, float* saveValue, unsigned int num_points){
66  if (num_points < 1) {
67  return;
68  }
69  unsigned int number = 1;
70  unsigned int j = 0;
71  // num_points-1 keeps Fedora 7's gcc from crashing...
72  // num_points won't work. :(
73  const unsigned int eighthPoints = (num_points-1) / 8;
74 
75  float* outPtr = outputVector;
76  const float* inPtr = inputVector;
77  __m256 upperBound = _mm256_set1_ps(bound);
78  __m256 lowerBound = _mm256_set1_ps(-bound);
79  __m256 next3old1;
80  __m256 next4;
81  __m256 boundAdjust;
82  __m256 posBoundAdjust = _mm256_set1_ps(-2*bound); // Subtract when we're above.
83  __m256 negBoundAdjust = _mm256_set1_ps(2*bound); // Add when we're below.
84  // Do the first 8 by hand since we're going in from the saveValue:
85  *outPtr = *inPtr - *saveValue;
86  if (*outPtr > bound) *outPtr -= 2*bound;
87  if (*outPtr < -bound) *outPtr += 2*bound;
88  inPtr++;
89  outPtr++;
90  for (j = 1; j < ( (8 < num_points) ? 8 : num_points); j++) {
91  *outPtr = *(inPtr) - *(inPtr-1);
92  if (*outPtr > bound) *outPtr -= 2*bound;
93  if (*outPtr < -bound) *outPtr += 2*bound;
94  inPtr++;
95  outPtr++;
96  }
97 
98  for (; number < eighthPoints; number++) {
99  // Load data
100  next3old1 = _mm256_loadu_ps((float*) (inPtr-1));
101  next4 = _mm256_load_ps(inPtr);
102  inPtr += 8;
103  // Subtract and store:
104  next3old1 = _mm256_sub_ps(next4, next3old1);
105  // Bound:
106  boundAdjust = _mm256_cmp_ps(next3old1, upperBound, 14);
107  boundAdjust = _mm256_and_ps(boundAdjust, posBoundAdjust);
108  next4 = _mm256_cmp_ps(next3old1, lowerBound, 1);
109  next4 = _mm256_and_ps(next4, negBoundAdjust);
110  boundAdjust = _mm256_or_ps(next4, boundAdjust);
111  // Make sure we're in the bounding interval:
112  next3old1 = _mm256_add_ps(next3old1, boundAdjust);
113  _mm256_store_ps(outPtr,next3old1); // Store the results back into the output
114  outPtr += 8;
115  }
116 
117  for (number = (8 > (eighthPoints*8) ? 8 : (8 * eighthPoints)); number < num_points; number++) {
118  *outPtr = *(inPtr) - *(inPtr-1);
119  if (*outPtr > bound) *outPtr -= 2*bound;
120  if (*outPtr < -bound) *outPtr += 2*bound;
121  inPtr++;
122  outPtr++;
123  }
124 
125  *saveValue = inputVector[num_points-1];
126 }
127 #endif /* LV_HAVE_AVX */
128 
129 
130 #ifdef LV_HAVE_SSE
131 #include <xmmintrin.h>
132 
133 static inline void volk_32f_s32f_32f_fm_detect_32f_a_sse(float* outputVector, const float* inputVector, const float bound, float* saveValue, unsigned int num_points){
134  if (num_points < 1) {
135  return;
136  }
137  unsigned int number = 1;
138  unsigned int j = 0;
139  // num_points-1 keeps Fedora 7's gcc from crashing...
140  // num_points won't work. :(
141  const unsigned int quarterPoints = (num_points-1) / 4;
142 
143  float* outPtr = outputVector;
144  const float* inPtr = inputVector;
145  __m128 upperBound = _mm_set_ps1(bound);
146  __m128 lowerBound = _mm_set_ps1(-bound);
147  __m128 next3old1;
148  __m128 next4;
149  __m128 boundAdjust;
150  __m128 posBoundAdjust = _mm_set_ps1(-2*bound); // Subtract when we're above.
151  __m128 negBoundAdjust = _mm_set_ps1(2*bound); // Add when we're below.
152  // Do the first 4 by hand since we're going in from the saveValue:
153  *outPtr = *inPtr - *saveValue;
154  if (*outPtr > bound) *outPtr -= 2*bound;
155  if (*outPtr < -bound) *outPtr += 2*bound;
156  inPtr++;
157  outPtr++;
158  for (j = 1; j < ( (4 < num_points) ? 4 : num_points); j++) {
159  *outPtr = *(inPtr) - *(inPtr-1);
160  if (*outPtr > bound) *outPtr -= 2*bound;
161  if (*outPtr < -bound) *outPtr += 2*bound;
162  inPtr++;
163  outPtr++;
164  }
165 
166  for (; number < quarterPoints; number++) {
167  // Load data
168  next3old1 = _mm_loadu_ps((float*) (inPtr-1));
169  next4 = _mm_load_ps(inPtr);
170  inPtr += 4;
171  // Subtract and store:
172  next3old1 = _mm_sub_ps(next4, next3old1);
173  // Bound:
174  boundAdjust = _mm_cmpgt_ps(next3old1, upperBound);
175  boundAdjust = _mm_and_ps(boundAdjust, posBoundAdjust);
176  next4 = _mm_cmplt_ps(next3old1, lowerBound);
177  next4 = _mm_and_ps(next4, negBoundAdjust);
178  boundAdjust = _mm_or_ps(next4, boundAdjust);
179  // Make sure we're in the bounding interval:
180  next3old1 = _mm_add_ps(next3old1, boundAdjust);
181  _mm_store_ps(outPtr,next3old1); // Store the results back into the output
182  outPtr += 4;
183  }
184 
185  for (number = (4 > (quarterPoints*4) ? 4 : (4 * quarterPoints)); number < num_points; number++) {
186  *outPtr = *(inPtr) - *(inPtr-1);
187  if (*outPtr > bound) *outPtr -= 2*bound;
188  if (*outPtr < -bound) *outPtr += 2*bound;
189  inPtr++;
190  outPtr++;
191  }
192 
193  *saveValue = inputVector[num_points-1];
194 }
195 #endif /* LV_HAVE_SSE */
196 
197 #ifdef LV_HAVE_GENERIC
198 
199 static inline void volk_32f_s32f_32f_fm_detect_32f_generic(float* outputVector, const float* inputVector, const float bound, float* saveValue, unsigned int num_points){
200  if (num_points < 1) {
201  return;
202  }
203  unsigned int number = 0;
204  float* outPtr = outputVector;
205  const float* inPtr = inputVector;
206 
207  // Do the first 1 by hand since we're going in from the saveValue:
208  *outPtr = *inPtr - *saveValue;
209  if (*outPtr > bound) *outPtr -= 2*bound;
210  if (*outPtr < -bound) *outPtr += 2*bound;
211  inPtr++;
212  outPtr++;
213 
214  for (number = 1; number < num_points; number++) {
215  *outPtr = *(inPtr) - *(inPtr-1);
216  if (*outPtr > bound) *outPtr -= 2*bound;
217  if (*outPtr < -bound) *outPtr += 2*bound;
218  inPtr++;
219  outPtr++;
220  }
221 
222  *saveValue = inputVector[num_points-1];
223 }
224 #endif /* LV_HAVE_GENERIC */
225 
226 
227 
228 
229 #endif /* INCLUDED_volk_32f_s32f_32f_fm_detect_32f_a_H */
230 
231 
232 #ifndef INCLUDED_volk_32f_s32f_32f_fm_detect_32f_u_H
233 #define INCLUDED_volk_32f_s32f_32f_fm_detect_32f_u_H
234 
235 #include <inttypes.h>
236 #include <stdio.h>
237 
238 #ifdef LV_HAVE_AVX
239 #include <immintrin.h>
240 
241 static inline void volk_32f_s32f_32f_fm_detect_32f_u_avx(float* outputVector, const float* inputVector, const float bound, float* saveValue, unsigned int num_points){
242  if (num_points < 1) {
243  return;
244  }
245  unsigned int number = 1;
246  unsigned int j = 0;
247  // num_points-1 keeps Fedora 7's gcc from crashing...
248  // num_points won't work. :(
249  const unsigned int eighthPoints = (num_points-1) / 8;
250 
251  float* outPtr = outputVector;
252  const float* inPtr = inputVector;
253  __m256 upperBound = _mm256_set1_ps(bound);
254  __m256 lowerBound = _mm256_set1_ps(-bound);
255  __m256 next3old1;
256  __m256 next4;
257  __m256 boundAdjust;
258  __m256 posBoundAdjust = _mm256_set1_ps(-2*bound); // Subtract when we're above.
259  __m256 negBoundAdjust = _mm256_set1_ps(2*bound); // Add when we're below.
260  // Do the first 8 by hand since we're going in from the saveValue:
261  *outPtr = *inPtr - *saveValue;
262  if (*outPtr > bound) *outPtr -= 2*bound;
263  if (*outPtr < -bound) *outPtr += 2*bound;
264  inPtr++;
265  outPtr++;
266  for (j = 1; j < ( (8 < num_points) ? 8 : num_points); j++) {
267  *outPtr = *(inPtr) - *(inPtr-1);
268  if (*outPtr > bound) *outPtr -= 2*bound;
269  if (*outPtr < -bound) *outPtr += 2*bound;
270  inPtr++;
271  outPtr++;
272  }
273 
274  for (; number < eighthPoints; number++) {
275  // Load data
276  next3old1 = _mm256_loadu_ps((float*) (inPtr-1));
277  next4 = _mm256_loadu_ps(inPtr);
278  inPtr += 8;
279  // Subtract and store:
280  next3old1 = _mm256_sub_ps(next4, next3old1);
281  // Bound:
282  boundAdjust = _mm256_cmp_ps(next3old1, upperBound, 14);
283  boundAdjust = _mm256_and_ps(boundAdjust, posBoundAdjust);
284  next4 = _mm256_cmp_ps(next3old1, lowerBound, 1);
285  next4 = _mm256_and_ps(next4, negBoundAdjust);
286  boundAdjust = _mm256_or_ps(next4, boundAdjust);
287  // Make sure we're in the bounding interval:
288  next3old1 = _mm256_add_ps(next3old1, boundAdjust);
289  _mm256_storeu_ps(outPtr,next3old1); // Store the results back into the output
290  outPtr += 8;
291  }
292 
293  for (number = (8 > (eighthPoints*8) ? 8 : (8 * eighthPoints)); number < num_points; number++) {
294  *outPtr = *(inPtr) - *(inPtr-1);
295  if (*outPtr > bound) *outPtr -= 2*bound;
296  if (*outPtr < -bound) *outPtr += 2*bound;
297  inPtr++;
298  outPtr++;
299  }
300 
301  *saveValue = inputVector[num_points-1];
302 }
303 #endif /* LV_HAVE_AVX */
304 
305 
306 #endif /* INCLUDED_volk_32f_s32f_32f_fm_detect_32f_u_H */
static void volk_32f_s32f_32f_fm_detect_32f_u_avx(float *outputVector, const float *inputVector, const float bound, float *saveValue, unsigned int num_points)
Definition: volk_32f_s32f_32f_fm_detect_32f.h:241
static void volk_32f_s32f_32f_fm_detect_32f_a_sse(float *outputVector, const float *inputVector, const float bound, float *saveValue, unsigned int num_points)
Definition: volk_32f_s32f_32f_fm_detect_32f.h:133
static void volk_32f_s32f_32f_fm_detect_32f_a_avx(float *outputVector, const float *inputVector, const float bound, float *saveValue, unsigned int num_points)
Definition: volk_32f_s32f_32f_fm_detect_32f.h:65
static void volk_32f_s32f_32f_fm_detect_32f_generic(float *outputVector, const float *inputVector, const float bound, float *saveValue, unsigned int num_points)
Definition: volk_32f_s32f_32f_fm_detect_32f.h:199