Debian Codegraph @

src/x8-lut/gen/x8-lut-avx-u48.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/x8-lut/ssse3.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2021 Google LLC
6 //
7 // This source code is licensed under the BSD-style license found in the
8 // LICENSE file in the root directory of this source tree.
9
10 #include <assert.h>
11
12 #include <immintrin.h>
13
14 #include "xnnpack/common.h"
15 #include "xnnpack/intrinsics-polyfill.h"
16 #include "xnnpack/lut.h"
17
18
19 void xnn_x8_lut_ukernel__avx_u48(
20 size_t batch,
21 const uint8_t* input,
22 uint8_t* output,
23 const uint8_t table[restrict XNN_MIN_ELEMENTS(256)])
24 {
25 assert(batch != 0);
26 assert(batch % sizeof(uint8_t) == 0);
27 assert(input != NULL);
28 assert(output != NULL);
29
30 const __m128i vt0 = _mm_load_si128((const __m128i*) table);
31 const __m128i vt1 = _mm_load_si128((const __m128i*) (table + 16));
32 const __m128i vt2 = _mm_load_si128((const __m128i*) (table + 32));
33 const __m128i vt3 = _mm_load_si128((const __m128i*) (table + 48));
34 const __m128i vt4 = _mm_load_si128((const __m128i*) (table + 64));
35 const __m128i vt5 = _mm_load_si128((const __m128i*) (table + 80));
36 const __m128i vt6 = _mm_load_si128((const __m128i*) (table + 96));
37 const __m128i vt7 = _mm_load_si128((const __m128i*) (table + 112));
38 const __m128i vt8 = _mm_load_si128((const __m128i*) (table + 128));
39 const __m128i vt9 = _mm_load_si128((const __m128i*) (table + 144));
40 const __m128i vtA = _mm_load_si128((const __m128i*) (table + 160));
41 const __m128i vtB = _mm_load_si128((const __m128i*) (table + 176));
42 const __m128i vtC = _mm_load_si128((const __m128i*) (table + 192));
43 const __m128i vtD = _mm_load_si128((const __m128i*) (table + 208));
44 const __m128i vtE = _mm_load_si128((const __m128i*) (table + 224));
45 const __m128i vtF = _mm_load_si128((const __m128i*) (table + 240));
46
47 const __m128i vtable0 = vt0;
48 const __m128i vtable1 = _mm_xor_si128(vt0, vt1);
49 const __m128i vtable2 = _mm_xor_si128(vt1, vt2);
50 const __m128i vtable3 = _mm_xor_si128(vt2, vt3);
51 const __m128i vtable4 = _mm_xor_si128(vt3, vt4);
52 const __m128i vtable5 = _mm_xor_si128(vt4, vt5);
53 const __m128i vtable6 = _mm_xor_si128(vt5, vt6);
54 const __m128i vtable7 = _mm_xor_si128(vt6, vt7);
55 const __m128i vtable8 = _mm_xor_si128(_mm_xor_si128(vt7, vt8), vtable0);
56 const __m128i vtable9 = _mm_xor_si128(_mm_xor_si128(vt8, vt9), vtable1);
57 const __m128i vtableA = _mm_xor_si128(_mm_xor_si128(vt9, vtA), vtable2);
58 const __m128i vtableB = _mm_xor_si128(_mm_xor_si128(vtA, vtB), vtable3);
59 const __m128i vtableC = _mm_xor_si128(_mm_xor_si128(vtB, vtC), vtable4);
60 const __m128i vtableD = _mm_xor_si128(_mm_xor_si128(vtC, vtD), vtable5);
61 const __m128i vtableE = _mm_xor_si128(_mm_xor_si128(vtD, vtE), vtable6);
62 const __m128i vtableF = _mm_xor_si128(_mm_xor_si128(vtE, vtF), vtable7);
63
64 const __m128i voffset = _mm_set1_epi8(16);
65 for (; batch >= 48 * sizeof(uint8_t); batch -= 48 * sizeof(uint8_t)) {
66 __m128i vx0 = _mm_loadu_si128((const __m128i*) input);
67 __m128i vx1 = _mm_loadu_si128((const __m128i*) (input + 16));
68 __m128i vx2 = _mm_loadu_si128((const __m128i*) (input + 32));
69 input += 48;
70
71 __m128i vy0 = _mm_shuffle_epi8(vtable0, vx0);
72 __m128i vy1 = _mm_shuffle_epi8(vtable0, vx1);
73 __m128i vy2 = _mm_shuffle_epi8(vtable0, vx2);
74
75 vx0 = _mm_sub_epi8(vx0, voffset);
76 vx1 = _mm_sub_epi8(vx1, voffset);
77 vx2 = _mm_sub_epi8(vx2, voffset);
78 vy0 = _mm_xor_si128(vy0, _mm_shuffle_epi8(vtable1, vx0));
79 vy1 = _mm_xor_si128(vy1, _mm_shuffle_epi8(vtable1, vx1));
80 vy2 = _mm_xor_si128(vy2, _mm_shuffle_epi8(vtable1, vx2));
81 vx0 = _mm_sub_epi8(vx0, voffset);
82 vx1 = _mm_sub_epi8(vx1, voffset);
83 vx2 = _mm_sub_epi8(vx2, voffset);
84 vy0 = _mm_xor_si128(vy0, _mm_shuffle_epi8(vtable2, vx0));
85 vy1 = _mm_xor_si128(vy1, _mm_shuffle_epi8(vtable2, vx1));
86 vy2 = _mm_xor_si128(vy2, _mm_shuffle_epi8(vtable2, vx2));
87 vx0 = _mm_sub_epi8(vx0, voffset);
88 vx1 = _mm_sub_epi8(vx1, voffset);
89 vx2 = _mm_sub_epi8(vx2, voffset);
90 vy0 = _mm_xor_si128(vy0, _mm_shuffle_epi8(vtable3, vx0));
91 vy1 = _mm_xor_si128(vy1, _mm_shuffle_epi8(vtable3, vx1));
92 vy2 = _mm_xor_si128(vy2, _mm_shuffle_epi8(vtable3, vx2));
93 vx0 = _mm_sub_epi8(vx0, voffset);
94 vx1 = _mm_sub_epi8(vx1, voffset);
95 vx2 = _mm_sub_epi8(vx2, voffset);
96 vy0 = _mm_xor_si128(vy0, _mm_shuffle_epi8(vtable4, vx0));
97 vy1 = _mm_xor_si128(vy1, _mm_shuffle_epi8(vtable4, vx1));
98 vy2 = _mm_xor_si128(vy2, _mm_shuffle_epi8(vtable4, vx2));
99 vx0 = _mm_sub_epi8(vx0, voffset);
100 vx1 = _mm_sub_epi8(vx1, voffset);
101 vx2 = _mm_sub_epi8(vx2, voffset);
102 vy0 = _mm_xor_si128(vy0, _mm_shuffle_epi8(vtable5, vx0));
103 vy1 = _mm_xor_si128(vy1, _mm_shuffle_epi8(vtable5, vx1));
104 vy2 = _mm_xor_si128(vy2, _mm_shuffle_epi8(vtable5, vx2));
105 vx0 = _mm_sub_epi8(vx0, voffset);
106 vx1 = _mm_sub_epi8(vx1, voffset);
107 vx2 = _mm_sub_epi8(vx2, voffset);
108 vy0 = _mm_xor_si128(vy0, _mm_shuffle_epi8(vtable6, vx0));
109 vy1 = _mm_xor_si128(vy1, _mm_shuffle_epi8(vtable6, vx1));
110 vy2 = _mm_xor_si128(vy2, _mm_shuffle_epi8(vtable6, vx2));
111 vx0 = _mm_sub_epi8(vx0, voffset);
112 vx1 = _mm_sub_epi8(vx1, voffset);
113 vx2 = _mm_sub_epi8(vx2, voffset);
114 vy0 = _mm_xor_si128(vy0, _mm_shuffle_epi8(vtable7, vx0));
115 vy1 = _mm_xor_si128(vy1, _mm_shuffle_epi8(vtable7, vx1));
116 vy2 = _mm_xor_si128(vy2, _mm_shuffle_epi8(vtable7, vx2));
117 vx0 = _mm_sub_epi8(vx0, voffset);
118 vx1 = _mm_sub_epi8(vx1, voffset);
119 vx2 = _mm_sub_epi8(vx2, voffset);
120 vy0 = _mm_xor_si128(vy0, _mm_shuffle_epi8(vtable8, vx0));
121 vy1 = _mm_xor_si128(vy1, _mm_shuffle_epi8(vtable8, vx1));
122 vy2 = _mm_xor_si128(vy2, _mm_shuffle_epi8(vtable8, vx2));
123
124 vx0 = _mm_subs_epi8(vx0, voffset);
125 vx1 = _mm_subs_epi8(vx1, voffset);
126 vx2 = _mm_subs_epi8(vx2, voffset);
127 vy0 = _mm_xor_si128(vy0, _mm_shuffle_epi8(vtable9, vx0));
128 vy1 = _mm_xor_si128(vy1, _mm_shuffle_epi8(vtable9, vx1));
129 vy2 = _mm_xor_si128(vy2, _mm_shuffle_epi8(vtable9, vx2));
130 vx0 = _mm_subs_epi8(vx0, voffset);
131 vx1 = _mm_subs_epi8(vx1, voffset);
132 vx2 = _mm_subs_epi8(vx2, voffset);
133 vy0 = _mm_xor_si128(vy0, _mm_shuffle_epi8(vtableA, vx0));
134 vy1 = _mm_xor_si128(vy1, _mm_shuffle_epi8(vtableA, vx1));
135 vy2 = _mm_xor_si128(vy2, _mm_shuffle_epi8(vtableA, vx2));
136 vx0 = _mm_subs_epi8(vx0, voffset);
137 vx1 = _mm_subs_epi8(vx1, voffset);
138 vx2 = _mm_subs_epi8(vx2, voffset);
139 vy0 = _mm_xor_si128(vy0, _mm_shuffle_epi8(vtableB, vx0));
140 vy1 = _mm_xor_si128(vy1, _mm_shuffle_epi8(vtableB, vx1));
141 vy2 = _mm_xor_si128(vy2, _mm_shuffle_epi8(vtableB, vx2));
142 vx0 = _mm_subs_epi8(vx0, voffset);
143 vx1 = _mm_subs_epi8(vx1, voffset);
144 vx2 = _mm_subs_epi8(vx2, voffset);
145 vy0 = _mm_xor_si128(vy0, _mm_shuffle_epi8(vtableC, vx0));
146 vy1 = _mm_xor_si128(vy1, _mm_shuffle_epi8(vtableC, vx1));
147 vy2 = _mm_xor_si128(vy2, _mm_shuffle_epi8(vtableC, vx2));
148 vx0 = _mm_subs_epi8(vx0, voffset);
149 vx1 = _mm_subs_epi8(vx1, voffset);
150 vx2 = _mm_subs_epi8(vx2, voffset);
151 vy0 = _mm_xor_si128(vy0, _mm_shuffle_epi8(vtableD, vx0));
152 vy1 = _mm_xor_si128(vy1, _mm_shuffle_epi8(vtableD, vx1));
153 vy2 = _mm_xor_si128(vy2, _mm_shuffle_epi8(vtableD, vx2));
154 vx0 = _mm_subs_epi8(vx0, voffset);
155 vx1 = _mm_subs_epi8(vx1, voffset);
156 vx2 = _mm_subs_epi8(vx2, voffset);
157 vy0 = _mm_xor_si128(vy0, _mm_shuffle_epi8(vtableE, vx0));
158 vy1 = _mm_xor_si128(vy1, _mm_shuffle_epi8(vtableE, vx1));
159 vy2 = _mm_xor_si128(vy2, _mm_shuffle_epi8(vtableE, vx2));
160 vx0 = _mm_subs_epi8(vx0, voffset);
161 vx1 = _mm_subs_epi8(vx1, voffset);
162 vx2 = _mm_subs_epi8(vx2, voffset);
163 vy0 = _mm_xor_si128(vy0, _mm_shuffle_epi8(vtableF, vx0));
164 vy1 = _mm_xor_si128(vy1, _mm_shuffle_epi8(vtableF, vx1));
165 vy2 = _mm_xor_si128(vy2, _mm_shuffle_epi8(vtableF, vx2));
166
167 _mm_storeu_si128((__m128i*) output, vy0);
168 _mm_storeu_si128((__m128i*) (output + 16), vy1);
169 _mm_storeu_si128((__m128i*) (output + 32), vy2);
170 output += 48;
171 }
172 for (; batch >= 16 * sizeof(uint8_t); batch -= 16 * sizeof(uint8_t)) {
173 __m128i vx = _mm_loadu_si128((const __m128i*) input);
174 input += 16;
175
176 __m128i vy = _mm_shuffle_epi8(vtable0, vx);
177
178 vx = _mm_sub_epi8(vx, voffset);
179 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable1, vx));
180 vx = _mm_sub_epi8(vx, voffset);
181 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable2, vx));
182 vx = _mm_sub_epi8(vx, voffset);
183 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable3, vx));
184 vx = _mm_sub_epi8(vx, voffset);
185 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable4, vx));
186 vx = _mm_sub_epi8(vx, voffset);
187 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable5, vx));
188 vx = _mm_sub_epi8(vx, voffset);
189 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable6, vx));
190 vx = _mm_sub_epi8(vx, voffset);
191 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable7, vx));
192 vx = _mm_sub_epi8(vx, voffset);
193 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable8, vx));
194
195 vx = _mm_subs_epi8(vx, voffset);
196 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable9, vx));
197 vx = _mm_subs_epi8(vx, voffset);
198 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtableA, vx));
199 vx = _mm_subs_epi8(vx, voffset);
200 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtableB, vx));
201 vx = _mm_subs_epi8(vx, voffset);
202 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtableC, vx));
203 vx = _mm_subs_epi8(vx, voffset);
204 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtableD, vx));
205 vx = _mm_subs_epi8(vx, voffset);
206 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtableE, vx));
207 vx = _mm_subs_epi8(vx, voffset);
208 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtableF, vx));
209
210 _mm_storeu_si128((__m128i*) output, vy);
211 output += 16;
212 }
213 if XNN_UNLIKELY(batch != 0) {
214 __m128i vx = _mm_loadu_si128((const __m128i*) input);
215
216 __m128i vy = _mm_shuffle_epi8(vtable0, vx);
217
218 vx = _mm_sub_epi8(vx, voffset);
219 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable1, vx));
220 vx = _mm_sub_epi8(vx, voffset);
221 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable2, vx));
222 vx = _mm_sub_epi8(vx, voffset);
223 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable3, vx));
224 vx = _mm_sub_epi8(vx, voffset);
225 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable4, vx));
226 vx = _mm_sub_epi8(vx, voffset);
227 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable5, vx));
228 vx = _mm_sub_epi8(vx, voffset);
229 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable6, vx));
230 vx = _mm_sub_epi8(vx, voffset);
231 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable7, vx));
232 vx = _mm_sub_epi8(vx, voffset);
233 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable8, vx));
234
235 vx = _mm_subs_epi8(vx, voffset);
236 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable9, vx));
237 vx = _mm_subs_epi8(vx, voffset);
238 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtableA, vx));
239 vx = _mm_subs_epi8(vx, voffset);
240 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtableB, vx));
241 vx = _mm_subs_epi8(vx, voffset);
242 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtableC, vx));
243 vx = _mm_subs_epi8(vx, voffset);
244 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtableD, vx));
245 vx = _mm_subs_epi8(vx, voffset);
246 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtableE, vx));
247 vx = _mm_subs_epi8(vx, voffset);
248 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtableF, vx));
249
250 if (batch & (8 * sizeof(uint8_t))) {
251 _mm_storel_epi64((__m128i*) output, vy);
252 vy = _mm_unpackhi_epi64(vy, vy);
253 output += 8;
254 }
255 if (batch & (4 * sizeof(uint8_t))) {
256 _mm_storeu_si32(output, vy);
257 vy = _mm_srli_epi64(vy, 32);
258 output += 4;
259 }
260 if (batch & (2 * sizeof(uint8_t))) {
261 _mm_storeu_si16(output, vy);
262 vy = _mm_srli_epi32(vy, 16);
263 output += 2;
264 }
265 if (batch & (1 * sizeof(uint8_t))) {
266 *output = (uint8_t) _mm_extract_epi8(vy, 0);
267 }
268 }
269 }