GNU Radio C++ API
volk_16i_max_star_horizontal_16i_a.h
Go to the documentation of this file.
1 #ifndef INCLUDED_volk_16i_max_star_horizontal_16i_a_H
2 #define INCLUDED_volk_16i_max_star_horizontal_16i_a_H
3 
4 
5 #include<inttypes.h>
6 #include<stdio.h>
7 
8 
9 #ifdef LV_HAVE_SSSE3
10 
11 #include<xmmintrin.h>
12 #include<emmintrin.h>
13 #include<tmmintrin.h>
14 
15 static inline void volk_16i_max_star_horizontal_16i_a_ssse3(int16_t* target, int16_t* src0, unsigned int num_bytes) {
16 
17  const static uint8_t shufmask0[16] = {0x00, 0x01, 0x04, 0x05, 0x08, 0x09, 0x0c, 0x0d, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
18  const static uint8_t shufmask1[16] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x01, 0x04, 0x05, 0x08, 0x09, 0x0c, 0x0d};
19  const static uint8_t andmask0[16] = {0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
20  const static uint8_t andmask1[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02};
21 
22 
23 
24  volatile __m128i xmm0, xmm1, xmm2, xmm3, xmm4;
25  __m128i xmm5, xmm6, xmm7, xmm8;
26 
27  xmm4 = _mm_load_si128((__m128i*)shufmask0);
28  xmm5 = _mm_load_si128((__m128i*)shufmask1);
29  xmm6 = _mm_load_si128((__m128i*)andmask0);
30  xmm7 = _mm_load_si128((__m128i*)andmask1);
31 
32  __m128i *p_target, *p_src0;
33 
34  p_target = (__m128i*)target;
35  p_src0 = (__m128i*)src0;
36 
37  int bound = num_bytes >> 5;
38  int intermediate = (num_bytes >> 4) & 1;
39  int leftovers = (num_bytes >> 1) & 7;
40 
41  int i = 0;
42 
43 
44  for(i = 0; i < bound; ++i) {
45 
46  xmm0 = _mm_load_si128(p_src0);
47  xmm1 = _mm_load_si128(&p_src0[1]);
48 
49 
50 
51  xmm2 = _mm_xor_si128(xmm2, xmm2);
52  p_src0 += 2;
53 
54  xmm3 = _mm_hsub_epi16(xmm0, xmm1);
55 
56  xmm2 = _mm_cmpgt_epi16(xmm2, xmm3);
57 
58  xmm8 = _mm_and_si128(xmm2, xmm6);
59  xmm3 = _mm_and_si128(xmm2, xmm7);
60 
61 
62  xmm8 = _mm_add_epi8(xmm8, xmm4);
63  xmm3 = _mm_add_epi8(xmm3, xmm5);
64 
65  xmm0 = _mm_shuffle_epi8(xmm0, xmm8);
66  xmm1 = _mm_shuffle_epi8(xmm1, xmm3);
67 
68 
69  xmm3 = _mm_add_epi16(xmm0, xmm1);
70 
71 
72  _mm_store_si128(p_target, xmm3);
73 
74  p_target += 1;
75 
76  }
77 
78  for(i = 0; i < intermediate; ++i) {
79 
80  xmm0 = _mm_load_si128(p_src0);
81 
82 
83  xmm2 = _mm_xor_si128(xmm2, xmm2);
84  p_src0 += 1;
85 
86  xmm3 = _mm_hsub_epi16(xmm0, xmm1);
87  xmm2 = _mm_cmpgt_epi16(xmm2, xmm3);
88 
89  xmm8 = _mm_and_si128(xmm2, xmm6);
90 
91  xmm3 = _mm_add_epi8(xmm8, xmm4);
92 
93  xmm0 = _mm_shuffle_epi8(xmm0, xmm3);
94 
95 
96  _mm_storel_pd((double*)p_target, (__m128d)xmm0);
97 
98  p_target = (__m128i*)((int8_t*)p_target + 8);
99 
100  }
101 
102  for(i = (bound << 4) + (intermediate << 3); i < (bound << 4) + (intermediate << 3) + leftovers ; i += 2) {
103  target[i>>1] = ((int16_t)(src0[i] - src0[i + 1]) > 0) ? src0[i] : src0[i + 1];
104  }
105 
106 
107 }
108 
109 #endif /*LV_HAVE_SSSE3*/
110 
111 
112 #ifdef LV_HAVE_GENERIC
113 static inline void volk_16i_max_star_horizontal_16i_a_generic(int16_t* target, int16_t* src0, unsigned int num_bytes) {
114 
115  int i = 0;
116 
117  int bound = num_bytes >> 1;
118 
119 
120  for(i = 0; i < bound; i += 2) {
121  target[i >> 1] = ((int16_t) (src0[i] - src0[i + 1]) > 0) ? src0[i] : src0[i+1];
122  }
123 
124 }
125 
126 
127 
128 #endif /*LV_HAVE_GENERIC*/
129 
130 #endif /*INCLUDED_volk_16i_max_star_horizontal_16i_a_H*/