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_32i_s32f_convert_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 
23 /*!
24  * \page volk_32i_s32f_convert_32f
25  *
26  * \b Overview
27  *
28  * Converts the samples in the inputVector from 32-bit integers into
29  * floating point values and then divides them by the input scalar.
30  *
31  * <b>Dispatcher Prototype</b>
32  * \code
33  * void volk_32i_s32f_convert_32f(float* outputVector, const int32_t* inputVector, const float scalar, unsigned int num_points)
34  * \endcode
35  *
36  * \b Inputs
37  * \li inputVector: The vector of 32-bit integers.
38  * \li scalar: The value that the output is divided by after being converted to a float.
39  * \li num_points: The number of values.
40  *
41  * \b Outputs
42  * \li complexVector: The output vector of floats.
43  *
44  * \b Example
45  * Convert full-range integers to floats in range [0,1].
46  * \code
47  * int N = 1<<8;
48  * unsigned int alignment = volk_get_alignment();
49  *
50  * int32_t* x = (int32_t*)volk_malloc(N*sizeof(int32_t), alignment);
51  * float* z = (float*)volk_malloc(N*sizeof(float), alignment);
52  * float scale = (float)N;
53  * for(unsigned int ii=0; ii<N; ++ii){
54  * x[ii] = ii;
55  * }
56  *
57  * volk_32i_s32f_convert_32f(z, x, scale, N);
58  *
59  * volk_free(x);
60  * volk_free(z);
61  * \endcode
62  */
63 
64 #ifndef INCLUDED_volk_32i_s32f_convert_32f_u_H
65 #define INCLUDED_volk_32i_s32f_convert_32f_u_H
66 
67 #include <inttypes.h>
68 #include <stdio.h>
69 
70 #ifdef LV_HAVE_SSE2
71 #include <emmintrin.h>
72 
73 static inline void
74 volk_32i_s32f_convert_32f_u_sse2(float* outputVector, const int32_t* inputVector,
75  const float scalar, unsigned int num_points)
76 {
77  unsigned int number = 0;
78  const unsigned int quarterPoints = num_points / 4;
79 
80  float* outputVectorPtr = outputVector;
81  const float iScalar = 1.0 / scalar;
82  __m128 invScalar = _mm_set_ps1(iScalar);
83  int32_t* inputPtr = (int32_t*)inputVector;
84  __m128i inputVal;
85  __m128 ret;
86 
87  for(;number < quarterPoints; number++){
88  // Load the 4 values
89  inputVal = _mm_loadu_si128((__m128i*)inputPtr);
90 
91  ret = _mm_cvtepi32_ps(inputVal);
92  ret = _mm_mul_ps(ret, invScalar);
93 
94  _mm_storeu_ps(outputVectorPtr, ret);
95 
96  outputVectorPtr += 4;
97  inputPtr += 4;
98  }
99 
100  number = quarterPoints * 4;
101  for(; number < num_points; number++){
102  outputVector[number] =((float)(inputVector[number])) * iScalar;
103  }
104 }
105 #endif /* LV_HAVE_SSE2 */
106 
107 
108 #ifdef LV_HAVE_GENERIC
109 
110 static inline void
111 volk_32i_s32f_convert_32f_generic(float* outputVector, const int32_t* inputVector,
112  const float scalar, unsigned int num_points)
113 {
114  float* outputVectorPtr = outputVector;
115  const int32_t* inputVectorPtr = inputVector;
116  unsigned int number = 0;
117  const float iScalar = 1.0 / scalar;
118 
119  for(number = 0; number < num_points; number++){
120  *outputVectorPtr++ = ((float)(*inputVectorPtr++)) * iScalar;
121  }
122 }
123 #endif /* LV_HAVE_GENERIC */
124 
125 #endif /* INCLUDED_volk_32i_s32f_convert_32f_u_H */
126 
127 
128 
129 #ifndef INCLUDED_volk_32i_s32f_convert_32f_a_H
130 #define INCLUDED_volk_32i_s32f_convert_32f_a_H
131 
132 #include <inttypes.h>
133 #include <stdio.h>
134 
135 #ifdef LV_HAVE_SSE2
136 #include <emmintrin.h>
137 
138 static inline void
139 volk_32i_s32f_convert_32f_a_sse2(float* outputVector, const int32_t* inputVector,
140  const float scalar, unsigned int num_points)
141 {
142  unsigned int number = 0;
143  const unsigned int quarterPoints = num_points / 4;
144 
145  float* outputVectorPtr = outputVector;
146  const float iScalar = 1.0 / scalar;
147  __m128 invScalar = _mm_set_ps1(iScalar);
148  int32_t* inputPtr = (int32_t*)inputVector;
149  __m128i inputVal;
150  __m128 ret;
151 
152  for(;number < quarterPoints; number++){
153  // Load the 4 values
154  inputVal = _mm_load_si128((__m128i*)inputPtr);
155 
156  ret = _mm_cvtepi32_ps(inputVal);
157  ret = _mm_mul_ps(ret, invScalar);
158 
159  _mm_store_ps(outputVectorPtr, ret);
160 
161  outputVectorPtr += 4;
162  inputPtr += 4;
163  }
164 
165  number = quarterPoints * 4;
166  for(; number < num_points; number++){
167  outputVector[number] =((float)(inputVector[number])) * iScalar;
168  }
169 }
170 #endif /* LV_HAVE_SSE2 */
171 
172 
173 #ifdef LV_HAVE_GENERIC
174 
175 static inline void
176 volk_32i_s32f_convert_32f_a_generic(float* outputVector, const int32_t* inputVector,
177  const float scalar, unsigned int num_points)
178 {
179  float* outputVectorPtr = outputVector;
180  const int32_t* inputVectorPtr = inputVector;
181  unsigned int number = 0;
182  const float iScalar = 1.0 / scalar;
183 
184  for(number = 0; number < num_points; number++){
185  *outputVectorPtr++ = ((float)(*inputVectorPtr++)) * iScalar;
186  }
187 }
188 #endif /* LV_HAVE_GENERIC */
189 
190 
191 
192 
193 #endif /* INCLUDED_volk_32i_s32f_convert_32f_a_H */
signed int int32_t
Definition: stdint.h:77