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