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_max_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_max_32f
25  *
26  * \b Overview
27  *
28  * Selects maximum value from each entry between bVector and aVector
29  * and store their results in the cVector.
30  *
31  * c[i] = max(a[i], b[i])
32  *
33  * <b>Dispatcher Prototype</b>
34  * \code
35  * void volk_32f_x2_max_32f(float* cVector, const float* aVector, const float* bVector, unsigned int num_points)
36  * \endcode
37  *
38  * \b Inputs
39  * \li aVector: First input vector.
40  * \li bVector: Second input vector.
41  * \li num_points: The number of values in both input vectors.
42  *
43  * \b Outputs
44  * \li cVector: The output vector.
45  *
46  * \b Example
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_max_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_max_32f_a_H
72 #define INCLUDED_volk_32f_x2_max_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_max_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  aVal = _mm_load_ps(aPtr);
94  bVal = _mm_load_ps(bPtr);
95 
96  cVal = _mm_max_ps(aVal, bVal);
97 
98  _mm_store_ps(cPtr,cVal); // Store the results back into the C container
99 
100  aPtr += 4;
101  bPtr += 4;
102  cPtr += 4;
103  }
104 
105  number = quarterPoints * 4;
106  for(;number < num_points; number++){
107  const float a = *aPtr++;
108  const float b = *bPtr++;
109  *cPtr++ = ( a > b ? a : b);
110  }
111 }
112 #endif /* LV_HAVE_SSE */
113 
114 
115 #ifdef LV_HAVE_NEON
116 #include <arm_neon.h>
117 
118 static inline void
119 volk_32f_x2_max_32f_neon(float* cVector, const float* aVector,
120  const float* bVector, unsigned int num_points)
121 {
122  unsigned int quarter_points = num_points / 4;
123  float* cPtr = cVector;
124  const float* aPtr = aVector;
125  const float* bPtr= bVector;
126  unsigned int number = 0;
127 
128  float32x4_t a_vec, b_vec, c_vec;
129  for(number = 0; number < quarter_points; number++){
130  a_vec = vld1q_f32(aPtr);
131  b_vec = vld1q_f32(bPtr);
132  c_vec = vmaxq_f32(a_vec, b_vec);
133  vst1q_f32(cPtr, c_vec);
134  aPtr += 4;
135  bPtr += 4;
136  cPtr += 4;
137  }
138 
139  for(number = quarter_points*4; number < num_points; number++){
140  const float a = *aPtr++;
141  const float b = *bPtr++;
142  *cPtr++ = ( a > b ? a : b);
143  }
144 }
145 #endif /* LV_HAVE_NEON */
146 
147 
148 #ifdef LV_HAVE_GENERIC
149 
150 static inline void
151 volk_32f_x2_max_32f_generic(float* cVector, const float* aVector,
152  const float* bVector, unsigned int num_points)
153 {
154  float* cPtr = cVector;
155  const float* aPtr = aVector;
156  const float* bPtr= bVector;
157  unsigned int number = 0;
158 
159  for(number = 0; number < num_points; number++){
160  const float a = *aPtr++;
161  const float b = *bPtr++;
162  *cPtr++ = ( a > b ? a : b);
163  }
164 }
165 #endif /* LV_HAVE_GENERIC */
166 
167 
168 #ifdef LV_HAVE_ORC
169 extern void
170 volk_32f_x2_max_32f_a_orc_impl(float* cVector, const float* aVector,
171  const float* bVector, unsigned int num_points);
172 
173 static inline void
174 volk_32f_x2_max_32f_u_orc(float* cVector, const float* aVector,
175  const float* bVector, unsigned int num_points)
176 {
177  volk_32f_x2_max_32f_a_orc_impl(cVector, aVector, bVector, num_points);
178 }
179 #endif /* LV_HAVE_ORC */
180 
181 
182 #endif /* INCLUDED_volk_32f_x2_max_32f_a_H */