Vector Optimized Library of Kernels  3.0.0
Architecture-tuned implementations of math kernels
volk_32f_s32f_normalize.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 
57 #ifndef INCLUDED_volk_32f_s32f_normalize_a_H
58 #define INCLUDED_volk_32f_s32f_normalize_a_H
59 
60 #include <inttypes.h>
61 #include <stdio.h>
62 
63 #ifdef LV_HAVE_AVX
64 #include <immintrin.h>
65 
66 static inline void volk_32f_s32f_normalize_a_avx(float* vecBuffer,
67  const float scalar,
68  unsigned int num_points)
69 {
70  unsigned int number = 0;
71  float* inputPtr = vecBuffer;
72 
73  const float invScalar = 1.0 / scalar;
74  __m256 vecScalar = _mm256_set1_ps(invScalar);
75 
76  __m256 input1;
77 
78  const uint64_t eighthPoints = num_points / 8;
79  for (; number < eighthPoints; number++) {
80 
81  input1 = _mm256_load_ps(inputPtr);
82 
83  input1 = _mm256_mul_ps(input1, vecScalar);
84 
85  _mm256_store_ps(inputPtr, input1);
86 
87  inputPtr += 8;
88  }
89 
90  number = eighthPoints * 8;
91  for (; number < num_points; number++) {
92  *inputPtr *= invScalar;
93  inputPtr++;
94  }
95 }
96 #endif /* LV_HAVE_AVX */
97 
98 #ifdef LV_HAVE_SSE
99 #include <xmmintrin.h>
100 
101 static inline void volk_32f_s32f_normalize_a_sse(float* vecBuffer,
102  const float scalar,
103  unsigned int num_points)
104 {
105  unsigned int number = 0;
106  float* inputPtr = vecBuffer;
107 
108  const float invScalar = 1.0 / scalar;
109  __m128 vecScalar = _mm_set_ps1(invScalar);
110 
111  __m128 input1;
112 
113  const uint64_t quarterPoints = num_points / 4;
114  for (; number < quarterPoints; number++) {
115 
116  input1 = _mm_load_ps(inputPtr);
117 
118  input1 = _mm_mul_ps(input1, vecScalar);
119 
120  _mm_store_ps(inputPtr, input1);
121 
122  inputPtr += 4;
123  }
124 
125  number = quarterPoints * 4;
126  for (; number < num_points; number++) {
127  *inputPtr *= invScalar;
128  inputPtr++;
129  }
130 }
131 #endif /* LV_HAVE_SSE */
132 
133 #ifdef LV_HAVE_GENERIC
134 
135 static inline void volk_32f_s32f_normalize_generic(float* vecBuffer,
136  const float scalar,
137  unsigned int num_points)
138 {
139  unsigned int number = 0;
140  float* inputPtr = vecBuffer;
141  const float invScalar = 1.0 / scalar;
142  for (number = 0; number < num_points; number++) {
143  *inputPtr *= invScalar;
144  inputPtr++;
145  }
146 }
147 #endif /* LV_HAVE_GENERIC */
148 
149 #ifdef LV_HAVE_ORC
150 
151 extern void volk_32f_s32f_normalize_a_orc_impl(float* dst,
152  float* src,
153  const float scalar,
154  unsigned int num_points);
155 static inline void volk_32f_s32f_normalize_u_orc(float* vecBuffer,
156  const float scalar,
157  unsigned int num_points)
158 {
159  float invscalar = 1.0 / scalar;
160  volk_32f_s32f_normalize_a_orc_impl(vecBuffer, vecBuffer, invscalar, num_points);
161 }
162 #endif /* LV_HAVE_GENERIC */
163 
164 #endif /* INCLUDED_volk_32f_s32f_normalize_a_H */
165 
166 #ifndef INCLUDED_volk_32f_s32f_normalize_u_H
167 #define INCLUDED_volk_32f_s32f_normalize_u_H
168 
169 #include <inttypes.h>
170 #include <stdio.h>
171 #ifdef LV_HAVE_AVX
172 #include <immintrin.h>
173 
174 static inline void volk_32f_s32f_normalize_u_avx(float* vecBuffer,
175  const float scalar,
176  unsigned int num_points)
177 {
178  unsigned int number = 0;
179  float* inputPtr = vecBuffer;
180 
181  const float invScalar = 1.0 / scalar;
182  __m256 vecScalar = _mm256_set1_ps(invScalar);
183 
184  __m256 input1;
185 
186  const uint64_t eighthPoints = num_points / 8;
187  for (; number < eighthPoints; number++) {
188 
189  input1 = _mm256_loadu_ps(inputPtr);
190 
191  input1 = _mm256_mul_ps(input1, vecScalar);
192 
193  _mm256_storeu_ps(inputPtr, input1);
194 
195  inputPtr += 8;
196  }
197 
198  number = eighthPoints * 8;
199  for (; number < num_points; number++) {
200  *inputPtr *= invScalar;
201  inputPtr++;
202  }
203 }
204 #endif /* LV_HAVE_AVX */
205 
206 
207 #endif /* INCLUDED_volk_32f_s32f_normalize_u_H */
float32x4_t __m128
Definition: sse2neon.h:235
FORCE_INLINE __m128 _mm_mul_ps(__m128 a, __m128 b)
Definition: sse2neon.h:2205
FORCE_INLINE __m128 _mm_set_ps1(float)
Definition: sse2neon.h:2437
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
static void volk_32f_s32f_normalize_a_avx(float *vecBuffer, const float scalar, unsigned int num_points)
Definition: volk_32f_s32f_normalize.h:66
static void volk_32f_s32f_normalize_u_avx(float *vecBuffer, const float scalar, unsigned int num_points)
Definition: volk_32f_s32f_normalize.h:174
static void volk_32f_s32f_normalize_generic(float *vecBuffer, const float scalar, unsigned int num_points)
Definition: volk_32f_s32f_normalize.h:135
static void volk_32f_s32f_normalize_a_sse(float *vecBuffer, const float scalar, unsigned int num_points)
Definition: volk_32f_s32f_normalize.h:101