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_64f_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_64f_convert_32f
25  *
26  * \b Overview
27  *
28  * Converts doubles into floats.
29  *
30  * <b>Dispatcher Prototype</b>
31  * \code
32  * void volk_64f_convert_32f(float* outputVector, const double* inputVector, unsigned int num_points)
33  * \endcode
34  *
35  * \b Inputs
36  * \li inputVector: The vector of doubles to convert to floats.
37  * \li num_points: The number of data points.
38  *
39  * \b Outputs
40  * \li outputVector: returns the converted floats.
41  *
42  * \b Example
43  * \code
44  * int N = 10;
45  * unsigned int alignment = volk_get_alignment();
46  * double* increasing = (double*)volk_malloc(sizeof(double)*N, alignment);
47  * float* out = (float*)volk_malloc(sizeof(float)*N, alignment);
48  *
49  * for(unsigned int ii = 0; ii < N; ++ii){
50  * increasing[ii] = (double)ii;
51  * }
52  *
53  * volk_64f_convert_32f(out, increasing, N);
54  *
55  * for(unsigned int ii = 0; ii < N; ++ii){
56  * printf("out[%u] = %1.2f\n", ii, out[ii]);
57  * }
58  *
59  * volk_free(increasing);
60  * volk_free(out);
61  * \endcode
62  */
63 
64 #ifndef INCLUDED_volk_64f_convert_32f_u_H
65 #define INCLUDED_volk_64f_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 volk_64f_convert_32f_u_sse2(float* outputVector, const double* inputVector, unsigned int num_points){
74  unsigned int number = 0;
75 
76  const unsigned int quarterPoints = num_points / 4;
77 
78  const double* inputVectorPtr = (const double*)inputVector;
79  float* outputVectorPtr = outputVector;
80  __m128 ret, ret2;
81  __m128d inputVal1, inputVal2;
82 
83  for(;number < quarterPoints; number++){
84  inputVal1 = _mm_loadu_pd(inputVectorPtr); inputVectorPtr += 2;
85  inputVal2 = _mm_loadu_pd(inputVectorPtr); inputVectorPtr += 2;
86 
87  ret = _mm_cvtpd_ps(inputVal1);
88  ret2 = _mm_cvtpd_ps(inputVal2);
89 
90  ret = _mm_movelh_ps(ret, ret2);
91 
92  _mm_storeu_ps(outputVectorPtr, ret);
93  outputVectorPtr += 4;
94  }
95 
96  number = quarterPoints * 4;
97  for(; number < num_points; number++){
98  outputVector[number] = (float)(inputVector[number]);
99  }
100 }
101 #endif /* LV_HAVE_SSE2 */
102 
103 
104 #ifdef LV_HAVE_GENERIC
105 
106 static inline void volk_64f_convert_32f_generic(float* outputVector, const double* inputVector, unsigned int num_points){
107  float* outputVectorPtr = outputVector;
108  const double* inputVectorPtr = inputVector;
109  unsigned int number = 0;
110 
111  for(number = 0; number < num_points; number++){
112  *outputVectorPtr++ = ((float)(*inputVectorPtr++));
113  }
114 }
115 #endif /* LV_HAVE_GENERIC */
116 
117 
118 
119 
120 #endif /* INCLUDED_volk_64f_convert_32f_u_H */
121 #ifndef INCLUDED_volk_64f_convert_32f_a_H
122 #define INCLUDED_volk_64f_convert_32f_a_H
123 
124 #include <inttypes.h>
125 #include <stdio.h>
126 
127 #ifdef LV_HAVE_SSE2
128 #include <emmintrin.h>
129 
130 static inline void volk_64f_convert_32f_a_sse2(float* outputVector, const double* inputVector, unsigned int num_points){
131  unsigned int number = 0;
132 
133  const unsigned int quarterPoints = num_points / 4;
134 
135  const double* inputVectorPtr = (const double*)inputVector;
136  float* outputVectorPtr = outputVector;
137  __m128 ret, ret2;
138  __m128d inputVal1, inputVal2;
139 
140  for(;number < quarterPoints; number++){
141  inputVal1 = _mm_load_pd(inputVectorPtr); inputVectorPtr += 2;
142  inputVal2 = _mm_load_pd(inputVectorPtr); inputVectorPtr += 2;
143 
144  ret = _mm_cvtpd_ps(inputVal1);
145  ret2 = _mm_cvtpd_ps(inputVal2);
146 
147  ret = _mm_movelh_ps(ret, ret2);
148 
149  _mm_store_ps(outputVectorPtr, ret);
150  outputVectorPtr += 4;
151  }
152 
153  number = quarterPoints * 4;
154  for(; number < num_points; number++){
155  outputVector[number] = (float)(inputVector[number]);
156  }
157 }
158 #endif /* LV_HAVE_SSE2 */
159 
160 
161 #ifdef LV_HAVE_GENERIC
162 
163 static inline void volk_64f_convert_32f_a_generic(float* outputVector, const double* inputVector, unsigned int num_points){
164  float* outputVectorPtr = outputVector;
165  const double* inputVectorPtr = inputVector;
166  unsigned int number = 0;
167 
168  for(number = 0; number < num_points; number++){
169  *outputVectorPtr++ = ((float)(*inputVectorPtr++));
170  }
171 }
172 #endif /* LV_HAVE_GENERIC */
173 
174 
175 
176 
177 #endif /* INCLUDED_volk_64f_convert_32f_a_H */