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_x2_subtract_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_32f_x2_subtract_32f
25  *
26  * \b Overview
27  *
28  * Subtracts values in bVector from values in aVector.
29  *
30  * c[i] = a[i] - b[i]
31  *
32  * <b>Dispatcher Prototype</b>
33  * \code
34  * void volk_32f_x2_subtract_32f(float* cVector, const float* aVector, const float* bVector, unsigned int num_points)
35  * \endcode
36  *
37  * \b Inputs
38  * \li aVector: The initial vector.
39  * \li bVector: The vector to be subtracted.
40  * \li num_points: The number of values in both input vectors.
41  *
42  * \b Outputs
43  * \li complexVector: The output vector.
44  *
45  * \b Example
46  * Subtract and increasing vector from a decreasing vector.
47  * \code
48  * int N = 10;
49  * unsigned int alignment = volk_get_alignment();
50  * float* increasing = (float*)volk_malloc(sizeof(float)*N, alignment);
51  * float* decreasing = (float*)volk_malloc(sizeof(float)*N, alignment);
52  * float* out = (float*)volk_malloc(sizeof(float)*N, alignment);
53  *
54  * for(unsigned int ii = 0; ii < N; ++ii){
55  * increasing[ii] = (float)ii;
56  * decreasing[ii] = 10.f - (float)ii;
57  * }
58  *
59  * volk_32f_x2_subtract_32f(out, increasing, decreasing, N);
60  *
61  * for(unsigned int ii = 0; ii < N; ++ii){
62  * printf("out[%u] = %1.2f\n", ii, out[ii]);
63  * }
64  *
65  * volk_free(increasing);
66  * volk_free(decreasing);
67  * volk_free(out);
68  * \endcode
69  */
70 
71 #ifndef INCLUDED_volk_32f_x2_subtract_32f_a_H
72 #define INCLUDED_volk_32f_x2_subtract_32f_a_H
73 
74 #include <inttypes.h>
75 #include <stdio.h>
76 
77 #ifdef LV_HAVE_SSE
78 #include <xmmintrin.h>
79 
80 static inline void
81 volk_32f_x2_subtract_32f_a_sse(float* cVector, const float* aVector,
82  const float* bVector, unsigned int num_points)
83 {
84  unsigned int number = 0;
85  const unsigned int quarterPoints = num_points / 4;
86 
87  float* cPtr = cVector;
88  const float* aPtr = aVector;
89  const float* bPtr = bVector;
90 
91  __m128 aVal, bVal, cVal;
92  for(;number < quarterPoints; number++){
93 
94  aVal = _mm_load_ps(aPtr);
95  bVal = _mm_load_ps(bPtr);
96 
97  cVal = _mm_sub_ps(aVal, bVal);
98 
99  _mm_store_ps(cPtr,cVal); // Store the results back into the C container
100 
101  aPtr += 4;
102  bPtr += 4;
103  cPtr += 4;
104  }
105 
106  number = quarterPoints * 4;
107  for(;number < num_points; number++){
108  *cPtr++ = (*aPtr++) - (*bPtr++);
109  }
110 }
111 #endif /* LV_HAVE_SSE */
112 
113 
114 #ifdef LV_HAVE_GENERIC
115 
116 static inline void
117 volk_32f_x2_subtract_32f_generic(float* cVector, const float* aVector,
118  const float* bVector, unsigned int num_points)
119 {
120  float* cPtr = cVector;
121  const float* aPtr = aVector;
122  const float* bPtr = bVector;
123  unsigned int number = 0;
124 
125  for(number = 0; number < num_points; number++){
126  *cPtr++ = (*aPtr++) - (*bPtr++);
127  }
128 }
129 #endif /* LV_HAVE_GENERIC */
130 
131 
132 #ifdef LV_HAVE_NEON
133 #include <arm_neon.h>
134 
135 static inline void
136 volk_32f_x2_subtract_32f_neon(float* cVector, const float* aVector,
137  const float* bVector, unsigned int num_points)
138 {
139  float* cPtr = cVector;
140  const float* aPtr = aVector;
141  const float* bPtr = bVector;
142  unsigned int number = 0;
143  unsigned int quarter_points = num_points / 4;
144 
145  float32x4_t a_vec, b_vec, c_vec;
146 
147  for(number = 0; number < quarter_points; number++){
148  a_vec = vld1q_f32(aPtr);
149  b_vec = vld1q_f32(bPtr);
150  c_vec = vsubq_f32(a_vec, b_vec);
151  vst1q_f32(cPtr, c_vec);
152  aPtr += 4;
153  bPtr += 4;
154  cPtr += 4;
155  }
156 
157  for(number = quarter_points * 4; number < num_points; number++){
158  *cPtr++ = (*aPtr++) - (*bPtr++);
159  }
160 }
161 #endif /* LV_HAVE_NEON */
162 
163 
164 #ifdef LV_HAVE_ORC
165 extern void
166 volk_32f_x2_subtract_32f_a_orc_impl(float* cVector, const float* aVector,
167  const float* bVector, unsigned int num_points);
168 
169 static inline void
170 volk_32f_x2_subtract_32f_u_orc(float* cVector, const float* aVector,
171  const float* bVector, unsigned int num_points)
172 {
173  volk_32f_x2_subtract_32f_a_orc_impl(cVector, aVector, bVector, num_points);
174 }
175 #endif /* LV_HAVE_ORC */
176 
177 
178 #endif /* INCLUDED_volk_32f_x2_subtract_32f_a_H */