Vector Optimized Library of Kernels  2.0
Architecture-tuned implementations of math kernels
volk_16i_max_star_horizontal_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_horizontal_16i_a_H
54 #define INCLUDED_volk_16i_max_star_horizontal_16i_a_H
55 
56 #include <volk/volk_common.h>
57 
58 #include<inttypes.h>
59 #include<stdio.h>
60 
61 
62 #ifdef LV_HAVE_SSSE3
63 
64 #include<xmmintrin.h>
65 #include<emmintrin.h>
66 #include<tmmintrin.h>
67 
68 static inline void
69 volk_16i_max_star_horizontal_16i_a_ssse3(int16_t* target, int16_t* src0, unsigned int num_points)
70 {
71  const unsigned int num_bytes = num_points*2;
72 
73  static const uint8_t shufmask0[16] = {0x00, 0x01, 0x04, 0x05, 0x08, 0x09, 0x0c, 0x0d, 0xff,
74  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
75  static const uint8_t shufmask1[16] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00,
76  0x01, 0x04, 0x05, 0x08, 0x09, 0x0c, 0x0d};
77  static const uint8_t andmask0[16] = {0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,0x02, 0x00,
78  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
79  static const uint8_t andmask1[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
80  0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02};
81 
82  __m128i xmm0, xmm1, xmm2, xmm3, xmm4;
83  __m128i xmm5, xmm6, xmm7, xmm8;
84 
85  xmm4 = _mm_load_si128((__m128i*)shufmask0);
86  xmm5 = _mm_load_si128((__m128i*)shufmask1);
87  xmm6 = _mm_load_si128((__m128i*)andmask0);
88  xmm7 = _mm_load_si128((__m128i*)andmask1);
89 
90  __m128i *p_target, *p_src0;
91 
92  p_target = (__m128i*)target;
93  p_src0 = (__m128i*)src0;
94 
95  int bound = num_bytes >> 5;
96  int intermediate = (num_bytes >> 4) & 1;
97  int leftovers = (num_bytes >> 1) & 7;
98 
99  int i = 0;
100 
101  for(i = 0; i < bound; ++i) {
102  xmm0 = _mm_load_si128(p_src0);
103  xmm1 = _mm_load_si128(&p_src0[1]);
104 
105  xmm2 = _mm_xor_si128(xmm2, xmm2);
106  p_src0 += 2;
107 
108  xmm3 = _mm_hsub_epi16(xmm0, xmm1);
109 
110  xmm2 = _mm_cmpgt_epi16(xmm2, xmm3);
111 
112  xmm8 = _mm_and_si128(xmm2, xmm6);
113  xmm3 = _mm_and_si128(xmm2, xmm7);
114 
115 
116  xmm8 = _mm_add_epi8(xmm8, xmm4);
117  xmm3 = _mm_add_epi8(xmm3, xmm5);
118 
119  xmm0 = _mm_shuffle_epi8(xmm0, xmm8);
120  xmm1 = _mm_shuffle_epi8(xmm1, xmm3);
121 
122 
123  xmm3 = _mm_add_epi16(xmm0, xmm1);
124 
125 
126  _mm_store_si128(p_target, xmm3);
127 
128  p_target += 1;
129  }
130 
131  for(i = 0; i < intermediate; ++i) {
132  xmm0 = _mm_load_si128(p_src0);
133 
134  xmm2 = _mm_xor_si128(xmm2, xmm2);
135  p_src0 += 1;
136 
137  xmm3 = _mm_hsub_epi16(xmm0, xmm1);
138  xmm2 = _mm_cmpgt_epi16(xmm2, xmm3);
139 
140  xmm8 = _mm_and_si128(xmm2, xmm6);
141 
142  xmm3 = _mm_add_epi8(xmm8, xmm4);
143 
144  xmm0 = _mm_shuffle_epi8(xmm0, xmm3);
145 
146  _mm_storel_pd((double*)p_target, bit128_p(&xmm0)->double_vec);
147 
148  p_target = (__m128i*)((int8_t*)p_target + 8);
149  }
150 
151  for(i = (bound << 4) + (intermediate << 3); i < (bound << 4) + (intermediate << 3) + leftovers ; i += 2) {
152  target[i>>1] = ((int16_t)(src0[i] - src0[i + 1]) > 0) ? src0[i] : src0[i + 1];
153  }
154 }
155 
156 #endif /*LV_HAVE_SSSE3*/
157 
158 #ifdef LV_HAVE_NEON
159 
160 #include <arm_neon.h>
161 static inline void
162 volk_16i_max_star_horizontal_16i_neon(int16_t* target, int16_t* src0, unsigned int num_points)
163 {
164  const unsigned int eighth_points = num_points / 16;
165  unsigned number;
166  int16x8x2_t input_vec;
167  int16x8_t diff, max_vec, zeros;
168  uint16x8_t comp1, comp2;
169  zeros = vdupq_n_s16(0);
170  for(number=0; number < eighth_points; ++number) {
171  input_vec = vld2q_s16(src0);
172  //__VOLK_PREFETCH(src0+16);
173  diff = vsubq_s16(input_vec.val[0], input_vec.val[1]);
174  comp1 = vcgeq_s16(diff, zeros);
175  comp2 = vcltq_s16(diff, zeros);
176 
177  input_vec.val[0] = vandq_s16(input_vec.val[0], (int16x8_t)comp1);
178  input_vec.val[1] = vandq_s16(input_vec.val[1], (int16x8_t)comp2);
179 
180  max_vec = vaddq_s16(input_vec.val[0], input_vec.val[1]);
181  vst1q_s16(target, max_vec);
182  src0 += 16;
183  target += 8;
184  }
185  for(number=0; number < num_points%16; number+=2) {
186  target[number >> 1] = ((int16_t)(src0[number] - src0[number + 1]) > 0) ? src0[number] : src0[number+1];
187  }
188 
189 }
190 #endif /* LV_HAVE_NEON */
191 
192 #ifdef LV_HAVE_NEONV7
193 extern void volk_16i_max_star_horizontal_16i_a_neonasm(int16_t* target, int16_t* src0, unsigned int num_points);
194 #endif /* LV_HAVE_NEONV7 */
195 
196 #ifdef LV_HAVE_GENERIC
197 static inline void
198 volk_16i_max_star_horizontal_16i_generic(int16_t* target, int16_t* src0, unsigned int num_points)
199 {
200  const unsigned int num_bytes = num_points*2;
201 
202  int i = 0;
203 
204  int bound = num_bytes >> 1;
205 
206  for(i = 0; i < bound; i += 2) {
207  target[i >> 1] = ((int16_t) (src0[i] - src0[i + 1]) > 0) ? src0[i] : src0[i+1];
208  }
209 }
210 
211 #endif /*LV_HAVE_GENERIC*/
212 
213 #endif /*INCLUDED_volk_16i_max_star_horizontal_16i_a_H*/
#define bit128_p(x)
Definition: volk_common.h:118
static void volk_16i_max_star_horizontal_16i_generic(int16_t *target, int16_t *src0, unsigned int num_points)
Definition: volk_16i_max_star_horizontal_16i.h:198
for i
Definition: volk_config_fixed.tmpl.h:25
static void volk_16i_max_star_horizontal_16i_neon(int16_t *target, int16_t *src0, unsigned int num_points)
Definition: volk_16i_max_star_horizontal_16i.h:162
static void volk_16i_max_star_horizontal_16i_a_ssse3(int16_t *target, int16_t *src0, unsigned int num_points)
Definition: volk_16i_max_star_horizontal_16i.h:69