23 #ifndef INCLUDED_volk_16i_permute_and_scalar_add_a_H
24 #define INCLUDED_volk_16i_permute_and_scalar_add_a_H
38 static inline void volk_16i_permute_and_scalar_add_a_sse2(
short* target,
short* src0,
short* permute_indexes,
short* cntl0,
short* cntl1,
short* cntl2,
short* cntl3,
short* scalars,
unsigned int num_points) {
40 const unsigned int num_bytes = num_points*2;
42 __m128i xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7;
44 __m128i *p_target, *p_cntl0, *p_cntl1, *p_cntl2, *p_cntl3, *p_scalars;
46 short* p_permute_indexes = permute_indexes;
48 p_target = (__m128i*)target;
49 p_cntl0 = (__m128i*)cntl0;
50 p_cntl1 = (__m128i*)cntl1;
51 p_cntl2 = (__m128i*)cntl2;
52 p_cntl3 = (__m128i*)cntl3;
53 p_scalars = (__m128i*)scalars;
57 int bound = (num_bytes >> 4);
58 int leftovers = (num_bytes >> 1) & 7;
60 xmm0 = _mm_load_si128(p_scalars);
62 xmm1 = _mm_shufflelo_epi16(xmm0, 0);
63 xmm2 = _mm_shufflelo_epi16(xmm0, 0x55);
64 xmm3 = _mm_shufflelo_epi16(xmm0, 0xaa);
65 xmm4 = _mm_shufflelo_epi16(xmm0, 0xff);
67 xmm1 = _mm_shuffle_epi32(xmm1, 0x00);
68 xmm2 = _mm_shuffle_epi32(xmm2, 0x00);
69 xmm3 = _mm_shuffle_epi32(xmm3, 0x00);
70 xmm4 = _mm_shuffle_epi32(xmm4, 0x00);
73 for(; i < bound; ++i) {
74 xmm0 = _mm_setzero_si128();
75 xmm5 = _mm_setzero_si128();
76 xmm6 = _mm_setzero_si128();
77 xmm7 = _mm_setzero_si128();
79 xmm0 = _mm_insert_epi16(xmm0, src0[p_permute_indexes[0]], 0);
80 xmm5 = _mm_insert_epi16(xmm5, src0[p_permute_indexes[1]], 1);
81 xmm6 = _mm_insert_epi16(xmm6, src0[p_permute_indexes[2]], 2);
82 xmm7 = _mm_insert_epi16(xmm7, src0[p_permute_indexes[3]], 3);
83 xmm0 = _mm_insert_epi16(xmm0, src0[p_permute_indexes[4]], 4);
84 xmm5 = _mm_insert_epi16(xmm5, src0[p_permute_indexes[5]], 5);
85 xmm6 = _mm_insert_epi16(xmm6, src0[p_permute_indexes[6]], 6);
86 xmm7 = _mm_insert_epi16(xmm7, src0[p_permute_indexes[7]], 7);
88 xmm0 = _mm_add_epi16(xmm0, xmm5);
89 xmm6 = _mm_add_epi16(xmm6, xmm7);
91 p_permute_indexes += 8;
93 xmm0 = _mm_add_epi16(xmm0, xmm6);
95 xmm5 = _mm_load_si128(p_cntl0);
96 xmm6 = _mm_load_si128(p_cntl1);
97 xmm7 = _mm_load_si128(p_cntl2);
99 xmm5 = _mm_and_si128(xmm5, xmm1);
100 xmm6 = _mm_and_si128(xmm6, xmm2);
101 xmm7 = _mm_and_si128(xmm7, xmm3);
103 xmm0 = _mm_add_epi16(xmm0, xmm5);
105 xmm5 = _mm_load_si128(p_cntl3);
107 xmm6 = _mm_add_epi16(xmm6, xmm7);
111 xmm5 = _mm_and_si128(xmm5, xmm4);
113 xmm0 = _mm_add_epi16(xmm0, xmm6);
118 xmm0 = _mm_add_epi16(xmm0, xmm5);
122 _mm_store_si128(p_target, xmm0);
131 for(i = bound * 8; i < (bound * 8) + leftovers; ++i) {
132 target[i] = src0[permute_indexes[i]]
133 + (cntl0[i] & scalars[0])
134 + (cntl1[i] & scalars[1])
135 + (cntl2[i] & scalars[2])
136 + (cntl3[i] & scalars[3]);
142 #ifdef LV_HAVE_GENERIC
143 static inline void volk_16i_permute_and_scalar_add_generic(
short* target,
short* src0,
short* permute_indexes,
short* cntl0,
short* cntl1,
short* cntl2,
short* cntl3,
short* scalars,
unsigned int num_points) {
145 const unsigned int num_bytes = num_points*2;
149 int bound = num_bytes >> 1;
151 for(i = 0; i < bound; ++i) {
152 target[i] = src0[permute_indexes[i]]
153 + (cntl0[i] & scalars[0])
154 + (cntl1[i] & scalars[1])
155 + (cntl2[i] & scalars[2])
156 + (cntl3[i] & scalars[3]);