GNU Radio Manual and C++ API Reference  3.7.7
The Free & Open Software Radio Ecosystem
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 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 
23 /*!
24  * \page volk_32f_s32f_normalize
25  *
26  * \b Overview
27  *
28  * Normalizes all points in the buffer by the scalar value (divides
29  * each data point by the scalar value).
30  *
31  * <b>Dispatcher Prototype</b>
32  * \code
33  * void volk_32f_s32f_normalize(float* vecBuffer, const float scalar, unsigned int num_points)
34  * \endcode
35  *
36  * \b Inputs
37  * \li vecBuffer: The buffer of values to be vectorized.
38  * \li scalar: The scale value to be applied to each buffer value.
39  * \li num_points: The number of data points.
40  *
41  * \b Outputs
42  * \li vecBuffer: returns as an in-place calculation.
43  *
44  * \b Example
45  * \code
46  * int N = 10;
47  * unsigned int alignment = volk_get_alignment();
48  * float* increasing = (float*)volk_malloc(sizeof(float)*N, alignment);
49  * float* out = (float*)volk_malloc(sizeof(float)*N, alignment);
50  *
51  *
52  * for(unsigned int ii = 0; ii < N; ++ii){
53  * increasing[ii] = 2.f * ((float)ii / (float)N) - 1.f;
54  * }
55  *
56  * // Normalize by the smallest delta (0.2 in this example)
57  * float scale = 5.0f;
58  *
59  * volk_32f_s32f_normalize(increasing, scale, N);
60  *
61  * for(unsigned int ii = 0; ii < N; ++ii){
62  * printf("increasing[%u] = %f\n", ii, increasing[ii]);
63  * }
64  *
65  * volk_free(increasing);
66  * volk_free(out);
67  * \endcode
68  */
69 
70 #ifndef INCLUDED_volk_32f_s32f_normalize_a_H
71 #define INCLUDED_volk_32f_s32f_normalize_a_H
72 
73 #include <inttypes.h>
74 #include <stdio.h>
75 
76 #ifdef LV_HAVE_SSE
77 #include <xmmintrin.h>
78 
79 static inline void volk_32f_s32f_normalize_a_sse(float* vecBuffer, const float scalar, unsigned int num_points){
80  unsigned int number = 0;
81  float* inputPtr = vecBuffer;
82 
83  const float invScalar = 1.0 / scalar;
84  __m128 vecScalar = _mm_set_ps1(invScalar);
85 
86  __m128 input1;
87 
88  const uint64_t quarterPoints = num_points / 4;
89  for(;number < quarterPoints; number++){
90 
91  input1 = _mm_load_ps(inputPtr);
92 
93  input1 = _mm_mul_ps(input1, vecScalar);
94 
95  _mm_store_ps(inputPtr, input1);
96 
97  inputPtr += 4;
98  }
99 
100  number = quarterPoints*4;
101  for(; number < num_points; number++){
102  *inputPtr *= invScalar;
103  inputPtr++;
104  }
105 }
106 #endif /* LV_HAVE_SSE */
107 
108 #ifdef LV_HAVE_GENERIC
109 
110 static inline void volk_32f_s32f_normalize_generic(float* vecBuffer, const float scalar, unsigned int num_points){
111  unsigned int number = 0;
112  float* inputPtr = vecBuffer;
113  const float invScalar = 1.0 / scalar;
114  for(number = 0; number < num_points; number++){
115  *inputPtr *= invScalar;
116  inputPtr++;
117  }
118 }
119 #endif /* LV_HAVE_GENERIC */
120 
121 #ifdef LV_HAVE_ORC
122 
123 extern void volk_32f_s32f_normalize_a_orc_impl(float* dst, float* src, const float scalar, unsigned int num_points);
124 static inline void volk_32f_s32f_normalize_u_orc(float* vecBuffer, const float scalar, unsigned int num_points){
125  float invscalar = 1.0 / scalar;
126  volk_32f_s32f_normalize_a_orc_impl(vecBuffer, vecBuffer, invscalar, num_points);
127 }
128 #endif /* LV_HAVE_GENERIC */
129 
130 
131 
132 
133 #endif /* INCLUDED_volk_32f_s32f_normalize_a_H */
unsigned __int64 uint64_t
Definition: stdint.h:90