Vector Optimized Library of Kernels  2.0
Architecture-tuned implementations of math kernels
volk_32f_s32f_multiply_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 
69 #ifndef INCLUDED_volk_32f_s32f_multiply_32f_u_H
70 #define INCLUDED_volk_32f_s32f_multiply_32f_u_H
71 
72 #include <inttypes.h>
73 #include <stdio.h>
74 
75 #ifdef LV_HAVE_SSE
76 #include <xmmintrin.h>
77 
78 static inline void
79 volk_32f_s32f_multiply_32f_u_sse(float* cVector, const float* aVector,
80  const float scalar, unsigned int num_points)
81 {
82  unsigned int number = 0;
83  const unsigned int quarterPoints = num_points / 4;
84 
85  float* cPtr = cVector;
86  const float* aPtr = aVector;
87 
88  __m128 aVal, bVal, cVal;
89  bVal = _mm_set_ps1(scalar);
90  for(;number < quarterPoints; number++){
91  aVal = _mm_loadu_ps(aPtr);
92 
93  cVal = _mm_mul_ps(aVal, bVal);
94 
95  _mm_storeu_ps(cPtr,cVal); // Store the results back into the C container
96 
97  aPtr += 4;
98  cPtr += 4;
99  }
100 
101  number = quarterPoints * 4;
102  for(;number < num_points; number++){
103  *cPtr++ = (*aPtr++) * scalar;
104  }
105 }
106 #endif /* LV_HAVE_SSE */
107 
108 #ifdef LV_HAVE_AVX
109 #include <immintrin.h>
110 
111 static inline void
112 volk_32f_s32f_multiply_32f_u_avx(float* cVector, const float* aVector,
113  const float scalar, unsigned int num_points)
114 {
115  unsigned int number = 0;
116  const unsigned int eighthPoints = num_points / 8;
117 
118  float* cPtr = cVector;
119  const float* aPtr = aVector;
120 
121  __m256 aVal, bVal, cVal;
122  bVal = _mm256_set1_ps(scalar);
123  for(;number < eighthPoints; number++){
124 
125  aVal = _mm256_loadu_ps(aPtr);
126 
127  cVal = _mm256_mul_ps(aVal, bVal);
128 
129  _mm256_storeu_ps(cPtr,cVal); // Store the results back into the C container
130 
131  aPtr += 8;
132  cPtr += 8;
133  }
134 
135  number = eighthPoints * 8;
136  for(;number < num_points; number++){
137  *cPtr++ = (*aPtr++) * scalar;
138  }
139 }
140 #endif /* LV_HAVE_AVX */
141 
142 #ifdef LV_HAVE_GENERIC
143 
144 static inline void
145 volk_32f_s32f_multiply_32f_generic(float* cVector, const float* aVector,
146  const float scalar, unsigned int num_points)
147 {
148  unsigned int number = 0;
149  const float* inputPtr = aVector;
150  float* outputPtr = cVector;
151  for(number = 0; number < num_points; number++){
152  *outputPtr = (*inputPtr) * scalar;
153  inputPtr++;
154  outputPtr++;
155  }
156 }
157 #endif /* LV_HAVE_GENERIC */
158 
159 #endif /* INCLUDED_volk_32f_s32f_multiply_32f_u_H */
160 
161 
162 #ifndef INCLUDED_volk_32f_s32f_multiply_32f_a_H
163 #define INCLUDED_volk_32f_s32f_multiply_32f_a_H
164 
165 #include <inttypes.h>
166 #include <stdio.h>
167 
168 #ifdef LV_HAVE_SSE
169 #include <xmmintrin.h>
170 
171 static inline void
172 volk_32f_s32f_multiply_32f_a_sse(float* cVector, const float* aVector,
173  const float scalar, unsigned int num_points)
174 {
175  unsigned int number = 0;
176  const unsigned int quarterPoints = num_points / 4;
177 
178  float* cPtr = cVector;
179  const float* aPtr = aVector;
180 
181  __m128 aVal, bVal, cVal;
182  bVal = _mm_set_ps1(scalar);
183  for(;number < quarterPoints; number++){
184  aVal = _mm_load_ps(aPtr);
185 
186  cVal = _mm_mul_ps(aVal, bVal);
187 
188  _mm_store_ps(cPtr,cVal); // Store the results back into the C container
189 
190  aPtr += 4;
191  cPtr += 4;
192  }
193 
194  number = quarterPoints * 4;
195  for(;number < num_points; number++){
196  *cPtr++ = (*aPtr++) * scalar;
197  }
198 }
199 #endif /* LV_HAVE_SSE */
200 
201 #ifdef LV_HAVE_AVX
202 #include <immintrin.h>
203 
204 static inline void
205 volk_32f_s32f_multiply_32f_a_avx(float* cVector, const float* aVector,
206  const float scalar, unsigned int num_points)
207 {
208  unsigned int number = 0;
209  const unsigned int eighthPoints = num_points / 8;
210 
211  float* cPtr = cVector;
212  const float* aPtr = aVector;
213 
214  __m256 aVal, bVal, cVal;
215  bVal = _mm256_set1_ps(scalar);
216  for(;number < eighthPoints; number++){
217  aVal = _mm256_load_ps(aPtr);
218 
219  cVal = _mm256_mul_ps(aVal, bVal);
220 
221  _mm256_store_ps(cPtr,cVal); // Store the results back into the C container
222 
223  aPtr += 8;
224  cPtr += 8;
225  }
226 
227  number = eighthPoints * 8;
228  for(;number < num_points; number++){
229  *cPtr++ = (*aPtr++) * scalar;
230  }
231 }
232 #endif /* LV_HAVE_AVX */
233 
234 #ifdef LV_HAVE_NEON
235 #include <arm_neon.h>
236 
237 static inline void
238 volk_32f_s32f_multiply_32f_u_neon(float* cVector, const float* aVector,
239  const float scalar, unsigned int num_points)
240 {
241  unsigned int number = 0;
242  const float* inputPtr = aVector;
243  float* outputPtr = cVector;
244  const unsigned int quarterPoints = num_points / 4;
245 
246  float32x4_t aVal, cVal;
247 
248  for(number = 0; number < quarterPoints; number++){
249  aVal = vld1q_f32(inputPtr); // Load into NEON regs
250  cVal = vmulq_n_f32 (aVal, scalar); // Do the multiply
251  vst1q_f32(outputPtr, cVal); // Store results back to output
252  inputPtr += 4;
253  outputPtr += 4;
254  }
255  for(number = quarterPoints * 4; number < num_points; number++){
256  *outputPtr++ = (*inputPtr++) * scalar;
257  }
258 }
259 #endif /* LV_HAVE_NEON */
260 
261 
262 #ifdef LV_HAVE_GENERIC
263 
264 static inline void
265 volk_32f_s32f_multiply_32f_a_generic(float* cVector, const float* aVector,
266  const float scalar, unsigned int num_points)
267 {
268  unsigned int number = 0;
269  const float* inputPtr = aVector;
270  float* outputPtr = cVector;
271  for(number = 0; number < num_points; number++){
272  *outputPtr = (*inputPtr) * scalar;
273  inputPtr++;
274  outputPtr++;
275  }
276 }
277 #endif /* LV_HAVE_GENERIC */
278 
279 
280 #ifdef LV_HAVE_ORC
281 
282 extern void
283 volk_32f_s32f_multiply_32f_a_orc_impl(float* dst, const float* src,
284  const float scalar, unsigned int num_points);
285 
286 static inline void
287 volk_32f_s32f_multiply_32f_u_orc(float* cVector, const float* aVector,
288  const float scalar, unsigned int num_points)
289 {
290  volk_32f_s32f_multiply_32f_a_orc_impl(cVector, aVector, scalar, num_points);
291 }
292 
293 #endif /* LV_HAVE_GENERIC */
294 
295 #endif /* INCLUDED_volk_32f_s32f_multiply_32f_a_H */
static void volk_32f_s32f_multiply_32f_a_avx(float *cVector, const float *aVector, const float scalar, unsigned int num_points)
Definition: volk_32f_s32f_multiply_32f.h:205
static void volk_32f_s32f_multiply_32f_generic(float *cVector, const float *aVector, const float scalar, unsigned int num_points)
Definition: volk_32f_s32f_multiply_32f.h:145
static void volk_32f_s32f_multiply_32f_u_sse(float *cVector, const float *aVector, const float scalar, unsigned int num_points)
Definition: volk_32f_s32f_multiply_32f.h:79
static void volk_32f_s32f_multiply_32f_a_generic(float *cVector, const float *aVector, const float scalar, unsigned int num_points)
Definition: volk_32f_s32f_multiply_32f.h:265
static void volk_32f_s32f_multiply_32f_a_sse(float *cVector, const float *aVector, const float scalar, unsigned int num_points)
Definition: volk_32f_s32f_multiply_32f.h:172
static void volk_32f_s32f_multiply_32f_u_neon(float *cVector, const float *aVector, const float scalar, unsigned int num_points)
Definition: volk_32f_s32f_multiply_32f.h:238
static void volk_32f_s32f_multiply_32f_u_avx(float *cVector, const float *aVector, const float scalar, unsigned int num_points)
Definition: volk_32f_s32f_multiply_32f.h:112