Vector Optimized Library of Kernels  2.0
Architecture-tuned implementations of math kernels
volk_32fc_x2_add_32fc.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2018 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 
73 #ifndef INCLUDED_volk_32fc_x2_add_32fc_u_H
74 #define INCLUDED_volk_32fc_x2_add_32fc_u_H
75 
76 #ifdef LV_HAVE_AVX
77 #include <immintrin.h>
78 
79 static inline void
81  const lv_32fc_t* bVector, unsigned int num_points)
82 {
83  unsigned int number = 0;
84  const unsigned int quarterPoints = num_points / 4;
85 
86  lv_32fc_t* cPtr = cVector;
87  const lv_32fc_t* aPtr = aVector;
88  const lv_32fc_t* bPtr= bVector;
89 
90  __m256 aVal, bVal, cVal;
91  for(;number < quarterPoints; number++){
92 
93  aVal = _mm256_loadu_ps((float *) aPtr);
94  bVal = _mm256_loadu_ps((float *) bPtr);
95 
96  cVal = _mm256_add_ps(aVal, bVal);
97 
98  _mm256_storeu_ps((float *) cPtr,cVal); // Store the results back into the C container
99 
100  aPtr += 4;
101  bPtr += 4;
102  cPtr += 4;
103  }
104 
105  number = quarterPoints * 4;
106  for(;number < num_points; number++){
107  *cPtr++ = (*aPtr++) + (*bPtr++);
108  }
109 }
110 #endif /* LV_HAVE_AVX */
111 
112 
113 #ifdef LV_HAVE_AVX
114 #include <immintrin.h>
115 
116 static inline void
118  const lv_32fc_t* bVector, unsigned int num_points)
119 {
120  unsigned int number = 0;
121  const unsigned int quarterPoints = num_points / 4;
122 
123  lv_32fc_t* cPtr = cVector;
124  const lv_32fc_t* aPtr = aVector;
125  const lv_32fc_t* bPtr= bVector;
126 
127  __m256 aVal, bVal, cVal;
128  for(;number < quarterPoints; number++){
129 
130  aVal = _mm256_load_ps((float*) aPtr);
131  bVal = _mm256_load_ps((float*) bPtr);
132 
133  cVal = _mm256_add_ps(aVal, bVal);
134 
135  _mm256_store_ps((float*) cPtr,cVal); // Store the results back into the C container
136 
137  aPtr += 4;
138  bPtr += 4;
139  cPtr += 4;
140  }
141 
142  number = quarterPoints * 4;
143  for(;number < num_points; number++){
144  *cPtr++ = (*aPtr++) + (*bPtr++);
145  }
146 }
147 #endif /* LV_HAVE_AVX */
148 
149 
150 #ifdef LV_HAVE_SSE
151 #include <xmmintrin.h>
152 
153 static inline void
155  const lv_32fc_t* bVector, unsigned int num_points)
156 {
157  unsigned int number = 0;
158  const unsigned int halfPoints = num_points / 2;
159 
160  lv_32fc_t* cPtr = cVector;
161  const lv_32fc_t* aPtr = aVector;
162  const lv_32fc_t* bPtr= bVector;
163 
164  __m128 aVal, bVal, cVal;
165  for(;number < halfPoints; number++){
166 
167  aVal = _mm_loadu_ps((float *) aPtr);
168  bVal = _mm_loadu_ps((float *) bPtr);
169 
170  cVal = _mm_add_ps(aVal, bVal);
171 
172  _mm_storeu_ps((float*) cPtr, cVal); // Store the results back into the C container
173 
174  aPtr += 2;
175  bPtr += 2;
176  cPtr += 2;
177  }
178 
179  number = halfPoints * 2;
180  for(;number < num_points; number++){
181  *cPtr++ = (*aPtr++) + (*bPtr++);
182  }
183 }
184 #endif /* LV_HAVE_SSE */
185 
186 
187 #ifdef LV_HAVE_GENERIC
188 
189 static inline void
191  const lv_32fc_t* bVector, unsigned int num_points)
192 {
193  lv_32fc_t* cPtr = cVector;
194  const lv_32fc_t* aPtr = aVector;
195  const lv_32fc_t* bPtr= bVector;
196  unsigned int number = 0;
197 
198  for(number = 0; number < num_points; number++){
199  *cPtr++ = (*aPtr++) + (*bPtr++);
200  }
201 }
202 #endif /* LV_HAVE_GENERIC */
203 
204 
205 #ifdef LV_HAVE_SSE
206 #include <xmmintrin.h>
207 
208 static inline void
209 volk_32fc_x2_add_32fc_a_sse(lv_32fc_t* cVector, const lv_32fc_t* aVector, const lv_32fc_t* bVector, unsigned int num_points)
210 {
211  unsigned int number = 0;
212  const unsigned int halfPoints = num_points / 2;
213 
214  lv_32fc_t* cPtr = cVector;
215  const lv_32fc_t* aPtr = aVector;
216  const lv_32fc_t* bPtr= bVector;
217 
218  __m128 aVal, bVal, cVal;
219  for(;number < halfPoints; number++){
220  aVal = _mm_load_ps((float *) aPtr);
221  bVal = _mm_load_ps((float *) bPtr);
222 
223  cVal = _mm_add_ps(aVal, bVal);
224 
225  _mm_store_ps((float *) cPtr,cVal); // Store the results back into the C container
226 
227  aPtr += 2;
228  bPtr += 2;
229  cPtr += 2;
230  }
231 
232  number = halfPoints * 2;
233  for(;number < num_points; number++){
234  *cPtr++ = (*aPtr++) + (*bPtr++);
235  }
236 }
237 #endif /* LV_HAVE_SSE */
238 
239 
240 #ifdef LV_HAVE_NEON
241 #include <arm_neon.h>
242 
243 static inline void
245  const lv_32fc_t* bVector, unsigned int num_points)
246 {
247  unsigned int number = 0;
248  const unsigned int halfPoints = num_points / 2;
249 
250  lv_32fc_t* cPtr = cVector;
251  const lv_32fc_t* aPtr = aVector;
252  const lv_32fc_t* bPtr= bVector;
253  float32x4_t aVal, bVal, cVal;
254  for(number=0; number < halfPoints; number++){
255  // Load in to NEON registers
256  aVal = vld1q_f32((const float32_t*)(aPtr));
257  bVal = vld1q_f32((const float32_t*)(bPtr));
258  __VOLK_PREFETCH(aPtr+2);
259  __VOLK_PREFETCH(bPtr+2);
260 
261  // vector add
262  cVal = vaddq_f32(aVal, bVal);
263  // Store the results back into the C container
264  vst1q_f32((float*)(cPtr),cVal);
265 
266  aPtr += 2; // q uses quadwords, 4 lv_32fc_ts per vadd
267  bPtr += 2;
268  cPtr += 2;
269  }
270 
271  number = halfPoints * 2; // should be = num_points
272  for(;number < num_points; number++){
273  *cPtr++ = (*aPtr++) + (*bPtr++);
274  }
275 }
276 
277 #endif /* LV_HAVE_NEON */
278 
279 
280 #endif /* INCLUDED_volk_32fc_x2_add_32fc_a_H */
static void volk_32fc_x2_add_32fc_u_neon(lv_32fc_t *cVector, const lv_32fc_t *aVector, const lv_32fc_t *bVector, unsigned int num_points)
Definition: volk_32fc_x2_add_32fc.h:244
static void volk_32fc_x2_add_32fc_u_avx(lv_32fc_t *cVector, const lv_32fc_t *aVector, const lv_32fc_t *bVector, unsigned int num_points)
Definition: volk_32fc_x2_add_32fc.h:80
#define __VOLK_PREFETCH(addr)
Definition: volk_common.h:39
static void volk_32fc_x2_add_32fc_a_avx(lv_32fc_t *cVector, const lv_32fc_t *aVector, const lv_32fc_t *bVector, unsigned int num_points)
Definition: volk_32fc_x2_add_32fc.h:117
float complex lv_32fc_t
Definition: volk_complex.h:61
static void volk_32fc_x2_add_32fc_u_sse(lv_32fc_t *cVector, const lv_32fc_t *aVector, const lv_32fc_t *bVector, unsigned int num_points)
Definition: volk_32fc_x2_add_32fc.h:154
static void volk_32fc_x2_add_32fc_a_sse(lv_32fc_t *cVector, const lv_32fc_t *aVector, const lv_32fc_t *bVector, unsigned int num_points)
Definition: volk_32fc_x2_add_32fc.h:209
static void volk_32fc_x2_add_32fc_generic(lv_32fc_t *cVector, const lv_32fc_t *aVector, const lv_32fc_t *bVector, unsigned int num_points)
Definition: volk_32fc_x2_add_32fc.h:190