Vector Optimized Library of Kernels  2.0
Architecture-tuned implementations of math kernels
volk_16i_x4_quad_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 
55 #ifndef INCLUDED_volk_16i_x4_quad_max_star_16i_a_H
56 #define INCLUDED_volk_16i_x4_quad_max_star_16i_a_H
57 
58 #include<inttypes.h>
59 #include<stdio.h>
60 
61 #ifdef LV_HAVE_SSE2
62 
63 #include<emmintrin.h>
64 
65 static inline void
66 volk_16i_x4_quad_max_star_16i_a_sse2(short* target, short* src0, short* src1,
67  short* src2, short* src3, unsigned int num_points)
68 {
69  const unsigned int num_bytes = num_points*2;
70 
71  int i = 0;
72 
73  int bound = (num_bytes >> 4);
74  int bound_copy = bound;
75  int leftovers = (num_bytes >> 1) & 7;
76 
77  __m128i *p_target, *p_src0, *p_src1, *p_src2, *p_src3;
78  p_target = (__m128i*) target;
79  p_src0 = (__m128i*)src0;
80  p_src1 = (__m128i*)src1;
81  p_src2 = (__m128i*)src2;
82  p_src3 = (__m128i*)src3;
83 
84  __m128i xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8;
85 
86  while(bound_copy > 0) {
87  xmm1 = _mm_load_si128(p_src0);
88  xmm2 = _mm_load_si128(p_src1);
89  xmm3 = _mm_load_si128(p_src2);
90  xmm4 = _mm_load_si128(p_src3);
91 
92  xmm5 = _mm_setzero_si128();
93  xmm6 = _mm_setzero_si128();
94  xmm7 = xmm1;
95  xmm8 = xmm3;
96 
97  xmm1 = _mm_sub_epi16(xmm2, xmm1);
98 
99  xmm3 = _mm_sub_epi16(xmm4, xmm3);
100 
101  xmm5 = _mm_cmpgt_epi16(xmm1, xmm5);
102  xmm6 = _mm_cmpgt_epi16(xmm3, xmm6);
103 
104  xmm2 = _mm_and_si128(xmm5, xmm2);
105  xmm4 = _mm_and_si128(xmm6, xmm4);
106  xmm5 = _mm_andnot_si128(xmm5, xmm7);
107  xmm6 = _mm_andnot_si128(xmm6, xmm8);
108 
109  xmm5 = _mm_add_epi16(xmm2, xmm5);
110  xmm6 = _mm_add_epi16(xmm4, xmm6);
111 
112  xmm1 = _mm_xor_si128(xmm1, xmm1);
113  xmm2 = xmm5;
114  xmm5 = _mm_sub_epi16(xmm6, xmm5);
115  p_src0 += 1;
116  bound_copy -= 1;
117 
118  xmm1 = _mm_cmpgt_epi16(xmm5, xmm1);
119  p_src1 += 1;
120 
121  xmm6 = _mm_and_si128(xmm1, xmm6);
122 
123  xmm1 = _mm_andnot_si128(xmm1, xmm2);
124  p_src2 += 1;
125 
126  xmm1 = _mm_add_epi16(xmm6, xmm1);
127  p_src3 += 1;
128 
129  _mm_store_si128(p_target, xmm1);
130  p_target += 1;
131 
132  }
133 
134 
135  /*__VOLK_ASM __VOLK_VOLATILE
136  (
137  "volk_16i_x4_quad_max_star_16i_a_sse2_L1:\n\t"
138  "cmp $0, %[bound]\n\t"
139  "je volk_16i_x4_quad_max_star_16i_a_sse2_END\n\t"
140 
141  "movaps (%[src0]), %%xmm1\n\t"
142  "movaps (%[src1]), %%xmm2\n\t"
143  "movaps (%[src2]), %%xmm3\n\t"
144  "movaps (%[src3]), %%xmm4\n\t"
145 
146  "pxor %%xmm5, %%xmm5\n\t"
147  "pxor %%xmm6, %%xmm6\n\t"
148  "movaps %%xmm1, %%xmm7\n\t"
149  "movaps %%xmm3, %%xmm8\n\t"
150  "psubw %%xmm2, %%xmm1\n\t"
151  "psubw %%xmm4, %%xmm3\n\t"
152 
153  "pcmpgtw %%xmm1, %%xmm5\n\t"
154  "pcmpgtw %%xmm3, %%xmm6\n\t"
155 
156  "pand %%xmm5, %%xmm2\n\t"
157  "pand %%xmm6, %%xmm4\n\t"
158  "pandn %%xmm7, %%xmm5\n\t"
159  "pandn %%xmm8, %%xmm6\n\t"
160 
161  "paddw %%xmm2, %%xmm5\n\t"
162  "paddw %%xmm4, %%xmm6\n\t"
163 
164  "pxor %%xmm1, %%xmm1\n\t"
165  "movaps %%xmm5, %%xmm2\n\t"
166 
167  "psubw %%xmm6, %%xmm5\n\t"
168  "add $16, %[src0]\n\t"
169  "add $-1, %[bound]\n\t"
170 
171  "pcmpgtw %%xmm5, %%xmm1\n\t"
172  "add $16, %[src1]\n\t"
173 
174  "pand %%xmm1, %%xmm6\n\t"
175 
176  "pandn %%xmm2, %%xmm1\n\t"
177  "add $16, %[src2]\n\t"
178 
179  "paddw %%xmm6, %%xmm1\n\t"
180  "add $16, %[src3]\n\t"
181 
182  "movaps %%xmm1, (%[target])\n\t"
183  "addw $16, %[target]\n\t"
184  "jmp volk_16i_x4_quad_max_star_16i_a_sse2_L1\n\t"
185 
186  "volk_16i_x4_quad_max_star_16i_a_sse2_END:\n\t"
187  :
188  :[bound]"r"(bound), [src0]"r"(src0), [src1]"r"(src1), [src2]"r"(src2), [src3]"r"(src3), [target]"r"(target)
189  :
190  );
191  */
192 
193  short temp0 = 0;
194  short temp1 = 0;
195  for(i = bound * 8; i < (bound * 8) + leftovers; ++i) {
196  temp0 = ((short)(src0[i] - src1[i]) > 0) ? src0[i] : src1[i];
197  temp1 = ((short)(src2[i] - src3[i])>0) ? src2[i] : src3[i];
198  target[i] = ((short)(temp0 - temp1)>0) ? temp0 : temp1;
199  }
200  return;
201 }
202 
203 #endif /*LV_HAVE_SSE2*/
204 
205 #ifdef LV_HAVE_NEON
206 
207 #include <arm_neon.h>
208 
209 static inline void
210 volk_16i_x4_quad_max_star_16i_neon(short* target, short* src0, short* src1,
211  short* src2, short* src3, unsigned int num_points)
212 {
213  const unsigned int eighth_points = num_points / 8;
214  unsigned i;
215 
216  int16x8_t src0_vec, src1_vec, src2_vec, src3_vec;
217  int16x8_t diff12, diff34;
218  int16x8_t comp0, comp1, comp2, comp3;
219  int16x8_t result1_vec, result2_vec;
220  int16x8_t zeros;
221  zeros = vdupq_n_s16(0);
222  for(i=0; i < eighth_points; ++i) {
223  src0_vec = vld1q_s16(src0);
224  src1_vec = vld1q_s16(src1);
225  src2_vec = vld1q_s16(src2);
226  src3_vec = vld1q_s16(src3);
227  diff12 = vsubq_s16(src0_vec, src1_vec);
228  diff34 = vsubq_s16(src2_vec, src3_vec);
229  comp0 = (int16x8_t)vcgeq_s16(diff12, zeros);
230  comp1 = (int16x8_t)vcltq_s16(diff12, zeros);
231  comp2 = (int16x8_t)vcgeq_s16(diff34, zeros);
232  comp3 = (int16x8_t)vcltq_s16(diff34, zeros);
233  comp0 = vandq_s16(src0_vec, comp0);
234  comp1 = vandq_s16(src1_vec, comp1);
235  comp2 = vandq_s16(src2_vec, comp2);
236  comp3 = vandq_s16(src3_vec, comp3);
237 
238  result1_vec = vaddq_s16(comp0, comp1);
239  result2_vec = vaddq_s16(comp2, comp3);
240 
241  diff12 = vsubq_s16(result1_vec, result2_vec);
242  comp0 = (int16x8_t)vcgeq_s16(diff12, zeros);
243  comp1 = (int16x8_t)vcltq_s16(diff12, zeros);
244  comp0 = vandq_s16(result1_vec, comp0);
245  comp1 = vandq_s16(result2_vec, comp1);
246  result1_vec = vaddq_s16(comp0, comp1);
247  vst1q_s16(target, result1_vec);
248  src0 += 8;
249  src1 += 8;
250  src2 += 8;
251  src3 += 8;
252  target += 8;
253  }
254 
255  short temp0 = 0;
256  short temp1 = 0;
257  for(i=eighth_points*8; i < num_points; ++i) {
258  temp0 = ((short)(*src0 - *src1) > 0) ? *src0 : *src1;
259  temp1 = ((short)(*src2 - *src3) > 0) ? *src2 : *src3;
260  *target++ = ((short)(temp0 - temp1)>0) ? temp0 : temp1;
261  src0++;
262  src1++;
263  src2++;
264  src3++;
265  }
266 }
267 #endif /* LV_HAVE_NEON */
268 
269 
270 #ifdef LV_HAVE_GENERIC
271 static inline void
272 volk_16i_x4_quad_max_star_16i_generic(short* target, short* src0, short* src1,
273  short* src2, short* src3, unsigned int num_points)
274 {
275  const unsigned int num_bytes = num_points*2;
276 
277  int i = 0;
278 
279  int bound = num_bytes >> 1;
280 
281  short temp0 = 0;
282  short temp1 = 0;
283  for(i = 0; i < bound; ++i) {
284  temp0 = ((short)(src0[i] - src1[i]) > 0) ? src0[i] : src1[i];
285  temp1 = ((short)(src2[i] - src3[i])>0) ? src2[i] : src3[i];
286  target[i] = ((short)(temp0 - temp1)>0) ? temp0 : temp1;
287  }
288 }
289 
290 #endif /*LV_HAVE_GENERIC*/
291 
292 #endif /*INCLUDED_volk_16i_x4_quad_max_star_16i_a_H*/
for i
Definition: volk_config_fixed.tmpl.h:25
static void volk_16i_x4_quad_max_star_16i_generic(short *target, short *src0, short *src1, short *src2, short *src3, unsigned int num_points)
Definition: volk_16i_x4_quad_max_star_16i.h:272
static void volk_16i_x4_quad_max_star_16i_a_sse2(short *target, short *src0, short *src1, short *src2, short *src3, unsigned int num_points)
Definition: volk_16i_x4_quad_max_star_16i.h:66
static void volk_16i_x4_quad_max_star_16i_neon(short *target, short *src0, short *src1, short *src2, short *src3, unsigned int num_points)
Definition: volk_16i_x4_quad_max_star_16i.h:210