Vector Optimized Library of Kernels  2.0
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<xmmintrin.h>
62 #include<emmintrin.h>
63 #include<tmmintrin.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) ? candidate : src0[(bound << 3) + i];
114  }
115 
116  target[0] = candidate;
117 }
118 
119 #endif /*LV_HAVE_SSSE3*/
120 
121 #ifdef LV_HAVE_NEON
122 #include <arm_neon.h>
123 
124 static inline void
125 volk_16i_max_star_16i_neon(short* target, short* src0, unsigned int num_points)
126 {
127  const unsigned int eighth_points = num_points / 8;
128  unsigned number;
129  int16x8_t input_vec;
130  int16x8_t diff, zeros;
131  uint16x8_t comp1, comp2;
132  zeros = vdupq_n_s16(0);
133 
134  int16x8x2_t tmpvec;
135 
136  int16x8_t candidate_vec = vld1q_dup_s16(src0 );
137  short candidate;
138  ++src0;
139 
140  for(number=0; number < eighth_points; ++number) {
141  input_vec = vld1q_s16(src0);
142  __VOLK_PREFETCH(src0+16);
143  diff = vsubq_s16(candidate_vec, input_vec);
144  comp1 = vcgeq_s16(diff, zeros);
145  comp2 = vcltq_s16(diff, zeros);
146 
147  tmpvec.val[0] = vandq_s16(candidate_vec, (int16x8_t)comp1);
148  tmpvec.val[1] = vandq_s16(input_vec, (int16x8_t)comp2);
149 
150  candidate_vec = vaddq_s16(tmpvec.val[0], tmpvec.val[1]);
151  src0 += 8;
152  }
153  vst1q_s16(&candidate, candidate_vec);
154 
155  for(number=0; number < num_points%8; number++) {
156  candidate = ((int16_t)(candidate - src0[number]) > 0) ? candidate : src0[number];
157  }
158  target[0] = candidate;
159 }
160 #endif /*LV_HAVE_NEON*/
161 
162 #ifdef LV_HAVE_GENERIC
163 
164 static inline void
165 volk_16i_max_star_16i_generic(short* target, short* src0, unsigned int num_points)
166 {
167  const unsigned int num_bytes = num_points*2;
168 
169  int i = 0;
170 
171  int bound = num_bytes >> 1;
172 
173  short candidate = src0[0];
174  for(i = 1; i < bound; ++i) {
175  candidate = ((short)(candidate - src0[i]) > 0) ? candidate : src0[i];
176  }
177  target[0] = candidate;
178 }
179 
180 #endif /*LV_HAVE_GENERIC*/
181 
182 
183 #endif /*INCLUDED_volk_16i_max_star_16i_a_H*/
static void volk_16i_max_star_16i_generic(short *target, short *src0, unsigned int num_points)
Definition: volk_16i_max_star_16i.h:165
#define __VOLK_PREFETCH(addr)
Definition: volk_common.h:39
for i
Definition: volk_config_fixed.tmpl.h:25
static void volk_16i_max_star_16i_neon(short *target, short *src0, unsigned int num_points)
Definition: volk_16i_max_star_16i.h:125
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