Vector Optimized Library of Kernels  3.3.0
Architecture-tuned implementations of math kernels
volk_32f_s32f_add_32f.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2020 Free Software Foundation, Inc.
4  *
5  * This file is part of VOLK
6  *
7  * SPDX-License-Identifier: LGPL-3.0-or-later
8  */
9 
55 #include <inttypes.h>
56 #include <stdio.h>
57 
58 #ifndef INCLUDED_volk_32f_s32f_add_32f_u_H
59 #define INCLUDED_volk_32f_s32f_add_32f_u_H
60 
61 #ifdef LV_HAVE_GENERIC
62 
63 static inline void volk_32f_s32f_add_32f_generic(float* cVector,
64  const float* aVector,
65  const float scalar,
66  unsigned int num_points)
67 {
68  unsigned int number = 0;
69  const float* inputPtr = aVector;
70  float* outputPtr = cVector;
71  for (number = 0; number < num_points; number++) {
72  *outputPtr = (*inputPtr) + scalar;
73  inputPtr++;
74  outputPtr++;
75  }
76 }
77 
78 #endif /* LV_HAVE_GENERIC */
79 #ifdef LV_HAVE_SSE
80 #include <xmmintrin.h>
81 
82 static inline void volk_32f_s32f_add_32f_u_sse(float* cVector,
83  const float* aVector,
84  const float scalar,
85  unsigned int num_points)
86 {
87  unsigned int number = 0;
88  const unsigned int quarterPoints = num_points / 4;
89 
90  float* cPtr = cVector;
91  const float* aPtr = aVector;
92 
93  __m128 aVal, bVal, cVal;
94  bVal = _mm_set_ps1(scalar);
95  for (; number < quarterPoints; number++) {
96  aVal = _mm_loadu_ps(aPtr);
97 
98  cVal = _mm_add_ps(aVal, bVal);
99 
100  _mm_storeu_ps(cPtr, cVal); // Store the results back into the C container
101 
102  aPtr += 4;
103  cPtr += 4;
104  }
105 
106  number = quarterPoints * 4;
107  volk_32f_s32f_add_32f_generic(cPtr, aPtr, scalar, num_points - number);
108 }
109 #endif /* LV_HAVE_SSE */
110 
111 #ifdef LV_HAVE_AVX
112 #include <immintrin.h>
113 
114 static inline void volk_32f_s32f_add_32f_u_avx(float* cVector,
115  const float* aVector,
116  const float scalar,
117  unsigned int num_points)
118 {
119  unsigned int number = 0;
120  const unsigned int eighthPoints = num_points / 8;
121 
122  float* cPtr = cVector;
123  const float* aPtr = aVector;
124 
125  __m256 aVal, bVal, cVal;
126  bVal = _mm256_set1_ps(scalar);
127  for (; number < eighthPoints; number++) {
128 
129  aVal = _mm256_loadu_ps(aPtr);
130 
131  cVal = _mm256_add_ps(aVal, bVal);
132 
133  _mm256_storeu_ps(cPtr, cVal); // Store the results back into the C container
134 
135  aPtr += 8;
136  cPtr += 8;
137  }
138 
139  number = eighthPoints * 8;
140  volk_32f_s32f_add_32f_generic(cPtr, aPtr, scalar, num_points - number);
141 }
142 #endif /* LV_HAVE_AVX */
143 
144 #ifdef LV_HAVE_NEON
145 #include <arm_neon.h>
146 
147 static inline void volk_32f_s32f_add_32f_u_neon(float* cVector,
148  const float* aVector,
149  const float scalar,
150  unsigned int num_points)
151 {
152  unsigned int number = 0;
153  const float* inputPtr = aVector;
154  float* outputPtr = cVector;
155  const unsigned int quarterPoints = num_points / 4;
156 
157  float32x4_t aVal, cVal, scalarvec;
158 
159  scalarvec = vdupq_n_f32(scalar);
160 
161  for (number = 0; number < quarterPoints; number++) {
162  aVal = vld1q_f32(inputPtr); // Load into NEON regs
163  cVal = vaddq_f32(aVal, scalarvec); // Do the add
164  vst1q_f32(outputPtr, cVal); // Store results back to output
165  inputPtr += 4;
166  outputPtr += 4;
167  }
168 
169  number = quarterPoints * 4;
170  volk_32f_s32f_add_32f_generic(outputPtr, inputPtr, scalar, num_points - number);
171 }
172 #endif /* LV_HAVE_NEON */
173 
174 #ifdef LV_HAVE_NEONV8
175 #include <arm_neon.h>
176 
177 static inline void volk_32f_s32f_add_32f_neonv8(float* cVector,
178  const float* aVector,
179  const float scalar,
180  unsigned int num_points)
181 {
182  const unsigned int eighthPoints = num_points / 8;
183 
184  const float* aPtr = aVector;
185  float* cPtr = cVector;
186  const float32x4_t scalarVec = vdupq_n_f32(scalar);
187 
188  for (unsigned int number = 0; number < eighthPoints; number++) {
189  float32x4_t a0 = vld1q_f32(aPtr);
190  float32x4_t a1 = vld1q_f32(aPtr + 4);
191  __VOLK_PREFETCH(aPtr + 16);
192 
193  vst1q_f32(cPtr, vaddq_f32(a0, scalarVec));
194  vst1q_f32(cPtr + 4, vaddq_f32(a1, scalarVec));
195 
196  aPtr += 8;
197  cPtr += 8;
198  }
199 
200  for (unsigned int number = eighthPoints * 8; number < num_points; number++) {
201  *cPtr++ = (*aPtr++) + scalar;
202  }
203 }
204 #endif /* LV_HAVE_NEONV8 */
205 
206 
207 #endif /* INCLUDED_volk_32f_s32f_add_32f_u_H */
208 
209 
210 #ifndef INCLUDED_volk_32f_s32f_add_32f_a_H
211 #define INCLUDED_volk_32f_s32f_add_32f_a_H
212 
213 #ifdef LV_HAVE_SSE
214 #include <xmmintrin.h>
215 
216 static inline void volk_32f_s32f_add_32f_a_sse(float* cVector,
217  const float* aVector,
218  const float scalar,
219  unsigned int num_points)
220 {
221  unsigned int number = 0;
222  const unsigned int quarterPoints = num_points / 4;
223 
224  float* cPtr = cVector;
225  const float* aPtr = aVector;
226 
227  __m128 aVal, bVal, cVal;
228  bVal = _mm_set_ps1(scalar);
229  for (; number < quarterPoints; number++) {
230  aVal = _mm_load_ps(aPtr);
231 
232  cVal = _mm_add_ps(aVal, bVal);
233 
234  _mm_store_ps(cPtr, cVal); // Store the results back into the C container
235 
236  aPtr += 4;
237  cPtr += 4;
238  }
239 
240  number = quarterPoints * 4;
241  volk_32f_s32f_add_32f_generic(cPtr, aPtr, scalar, num_points - number);
242 }
243 #endif /* LV_HAVE_SSE */
244 
245 #ifdef LV_HAVE_AVX
246 #include <immintrin.h>
247 
248 static inline void volk_32f_s32f_add_32f_a_avx(float* cVector,
249  const float* aVector,
250  const float scalar,
251  unsigned int num_points)
252 {
253  unsigned int number = 0;
254  const unsigned int eighthPoints = num_points / 8;
255 
256  float* cPtr = cVector;
257  const float* aPtr = aVector;
258 
259  __m256 aVal, bVal, cVal;
260  bVal = _mm256_set1_ps(scalar);
261  for (; number < eighthPoints; number++) {
262  aVal = _mm256_load_ps(aPtr);
263 
264  cVal = _mm256_add_ps(aVal, bVal);
265 
266  _mm256_store_ps(cPtr, cVal); // Store the results back into the C container
267 
268  aPtr += 8;
269  cPtr += 8;
270  }
271 
272  number = eighthPoints * 8;
273  volk_32f_s32f_add_32f_generic(cPtr, aPtr, scalar, num_points - number);
274 }
275 #endif /* LV_HAVE_AVX */
276 
277 #ifdef LV_HAVE_ORC
278 
279 extern void volk_32f_s32f_add_32f_a_orc_impl(float* dst,
280  const float* src,
281  const float scalar,
282  int num_points);
283 
284 static inline void volk_32f_s32f_add_32f_u_orc(float* cVector,
285  const float* aVector,
286  const float scalar,
287  unsigned int num_points)
288 {
289  volk_32f_s32f_add_32f_a_orc_impl(cVector, aVector, scalar, num_points);
290 }
291 #endif /* LV_HAVE_ORC */
292 
293 #ifdef LV_HAVE_RVV
294 #include <riscv_vector.h>
295 
296 static inline void volk_32f_s32f_add_32f_rvv(float* cVector,
297  const float* aVector,
298  const float scalar,
299  unsigned int num_points)
300 {
301  size_t n = num_points;
302  for (size_t vl; n > 0; n -= vl, aVector += vl, cVector += vl) {
303  vl = __riscv_vsetvl_e32m8(n);
304  vfloat32m8_t v = __riscv_vle32_v_f32m8(aVector, vl);
305  __riscv_vse32(cVector, __riscv_vfadd(v, scalar, vl), vl);
306  }
307 }
308 #endif /*LV_HAVE_RVV*/
309 
310 #endif /* INCLUDED_volk_32f_s32f_add_32f_a_H */
volk_32f_s32f_add_32f_u_sse
static void volk_32f_s32f_add_32f_u_sse(float *cVector, const float *aVector, const float scalar, unsigned int num_points)
Definition: volk_32f_s32f_add_32f.h:82
volk_32f_s32f_add_32f_generic
static void volk_32f_s32f_add_32f_generic(float *cVector, const float *aVector, const float scalar, unsigned int num_points)
Definition: volk_32f_s32f_add_32f.h:63
volk_32f_s32f_add_32f_a_sse
static void volk_32f_s32f_add_32f_a_sse(float *cVector, const float *aVector, const float scalar, unsigned int num_points)
Definition: volk_32f_s32f_add_32f.h:216
__VOLK_PREFETCH
#define __VOLK_PREFETCH(addr)
Definition: volk_common.h:68
volk_32f_s32f_add_32f_a_avx
static void volk_32f_s32f_add_32f_a_avx(float *cVector, const float *aVector, const float scalar, unsigned int num_points)
Definition: volk_32f_s32f_add_32f.h:248
volk_32f_s32f_add_32f_u_avx
static void volk_32f_s32f_add_32f_u_avx(float *cVector, const float *aVector, const float scalar, unsigned int num_points)
Definition: volk_32f_s32f_add_32f.h:114
volk_32f_s32f_add_32f_u_neon
static void volk_32f_s32f_add_32f_u_neon(float *cVector, const float *aVector, const float scalar, unsigned int num_points)
Definition: volk_32f_s32f_add_32f.h:147