Vector Optimized Library of Kernels  2.4
Architecture-tuned implementations of math kernels
volk_16i_max_star_16i.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 
53 #ifndef INCLUDED_volk_16i_max_star_16i_a_H
54 #define INCLUDED_volk_16i_max_star_16i_a_H
55 
56 #include <inttypes.h>
57 #include <stdio.h>
58 
59 #ifdef LV_HAVE_SSSE3
60 
61 #include <emmintrin.h>
62 #include <tmmintrin.h>
63 #include <xmmintrin.h>
64 
65 static inline void
66 volk_16i_max_star_16i_a_ssse3(short* target, short* src0, unsigned int num_points)
67 {
68  const unsigned int num_bytes = num_points * 2;
69 
70  short candidate = src0[0];
71  short cands[8];
72  __m128i xmm0, xmm1, xmm3, xmm4, xmm5, xmm6;
73 
74  __m128i* p_src0;
75 
76  p_src0 = (__m128i*)src0;
77 
78  int bound = num_bytes >> 4;
79  int leftovers = (num_bytes >> 1) & 7;
80 
81  int i = 0;
82 
83  xmm1 = _mm_setzero_si128();
84  xmm0 = _mm_setzero_si128();
85  //_mm_insert_epi16(xmm0, candidate, 0);
86 
87  xmm0 = _mm_shuffle_epi8(xmm0, xmm1);
88 
89  for (i = 0; i < bound; ++i) {
90  xmm1 = _mm_load_si128(p_src0);
91  p_src0 += 1;
92  // xmm2 = _mm_sub_epi16(xmm1, xmm0);
93 
94  xmm3 = _mm_cmpgt_epi16(xmm0, xmm1);
95  xmm4 = _mm_cmpeq_epi16(xmm0, xmm1);
96  xmm5 = _mm_cmpgt_epi16(xmm1, xmm0);
97 
98  xmm6 = _mm_xor_si128(xmm4, xmm5);
99 
100  xmm3 = _mm_and_si128(xmm3, xmm0);
101  xmm4 = _mm_and_si128(xmm6, xmm1);
102 
103  xmm0 = _mm_add_epi16(xmm3, xmm4);
104  }
105 
106  _mm_store_si128((__m128i*)cands, xmm0);
107 
108  for (i = 0; i < 8; ++i) {
109  candidate = ((short)(candidate - cands[i]) > 0) ? candidate : cands[i];
110  }
111 
112  for (i = 0; i < leftovers; ++i) {
113  candidate = ((short)(candidate - src0[(bound << 3) + i]) > 0)
114  ? candidate
115  : src0[(bound << 3) + i];
116  }
117 
118  target[0] = candidate;
119 }
120 
121 #endif /*LV_HAVE_SSSE3*/
122 
123 #ifdef LV_HAVE_NEON
124 #include <arm_neon.h>
125 
126 static inline void
127 volk_16i_max_star_16i_neon(short* target, short* src0, unsigned int num_points)
128 {
129  const unsigned int eighth_points = num_points / 8;
130  unsigned number;
131  int16x8_t input_vec;
132  int16x8_t diff, zeros;
133  uint16x8_t comp1, comp2;
134  zeros = vdupq_n_s16(0);
135 
136  int16x8x2_t tmpvec;
137 
138  int16x8_t candidate_vec = vld1q_dup_s16(src0);
139  short candidate;
140  ++src0;
141 
142  for (number = 0; number < eighth_points; ++number) {
143  input_vec = vld1q_s16(src0);
144  __VOLK_PREFETCH(src0 + 16);
145  diff = vsubq_s16(candidate_vec, input_vec);
146  comp1 = vcgeq_s16(diff, zeros);
147  comp2 = vcltq_s16(diff, zeros);
148 
149  tmpvec.val[0] = vandq_s16(candidate_vec, (int16x8_t)comp1);
150  tmpvec.val[1] = vandq_s16(input_vec, (int16x8_t)comp2);
151 
152  candidate_vec = vaddq_s16(tmpvec.val[0], tmpvec.val[1]);
153  src0 += 8;
154  }
155  vst1q_s16(&candidate, candidate_vec);
156 
157  for (number = 0; number < num_points % 8; number++) {
158  candidate = ((int16_t)(candidate - src0[number]) > 0) ? candidate : src0[number];
159  }
160  target[0] = candidate;
161 }
162 #endif /*LV_HAVE_NEON*/
163 
164 #ifdef LV_HAVE_GENERIC
165 
166 static inline void
167 volk_16i_max_star_16i_generic(short* target, short* src0, unsigned int num_points)
168 {
169  const unsigned int num_bytes = num_points * 2;
170 
171  int i = 0;
172 
173  int bound = num_bytes >> 1;
174 
175  short candidate = src0[0];
176  for (i = 1; i < bound; ++i) {
177  candidate = ((short)(candidate - src0[i]) > 0) ? candidate : src0[i];
178  }
179  target[0] = candidate;
180 }
181 
182 #endif /*LV_HAVE_GENERIC*/
183 
184 
185 #endif /*INCLUDED_volk_16i_max_star_16i_a_H*/
static void volk_16i_max_star_16i_neon(short *target, short *src0, unsigned int num_points)
Definition: volk_16i_max_star_16i.h:127
static void volk_16i_max_star_16i_a_ssse3(short *target, short *src0, unsigned int num_points)
Definition: volk_16i_max_star_16i.h:66
static void volk_16i_max_star_16i_generic(short *target, short *src0, unsigned int num_points)
Definition: volk_16i_max_star_16i.h:167
#define __VOLK_PREFETCH(addr)
Definition: volk_common.h:62
for i
Definition: volk_config_fixed.tmpl.h:25