/
volk_16i_max_star_horizontal_16i.h
213 lines (163 loc) · 5.78 KB
/
volk_16i_max_star_horizontal_16i.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/* -*- c++ -*- */
/*
* Copyright 2012, 2014 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
* GNU Radio is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* GNU Radio is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Radio; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
/*!
* \page volk_16i_max_star_horizontal_16i
*
* \b Overview
*
* <FIXME>
*
* <b>Dispatcher Prototype</b>
* \code
* void volk_16i_max_star_horizontal_16i(short* target, short* src0, unsigned int num_points);
* \endcode
*
* \b Inputs
* \li src0: The input vector.
* \li num_points: The number of complex data points.
*
* \b Outputs
* \li target: The output value of the max* operation.
*
* \b Example
* \code
* int N = 10000;
*
* volk_16i_max_star_horizontal_16i();
*
* volk_free(x);
* volk_free(t);
* \endcode
*/
#ifndef INCLUDED_volk_16i_max_star_horizontal_16i_a_H
#define INCLUDED_volk_16i_max_star_horizontal_16i_a_H
#include <volk/volk_common.h>
#include<inttypes.h>
#include<stdio.h>
#ifdef LV_HAVE_SSSE3
#include<xmmintrin.h>
#include<emmintrin.h>
#include<tmmintrin.h>
static inline void
volk_16i_max_star_horizontal_16i_a_ssse3(int16_t* target, int16_t* src0, unsigned int num_points)
{
const unsigned int num_bytes = num_points*2;
static const uint8_t shufmask0[16] = {0x00, 0x01, 0x04, 0x05, 0x08, 0x09, 0x0c, 0x0d, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
static const uint8_t shufmask1[16] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00,
0x01, 0x04, 0x05, 0x08, 0x09, 0x0c, 0x0d};
static const uint8_t andmask0[16] = {0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,0x02, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
static const uint8_t andmask1[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02};
__m128i xmm0, xmm1, xmm2, xmm3, xmm4;
__m128i xmm5, xmm6, xmm7, xmm8;
xmm4 = _mm_load_si128((__m128i*)shufmask0);
xmm5 = _mm_load_si128((__m128i*)shufmask1);
xmm6 = _mm_load_si128((__m128i*)andmask0);
xmm7 = _mm_load_si128((__m128i*)andmask1);
__m128i *p_target, *p_src0;
p_target = (__m128i*)target;
p_src0 = (__m128i*)src0;
int bound = num_bytes >> 5;
int intermediate = (num_bytes >> 4) & 1;
int leftovers = (num_bytes >> 1) & 7;
int i = 0;
for(i = 0; i < bound; ++i) {
xmm0 = _mm_load_si128(p_src0);
xmm1 = _mm_load_si128(&p_src0[1]);
xmm2 = _mm_xor_si128(xmm2, xmm2);
p_src0 += 2;
xmm3 = _mm_hsub_epi16(xmm0, xmm1);
xmm2 = _mm_cmpgt_epi16(xmm2, xmm3);
xmm8 = _mm_and_si128(xmm2, xmm6);
xmm3 = _mm_and_si128(xmm2, xmm7);
xmm8 = _mm_add_epi8(xmm8, xmm4);
xmm3 = _mm_add_epi8(xmm3, xmm5);
xmm0 = _mm_shuffle_epi8(xmm0, xmm8);
xmm1 = _mm_shuffle_epi8(xmm1, xmm3);
xmm3 = _mm_add_epi16(xmm0, xmm1);
_mm_store_si128(p_target, xmm3);
p_target += 1;
}
for(i = 0; i < intermediate; ++i) {
xmm0 = _mm_load_si128(p_src0);
xmm2 = _mm_xor_si128(xmm2, xmm2);
p_src0 += 1;
xmm3 = _mm_hsub_epi16(xmm0, xmm1);
xmm2 = _mm_cmpgt_epi16(xmm2, xmm3);
xmm8 = _mm_and_si128(xmm2, xmm6);
xmm3 = _mm_add_epi8(xmm8, xmm4);
xmm0 = _mm_shuffle_epi8(xmm0, xmm3);
_mm_storel_pd((double*)p_target, bit128_p(&xmm0)->double_vec);
p_target = (__m128i*)((int8_t*)p_target + 8);
}
for(i = (bound << 4) + (intermediate << 3); i < (bound << 4) + (intermediate << 3) + leftovers ; i += 2) {
target[i>>1] = ((int16_t)(src0[i] - src0[i + 1]) > 0) ? src0[i] : src0[i + 1];
}
}
#endif /*LV_HAVE_SSSE3*/
#ifdef LV_HAVE_NEON
#include <arm_neon.h>
static inline void
volk_16i_max_star_horizontal_16i_neon(int16_t* target, int16_t* src0, unsigned int num_points)
{
const unsigned int eighth_points = num_points / 16;
unsigned number;
int16x8x2_t input_vec;
int16x8_t diff, max_vec, zeros;
uint16x8_t comp1, comp2;
zeros = veorq_s16(zeros, zeros);
for(number=0; number < eighth_points; ++number) {
input_vec = vld2q_s16(src0);
//__VOLK_PREFETCH(src0+16);
diff = vsubq_s16(input_vec.val[0], input_vec.val[1]);
comp1 = vcgeq_s16(diff, zeros);
comp2 = vcltq_s16(diff, zeros);
input_vec.val[0] = vandq_s16(input_vec.val[0], (int16x8_t)comp1);
input_vec.val[1] = vandq_s16(input_vec.val[1], (int16x8_t)comp2);
max_vec = vaddq_s16(input_vec.val[0], input_vec.val[1]);
vst1q_s16(target, max_vec);
src0 += 16;
target += 8;
}
for(number=0; number < num_points%16; number+=2) {
target[number >> 1] = ((int16_t)(src0[number] - src0[number + 1]) > 0) ? src0[number] : src0[number+1];
}
}
#endif /* LV_HAVE_NEON */
#ifdef LV_HAVE_NEONV7
extern void volk_16i_max_star_horizontal_16i_a_neonasm(int16_t* target, int16_t* src0, unsigned int num_points);
#endif /* LV_HAVE_NEONV7 */
#ifdef LV_HAVE_GENERIC
static inline void
volk_16i_max_star_horizontal_16i_generic(int16_t* target, int16_t* src0, unsigned int num_points)
{
const unsigned int num_bytes = num_points*2;
int i = 0;
int bound = num_bytes >> 1;
for(i = 0; i < bound; i += 2) {
target[i >> 1] = ((int16_t) (src0[i] - src0[i + 1]) > 0) ? src0[i] : src0[i+1];
}
}
#endif /*LV_HAVE_GENERIC*/
#endif /*INCLUDED_volk_16i_max_star_horizontal_16i_a_H*/