Vector Optimized Library of Kernels  3.3.0
Architecture-tuned implementations of math kernels
volk_32f_x2_min_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_min_32f_a_H
59 #define INCLUDED_volk_32f_x2_min_32f_a_H
60 
61 #include <inttypes.h>
62 #include <stdio.h>
63 
64 #ifdef LV_HAVE_SSE
65 #include <xmmintrin.h>
66 
67 static inline void volk_32f_x2_min_32f_a_sse(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 quarterPoints = num_points / 4;
74 
75  float* cPtr = cVector;
76  const float* aPtr = aVector;
77  const float* bPtr = bVector;
78 
79  __m128 aVal, bVal, cVal;
80  for (; number < quarterPoints; number++) {
81  aVal = _mm_load_ps(aPtr);
82  bVal = _mm_load_ps(bPtr);
83 
84  cVal = _mm_min_ps(aVal, bVal);
85 
86  _mm_store_ps(cPtr, cVal); // Store the results back into the C container
87 
88  aPtr += 4;
89  bPtr += 4;
90  cPtr += 4;
91  }
92 
93  number = quarterPoints * 4;
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_SSE */
101 
102 
103 #ifdef LV_HAVE_NEON
104 #include <arm_neon.h>
105 
106 static inline void volk_32f_x2_min_32f_neon(float* cVector,
107  const float* aVector,
108  const float* bVector,
109  unsigned int num_points)
110 {
111  float* cPtr = cVector;
112  const float* aPtr = aVector;
113  const float* bPtr = bVector;
114  unsigned int number = 0;
115  unsigned int quarter_points = num_points / 4;
116 
117  float32x4_t a_vec, b_vec, c_vec;
118  for (number = 0; number < quarter_points; number++) {
119  a_vec = vld1q_f32(aPtr);
120  b_vec = vld1q_f32(bPtr);
121 
122  c_vec = vminq_f32(a_vec, b_vec);
123 
124  vst1q_f32(cPtr, c_vec);
125  aPtr += 4;
126  bPtr += 4;
127  cPtr += 4;
128  }
129 
130  for (number = quarter_points * 4; number < num_points; number++) {
131  const float a = *aPtr++;
132  const float b = *bPtr++;
133  *cPtr++ = (a < b ? a : b);
134  }
135 }
136 #endif /* LV_HAVE_NEON */
137 
138 #ifdef LV_HAVE_NEONV8
139 #include <arm_neon.h>
140 
141 static inline void volk_32f_x2_min_32f_neonv8(float* cVector,
142  const float* aVector,
143  const float* bVector,
144  unsigned int num_points)
145 {
146  const unsigned int eighthPoints = num_points / 8;
147 
148  const float* aPtr = aVector;
149  const float* bPtr = bVector;
150  float* cPtr = cVector;
151 
152  for (unsigned int number = 0; number < eighthPoints; number++) {
153  float32x4_t a0 = vld1q_f32(aPtr);
154  float32x4_t a1 = vld1q_f32(aPtr + 4);
155  float32x4_t b0 = vld1q_f32(bPtr);
156  float32x4_t b1 = vld1q_f32(bPtr + 4);
157  __VOLK_PREFETCH(aPtr + 16);
158  __VOLK_PREFETCH(bPtr + 16);
159 
160  vst1q_f32(cPtr, vminq_f32(a0, b0));
161  vst1q_f32(cPtr + 4, vminq_f32(a1, b1));
162 
163  aPtr += 8;
164  bPtr += 8;
165  cPtr += 8;
166  }
167 
168  for (unsigned int number = eighthPoints * 8; number < num_points; number++) {
169  const float a = *aPtr++;
170  const float b = *bPtr++;
171  *cPtr++ = (a < b ? a : b);
172  }
173 }
174 #endif /* LV_HAVE_NEONV8 */
175 
176 
177 #ifdef LV_HAVE_GENERIC
178 
179 static inline void volk_32f_x2_min_32f_generic(float* cVector,
180  const float* aVector,
181  const float* bVector,
182  unsigned int num_points)
183 {
184  float* cPtr = cVector;
185  const float* aPtr = aVector;
186  const float* bPtr = bVector;
187  unsigned int number = 0;
188 
189  for (number = 0; number < num_points; number++) {
190  const float a = *aPtr++;
191  const float b = *bPtr++;
192  *cPtr++ = (a < b ? a : b);
193  }
194 }
195 #endif /* LV_HAVE_GENERIC */
196 
197 
198 #ifdef LV_HAVE_ORC
199 
200 extern void volk_32f_x2_min_32f_a_orc_impl(float* cVector,
201  const float* aVector,
202  const float* bVector,
203  int num_points);
204 
205 static inline void volk_32f_x2_min_32f_u_orc(float* cVector,
206  const float* aVector,
207  const float* bVector,
208  unsigned int num_points)
209 {
210  volk_32f_x2_min_32f_a_orc_impl(cVector, aVector, bVector, num_points);
211 }
212 #endif /* LV_HAVE_ORC */
213 
214 #ifdef LV_HAVE_AVX
215 #include <immintrin.h>
216 
217 static inline void volk_32f_x2_min_32f_a_avx(float* cVector,
218  const float* aVector,
219  const float* bVector,
220  unsigned int num_points)
221 {
222  unsigned int number = 0;
223  const unsigned int eighthPoints = num_points / 8;
224 
225  float* cPtr = cVector;
226  const float* aPtr = aVector;
227  const float* bPtr = bVector;
228 
229  __m256 aVal, bVal, cVal;
230  for (; number < eighthPoints; number++) {
231  aVal = _mm256_load_ps(aPtr);
232  bVal = _mm256_load_ps(bPtr);
233 
234  cVal = _mm256_min_ps(aVal, bVal);
235 
236  _mm256_store_ps(cPtr, cVal); // Store the results back into the C container
237 
238  aPtr += 8;
239  bPtr += 8;
240  cPtr += 8;
241  }
242 
243  number = eighthPoints * 8;
244  for (; number < num_points; number++) {
245  const float a = *aPtr++;
246  const float b = *bPtr++;
247  *cPtr++ = (a < b ? a : b);
248  }
249 }
250 #endif /* LV_HAVE_AVX */
251 
252 #ifdef LV_HAVE_AVX512F
253 #include <immintrin.h>
254 
255 static inline void volk_32f_x2_min_32f_a_avx512f(float* cVector,
256  const float* aVector,
257  const float* bVector,
258  unsigned int num_points)
259 {
260  unsigned int number = 0;
261  const unsigned int sixteenthPoints = num_points / 16;
262 
263  float* cPtr = cVector;
264  const float* aPtr = aVector;
265  const float* bPtr = bVector;
266 
267  __m512 aVal, bVal, cVal;
268  for (; number < sixteenthPoints; number++) {
269  aVal = _mm512_load_ps(aPtr);
270  bVal = _mm512_load_ps(bPtr);
271 
272  cVal = _mm512_min_ps(aVal, bVal);
273 
274  _mm512_store_ps(cPtr, cVal); // Store the results back into the C container
275 
276  aPtr += 16;
277  bPtr += 16;
278  cPtr += 16;
279  }
280 
281  number = sixteenthPoints * 16;
282  for (; number < num_points; number++) {
283  const float a = *aPtr++;
284  const float b = *bPtr++;
285  *cPtr++ = (a < b ? a : b);
286  }
287 }
288 #endif /* LV_HAVE_AVX512F */
289 
290 #endif /* INCLUDED_volk_32f_x2_min_32f_a_H */
291 
292 
293 #ifndef INCLUDED_volk_32f_x2_min_32f_u_H
294 #define INCLUDED_volk_32f_x2_min_32f_u_H
295 
296 #include <inttypes.h>
297 #include <stdio.h>
298 
299 #ifdef LV_HAVE_AVX512F
300 #include <immintrin.h>
301 
302 static inline void volk_32f_x2_min_32f_u_avx512f(float* cVector,
303  const float* aVector,
304  const float* bVector,
305  unsigned int num_points)
306 {
307  unsigned int number = 0;
308  const unsigned int sixteenthPoints = num_points / 16;
309 
310  float* cPtr = cVector;
311  const float* aPtr = aVector;
312  const float* bPtr = bVector;
313 
314  __m512 aVal, bVal, cVal;
315  for (; number < sixteenthPoints; number++) {
316  aVal = _mm512_loadu_ps(aPtr);
317  bVal = _mm512_loadu_ps(bPtr);
318 
319  cVal = _mm512_min_ps(aVal, bVal);
320 
321  _mm512_storeu_ps(cPtr, cVal); // Store the results back into the C container
322 
323  aPtr += 16;
324  bPtr += 16;
325  cPtr += 16;
326  }
327 
328  number = sixteenthPoints * 16;
329  for (; number < num_points; number++) {
330  const float a = *aPtr++;
331  const float b = *bPtr++;
332  *cPtr++ = (a < b ? a : b);
333  }
334 }
335 #endif /* LV_HAVE_AVX512F */
336 
337 #ifdef LV_HAVE_AVX
338 #include <immintrin.h>
339 
340 static inline void volk_32f_x2_min_32f_u_avx(float* cVector,
341  const float* aVector,
342  const float* bVector,
343  unsigned int num_points)
344 {
345  unsigned int number = 0;
346  const unsigned int eighthPoints = num_points / 8;
347 
348  float* cPtr = cVector;
349  const float* aPtr = aVector;
350  const float* bPtr = bVector;
351 
352  __m256 aVal, bVal, cVal;
353  for (; number < eighthPoints; number++) {
354  aVal = _mm256_loadu_ps(aPtr);
355  bVal = _mm256_loadu_ps(bPtr);
356 
357  cVal = _mm256_min_ps(aVal, bVal);
358 
359  _mm256_storeu_ps(cPtr, cVal); // Store the results back into the C container
360 
361  aPtr += 8;
362  bPtr += 8;
363  cPtr += 8;
364  }
365 
366  number = eighthPoints * 8;
367  for (; number < num_points; number++) {
368  const float a = *aPtr++;
369  const float b = *bPtr++;
370  *cPtr++ = (a < b ? a : b);
371  }
372 }
373 #endif /* LV_HAVE_AVX */
374 
375 #ifdef LV_HAVE_RVV
376 #include <riscv_vector.h>
377 
378 static inline void volk_32f_x2_min_32f_rvv(float* cVector,
379  const float* aVector,
380  const float* bVector,
381  unsigned int num_points)
382 {
383  size_t n = num_points;
384  for (size_t vl; n > 0; n -= vl, aVector += vl, bVector += vl, cVector += vl) {
385  vl = __riscv_vsetvl_e32m8(n);
386  vfloat32m8_t va = __riscv_vle32_v_f32m8(aVector, vl);
387  vfloat32m8_t vb = __riscv_vle32_v_f32m8(bVector, vl);
388  __riscv_vse32(cVector, __riscv_vfmin(va, vb, vl), vl);
389  }
390 }
391 #endif /*LV_HAVE_RVV*/
392 
393 #endif /* INCLUDED_volk_32f_x2_min_32f_u_H */
__VOLK_PREFETCH
#define __VOLK_PREFETCH(addr)
Definition: volk_common.h:68
volk_32f_x2_min_32f_a_avx
static void volk_32f_x2_min_32f_a_avx(float *cVector, const float *aVector, const float *bVector, unsigned int num_points)
Definition: volk_32f_x2_min_32f.h:217
volk_32f_x2_min_32f_generic
static void volk_32f_x2_min_32f_generic(float *cVector, const float *aVector, const float *bVector, unsigned int num_points)
Definition: volk_32f_x2_min_32f.h:179
volk_32f_x2_min_32f_neon
static void volk_32f_x2_min_32f_neon(float *cVector, const float *aVector, const float *bVector, unsigned int num_points)
Definition: volk_32f_x2_min_32f.h:106
volk_32f_x2_min_32f_a_sse
static void volk_32f_x2_min_32f_a_sse(float *cVector, const float *aVector, const float *bVector, unsigned int num_points)
Definition: volk_32f_x2_min_32f.h:67
volk_32f_x2_min_32f_u_avx
static void volk_32f_x2_min_32f_u_avx(float *cVector, const float *aVector, const float *bVector, unsigned int num_points)
Definition: volk_32f_x2_min_32f.h:340