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_x2_max_64f.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_x2_max_64f
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_64f_x2_max_64f(double* cVector, const double* aVector, const double* 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  * double* increasing = (double*)volk_malloc(sizeof(double)*N, alignment);
51  * double* decreasing = (double*)volk_malloc(sizeof(double)*N, alignment);
52  * double* out = (double*)volk_malloc(sizeof(double)*N, alignment);
53  *
54  * for(unsigned int ii = 0; ii < N; ++ii){
55  * increasing[ii] = (double)ii;
56  * decreasing[ii] = 10.f - (double)ii;
57  * }
58  *
59  * volk_64f_x2_max_64f(out, increasing, decreasing, N);
60  *
61  * for(unsigned int ii = 0; ii < N; ++ii){
62  * printf("out[%u] = %1.2g\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_64f_x2_max_64f_a_H
72 #define INCLUDED_volk_64f_x2_max_64f_a_H
73 
74 #include <inttypes.h>
75 #include <stdio.h>
76 
77 #ifdef LV_HAVE_SSE2
78 #include <emmintrin.h>
79 
80 static inline void
81 volk_64f_x2_max_64f_a_sse2(double* cVector, const double* aVector,
82  const double* bVector, unsigned int num_points)
83 {
84  unsigned int number = 0;
85  const unsigned int halfPoints = num_points / 2;
86 
87  double* cPtr = cVector;
88  const double* aPtr = aVector;
89  const double* bPtr= bVector;
90 
91  __m128d aVal, bVal, cVal;
92  for(;number < halfPoints; number++){
93 
94  aVal = _mm_load_pd(aPtr);
95  bVal = _mm_load_pd(bPtr);
96 
97  cVal = _mm_max_pd(aVal, bVal);
98 
99  _mm_store_pd(cPtr,cVal); // Store the results back into the C container
100 
101  aPtr += 2;
102  bPtr += 2;
103  cPtr += 2;
104  }
105 
106  number = halfPoints * 2;
107  for(;number < num_points; number++){
108  const double a = *aPtr++;
109  const double b = *bPtr++;
110  *cPtr++ = ( a > b ? a : b);
111  }
112 }
113 #endif /* LV_HAVE_SSE2 */
114 
115 
116 #ifdef LV_HAVE_GENERIC
117 
118 static inline void
119 volk_64f_x2_max_64f_generic(double* cVector, const double* aVector,
120  const double* bVector, unsigned int num_points)
121 {
122  double* cPtr = cVector;
123  const double* aPtr = aVector;
124  const double* bPtr= bVector;
125  unsigned int number = 0;
126 
127  for(number = 0; number < num_points; number++){
128  const double a = *aPtr++;
129  const double b = *bPtr++;
130  *cPtr++ = ( a > b ? a : b);
131  }
132 }
133 #endif /* LV_HAVE_GENERIC */
134 
135 
136 #endif /* INCLUDED_volk_64f_x2_max_64f_a_H */