Vector Optimized Library of Kernels  2.4
Architecture-tuned implementations of math kernels
volk_32f_x2_subtract_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 
71 #ifndef INCLUDED_volk_32f_x2_subtract_32f_a_H
72 #define INCLUDED_volk_32f_x2_subtract_32f_a_H
73 
74 #include <inttypes.h>
75 #include <stdio.h>
76 
77 #ifdef LV_HAVE_AVX512F
78 #include <immintrin.h>
79 
80 static inline void volk_32f_x2_subtract_32f_a_avx512f(float* cVector,
81  const float* aVector,
82  const float* bVector,
83  unsigned int num_points)
84 {
85  unsigned int number = 0;
86  const unsigned int sixteenthPoints = num_points / 16;
87 
88  float* cPtr = cVector;
89  const float* aPtr = aVector;
90  const float* bPtr = bVector;
91 
92  __m512 aVal, bVal, cVal;
93  for (; number < sixteenthPoints; number++) {
94 
95  aVal = _mm512_load_ps(aPtr);
96  bVal = _mm512_load_ps(bPtr);
97 
98  cVal = _mm512_sub_ps(aVal, bVal);
99 
100  _mm512_store_ps(cPtr, cVal); // Store the results back into the C container
101 
102  aPtr += 16;
103  bPtr += 16;
104  cPtr += 16;
105  }
106 
107  number = sixteenthPoints * 16;
108  for (; number < num_points; number++) {
109  *cPtr++ = (*aPtr++) - (*bPtr++);
110  }
111 }
112 #endif /* LV_HAVE_AVX512F */
113 
114 #ifdef LV_HAVE_AVX
115 #include <immintrin.h>
116 
117 static inline void volk_32f_x2_subtract_32f_a_avx(float* cVector,
118  const float* aVector,
119  const float* bVector,
120  unsigned int num_points)
121 {
122  unsigned int number = 0;
123  const unsigned int eighthPoints = num_points / 8;
124 
125  float* cPtr = cVector;
126  const float* aPtr = aVector;
127  const float* bPtr = bVector;
128 
129  __m256 aVal, bVal, cVal;
130  for (; number < eighthPoints; number++) {
131 
132  aVal = _mm256_load_ps(aPtr);
133  bVal = _mm256_load_ps(bPtr);
134 
135  cVal = _mm256_sub_ps(aVal, bVal);
136 
137  _mm256_store_ps(cPtr, cVal); // Store the results back into the C container
138 
139  aPtr += 8;
140  bPtr += 8;
141  cPtr += 8;
142  }
143 
144  number = eighthPoints * 8;
145  for (; number < num_points; number++) {
146  *cPtr++ = (*aPtr++) - (*bPtr++);
147  }
148 }
149 #endif /* LV_HAVE_AVX */
150 
151 #ifdef LV_HAVE_SSE
152 #include <xmmintrin.h>
153 
154 static inline void volk_32f_x2_subtract_32f_a_sse(float* cVector,
155  const float* aVector,
156  const float* bVector,
157  unsigned int num_points)
158 {
159  unsigned int number = 0;
160  const unsigned int quarterPoints = num_points / 4;
161 
162  float* cPtr = cVector;
163  const float* aPtr = aVector;
164  const float* bPtr = bVector;
165 
166  __m128 aVal, bVal, cVal;
167  for (; number < quarterPoints; number++) {
168 
169  aVal = _mm_load_ps(aPtr);
170  bVal = _mm_load_ps(bPtr);
171 
172  cVal = _mm_sub_ps(aVal, bVal);
173 
174  _mm_store_ps(cPtr, cVal); // Store the results back into the C container
175 
176  aPtr += 4;
177  bPtr += 4;
178  cPtr += 4;
179  }
180 
181  number = quarterPoints * 4;
182  for (; number < num_points; number++) {
183  *cPtr++ = (*aPtr++) - (*bPtr++);
184  }
185 }
186 #endif /* LV_HAVE_SSE */
187 
188 
189 #ifdef LV_HAVE_GENERIC
190 
191 static inline void volk_32f_x2_subtract_32f_generic(float* cVector,
192  const float* aVector,
193  const float* bVector,
194  unsigned int num_points)
195 {
196  float* cPtr = cVector;
197  const float* aPtr = aVector;
198  const float* bPtr = bVector;
199  unsigned int number = 0;
200 
201  for (number = 0; number < num_points; number++) {
202  *cPtr++ = (*aPtr++) - (*bPtr++);
203  }
204 }
205 #endif /* LV_HAVE_GENERIC */
206 
207 
208 #ifdef LV_HAVE_NEON
209 #include <arm_neon.h>
210 
211 static inline void volk_32f_x2_subtract_32f_neon(float* cVector,
212  const float* aVector,
213  const float* bVector,
214  unsigned int num_points)
215 {
216  float* cPtr = cVector;
217  const float* aPtr = aVector;
218  const float* bPtr = bVector;
219  unsigned int number = 0;
220  unsigned int quarter_points = num_points / 4;
221 
222  float32x4_t a_vec, b_vec, c_vec;
223 
224  for (number = 0; number < quarter_points; number++) {
225  a_vec = vld1q_f32(aPtr);
226  b_vec = vld1q_f32(bPtr);
227  c_vec = vsubq_f32(a_vec, b_vec);
228  vst1q_f32(cPtr, c_vec);
229  aPtr += 4;
230  bPtr += 4;
231  cPtr += 4;
232  }
233 
234  for (number = quarter_points * 4; number < num_points; number++) {
235  *cPtr++ = (*aPtr++) - (*bPtr++);
236  }
237 }
238 #endif /* LV_HAVE_NEON */
239 
240 
241 #ifdef LV_HAVE_ORC
242 extern void volk_32f_x2_subtract_32f_a_orc_impl(float* cVector,
243  const float* aVector,
244  const float* bVector,
245  unsigned int num_points);
246 
247 static inline void volk_32f_x2_subtract_32f_u_orc(float* cVector,
248  const float* aVector,
249  const float* bVector,
250  unsigned int num_points)
251 {
252  volk_32f_x2_subtract_32f_a_orc_impl(cVector, aVector, bVector, num_points);
253 }
254 #endif /* LV_HAVE_ORC */
255 
256 
257 #endif /* INCLUDED_volk_32f_x2_subtract_32f_a_H */
258 
259 
260 #ifndef INCLUDED_volk_32f_x2_subtract_32f_u_H
261 #define INCLUDED_volk_32f_x2_subtract_32f_u_H
262 
263 #include <inttypes.h>
264 #include <stdio.h>
265 
266 #ifdef LV_HAVE_AVX512F
267 #include <immintrin.h>
268 
269 static inline void volk_32f_x2_subtract_32f_u_avx512f(float* cVector,
270  const float* aVector,
271  const float* bVector,
272  unsigned int num_points)
273 {
274  unsigned int number = 0;
275  const unsigned int sixteenthPoints = num_points / 16;
276 
277  float* cPtr = cVector;
278  const float* aPtr = aVector;
279  const float* bPtr = bVector;
280 
281  __m512 aVal, bVal, cVal;
282  for (; number < sixteenthPoints; number++) {
283 
284  aVal = _mm512_loadu_ps(aPtr);
285  bVal = _mm512_loadu_ps(bPtr);
286 
287  cVal = _mm512_sub_ps(aVal, bVal);
288 
289  _mm512_storeu_ps(cPtr, cVal); // Store the results back into the C container
290 
291  aPtr += 16;
292  bPtr += 16;
293  cPtr += 16;
294  }
295 
296  number = sixteenthPoints * 16;
297  for (; number < num_points; number++) {
298  *cPtr++ = (*aPtr++) - (*bPtr++);
299  }
300 }
301 #endif /* LV_HAVE_AVX512F */
302 
303 
304 #ifdef LV_HAVE_AVX
305 #include <immintrin.h>
306 
307 static inline void volk_32f_x2_subtract_32f_u_avx(float* cVector,
308  const float* aVector,
309  const float* bVector,
310  unsigned int num_points)
311 {
312  unsigned int number = 0;
313  const unsigned int eighthPoints = num_points / 8;
314 
315  float* cPtr = cVector;
316  const float* aPtr = aVector;
317  const float* bPtr = bVector;
318 
319  __m256 aVal, bVal, cVal;
320  for (; number < eighthPoints; number++) {
321 
322  aVal = _mm256_loadu_ps(aPtr);
323  bVal = _mm256_loadu_ps(bPtr);
324 
325  cVal = _mm256_sub_ps(aVal, bVal);
326 
327  _mm256_storeu_ps(cPtr, cVal); // Store the results back into the C container
328 
329  aPtr += 8;
330  bPtr += 8;
331  cPtr += 8;
332  }
333 
334  number = eighthPoints * 8;
335  for (; number < num_points; number++) {
336  *cPtr++ = (*aPtr++) - (*bPtr++);
337  }
338 }
339 #endif /* LV_HAVE_AVX */
340 
341 #endif /* INCLUDED_volk_32f_x2_subtract_32f_u_H */
static void volk_32f_x2_subtract_32f_a_avx(float *cVector, const float *aVector, const float *bVector, unsigned int num_points)
Definition: volk_32f_x2_subtract_32f.h:117
static void volk_32f_x2_subtract_32f_neon(float *cVector, const float *aVector, const float *bVector, unsigned int num_points)
Definition: volk_32f_x2_subtract_32f.h:211
static void volk_32f_x2_subtract_32f_generic(float *cVector, const float *aVector, const float *bVector, unsigned int num_points)
Definition: volk_32f_x2_subtract_32f.h:191
static void volk_32f_x2_subtract_32f_a_sse(float *cVector, const float *aVector, const float *bVector, unsigned int num_points)
Definition: volk_32f_x2_subtract_32f.h:154
static void volk_32f_x2_subtract_32f_u_avx(float *cVector, const float *aVector, const float *bVector, unsigned int num_points)
Definition: volk_32f_x2_subtract_32f.h:307