Debian Codegraph @

src/x8-lut/gen/x8-lut-avx-u64.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_u64(
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 >= 64 * sizeof(uint8_t); batch -= 64 * 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 __m128i vx3 = _mm_loadu_si128((const __m128i*) (input + 48));
70 input += 64;
71
72 __m128i vy0 = _mm_shuffle_epi8(vtable0, vx0);
73 __m128i vy1 = _mm_shuffle_epi8(vtable0, vx1);
74 __m128i vy2 = _mm_shuffle_epi8(vtable0, vx2);
75 __m128i vy3 = _mm_shuffle_epi8(vtable0, vx3);
76
77 vx0 = _mm_sub_epi8(vx0, voffset);
78 vx1 = _mm_sub_epi8(vx1, voffset);
79 vx2 = _mm_sub_epi8(vx2, voffset);
80 vx3 = _mm_sub_epi8(vx3, voffset);
81 vy0 = _mm_xor_si128(vy0, _mm_shuffle_epi8(vtable1, vx0));
82 vy1 = _mm_xor_si128(vy1, _mm_shuffle_epi8(vtable1, vx1));
83 vy2 = _mm_xor_si128(vy2, _mm_shuffle_epi8(vtable1, vx2));
84 vy3 = _mm_xor_si128(vy3, _mm_shuffle_epi8(vtable1, vx3));
85 vx0 = _mm_sub_epi8(vx0, voffset);
86 vx1 = _mm_sub_epi8(vx1, voffset);
87 vx2 = _mm_sub_epi8(vx2, voffset);
88 vx3 = _mm_sub_epi8(vx3, voffset);
89 vy0 = _mm_xor_si128(vy0, _mm_shuffle_epi8(vtable2, vx0));
90 vy1 = _mm_xor_si128(vy1, _mm_shuffle_epi8(vtable2, vx1));
91 vy2 = _mm_xor_si128(vy2, _mm_shuffle_epi8(vtable2, vx2));
92 vy3 = _mm_xor_si128(vy3, _mm_shuffle_epi8(vtable2, vx3));
93 vx0 = _mm_sub_epi8(vx0, voffset);
94 vx1 = _mm_sub_epi8(vx1, voffset);
95 vx2 = _mm_sub_epi8(vx2, voffset);
96 vx3 = _mm_sub_epi8(vx3, voffset);
97 vy0 = _mm_xor_si128(vy0, _mm_shuffle_epi8(vtable3, vx0));
98 vy1 = _mm_xor_si128(vy1, _mm_shuffle_epi8(vtable3, vx1));
99 vy2 = _mm_xor_si128(vy2, _mm_shuffle_epi8(vtable3, vx2));
100 vy3 = _mm_xor_si128(vy3, _mm_shuffle_epi8(vtable3, vx3));
101 vx0 = _mm_sub_epi8(vx0, voffset);
102 vx1 = _mm_sub_epi8(vx1, voffset);
103 vx2 = _mm_sub_epi8(vx2, voffset);
104 vx3 = _mm_sub_epi8(vx3, voffset);
105 vy0 = _mm_xor_si128(vy0, _mm_shuffle_epi8(vtable4, vx0));
106 vy1 = _mm_xor_si128(vy1, _mm_shuffle_epi8(vtable4, vx1));
107 vy2 = _mm_xor_si128(vy2, _mm_shuffle_epi8(vtable4, vx2));
108 vy3 = _mm_xor_si128(vy3, _mm_shuffle_epi8(vtable4, vx3));
109 vx0 = _mm_sub_epi8(vx0, voffset);
110 vx1 = _mm_sub_epi8(vx1, voffset);
111 vx2 = _mm_sub_epi8(vx2, voffset);
112 vx3 = _mm_sub_epi8(vx3, voffset);
113 vy0 = _mm_xor_si128(vy0, _mm_shuffle_epi8(vtable5, vx0));
114 vy1 = _mm_xor_si128(vy1, _mm_shuffle_epi8(vtable5, vx1));
115 vy2 = _mm_xor_si128(vy2, _mm_shuffle_epi8(vtable5, vx2));
116 vy3 = _mm_xor_si128(vy3, _mm_shuffle_epi8(vtable5, vx3));
117 vx0 = _mm_sub_epi8(vx0, voffset);
118 vx1 = _mm_sub_epi8(vx1, voffset);
119 vx2 = _mm_sub_epi8(vx2, voffset);
120 vx3 = _mm_sub_epi8(vx3, voffset);
121 vy0 = _mm_xor_si128(vy0, _mm_shuffle_epi8(vtable6, vx0));
122 vy1 = _mm_xor_si128(vy1, _mm_shuffle_epi8(vtable6, vx1));
123 vy2 = _mm_xor_si128(vy2, _mm_shuffle_epi8(vtable6, vx2));
124 vy3 = _mm_xor_si128(vy3, _mm_shuffle_epi8(vtable6, vx3));
125 vx0 = _mm_sub_epi8(vx0, voffset);
126 vx1 = _mm_sub_epi8(vx1, voffset);
127 vx2 = _mm_sub_epi8(vx2, voffset);
128 vx3 = _mm_sub_epi8(vx3, voffset);
129 vy0 = _mm_xor_si128(vy0, _mm_shuffle_epi8(vtable7, vx0));
130 vy1 = _mm_xor_si128(vy1, _mm_shuffle_epi8(vtable7, vx1));
131 vy2 = _mm_xor_si128(vy2, _mm_shuffle_epi8(vtable7, vx2));
132 vy3 = _mm_xor_si128(vy3, _mm_shuffle_epi8(vtable7, vx3));
133 vx0 = _mm_sub_epi8(vx0, voffset);
134 vx1 = _mm_sub_epi8(vx1, voffset);
135 vx2 = _mm_sub_epi8(vx2, voffset);
136 vx3 = _mm_sub_epi8(vx3, voffset);
137 vy0 = _mm_xor_si128(vy0, _mm_shuffle_epi8(vtable8, vx0));
138 vy1 = _mm_xor_si128(vy1, _mm_shuffle_epi8(vtable8, vx1));
139 vy2 = _mm_xor_si128(vy2, _mm_shuffle_epi8(vtable8, vx2));
140 vy3 = _mm_xor_si128(vy3, _mm_shuffle_epi8(vtable8, vx3));
141
142 vx0 = _mm_subs_epi8(vx0, voffset);
143 vx1 = _mm_subs_epi8(vx1, voffset);
144 vx2 = _mm_subs_epi8(vx2, voffset);
145 vx3 = _mm_subs_epi8(vx3, voffset);
146 vy0 = _mm_xor_si128(vy0, _mm_shuffle_epi8(vtable9, vx0));
147 vy1 = _mm_xor_si128(vy1, _mm_shuffle_epi8(vtable9, vx1));
148 vy2 = _mm_xor_si128(vy2, _mm_shuffle_epi8(vtable9, vx2));
149 vy3 = _mm_xor_si128(vy3, _mm_shuffle_epi8(vtable9, vx3));
150 vx0 = _mm_subs_epi8(vx0, voffset);
151 vx1 = _mm_subs_epi8(vx1, voffset);
152 vx2 = _mm_subs_epi8(vx2, voffset);
153 vx3 = _mm_subs_epi8(vx3, voffset);
154 vy0 = _mm_xor_si128(vy0, _mm_shuffle_epi8(vtableA, vx0));
155 vy1 = _mm_xor_si128(vy1, _mm_shuffle_epi8(vtableA, vx1));
156 vy2 = _mm_xor_si128(vy2, _mm_shuffle_epi8(vtableA, vx2));
157 vy3 = _mm_xor_si128(vy3, _mm_shuffle_epi8(vtableA, vx3));
158 vx0 = _mm_subs_epi8(vx0, voffset);
159 vx1 = _mm_subs_epi8(vx1, voffset);
160 vx2 = _mm_subs_epi8(vx2, voffset);
161 vx3 = _mm_subs_epi8(vx3, voffset);
162 vy0 = _mm_xor_si128(vy0, _mm_shuffle_epi8(vtableB, vx0));
163 vy1 = _mm_xor_si128(vy1, _mm_shuffle_epi8(vtableB, vx1));
164 vy2 = _mm_xor_si128(vy2, _mm_shuffle_epi8(vtableB, vx2));
165 vy3 = _mm_xor_si128(vy3, _mm_shuffle_epi8(vtableB, vx3));
166 vx0 = _mm_subs_epi8(vx0, voffset);
167 vx1 = _mm_subs_epi8(vx1, voffset);
168 vx2 = _mm_subs_epi8(vx2, voffset);
169 vx3 = _mm_subs_epi8(vx3, voffset);
170 vy0 = _mm_xor_si128(vy0, _mm_shuffle_epi8(vtableC, vx0));
171 vy1 = _mm_xor_si128(vy1, _mm_shuffle_epi8(vtableC, vx1));
172 vy2 = _mm_xor_si128(vy2, _mm_shuffle_epi8(vtableC, vx2));
173 vy3 = _mm_xor_si128(vy3, _mm_shuffle_epi8(vtableC, vx3));
174 vx0 = _mm_subs_epi8(vx0, voffset);
175 vx1 = _mm_subs_epi8(vx1, voffset);
176 vx2 = _mm_subs_epi8(vx2, voffset);
177 vx3 = _mm_subs_epi8(vx3, voffset);
178 vy0 = _mm_xor_si128(vy0, _mm_shuffle_epi8(vtableD, vx0));
179 vy1 = _mm_xor_si128(vy1, _mm_shuffle_epi8(vtableD, vx1));
180 vy2 = _mm_xor_si128(vy2, _mm_shuffle_epi8(vtableD, vx2));
181 vy3 = _mm_xor_si128(vy3, _mm_shuffle_epi8(vtableD, vx3));
182 vx0 = _mm_subs_epi8(vx0, voffset);
183 vx1 = _mm_subs_epi8(vx1, voffset);
184 vx2 = _mm_subs_epi8(vx2, voffset);
185 vx3 = _mm_subs_epi8(vx3, voffset);
186 vy0 = _mm_xor_si128(vy0, _mm_shuffle_epi8(vtableE, vx0));
187 vy1 = _mm_xor_si128(vy1, _mm_shuffle_epi8(vtableE, vx1));
188 vy2 = _mm_xor_si128(vy2, _mm_shuffle_epi8(vtableE, vx2));
189 vy3 = _mm_xor_si128(vy3, _mm_shuffle_epi8(vtableE, vx3));
190 vx0 = _mm_subs_epi8(vx0, voffset);
191 vx1 = _mm_subs_epi8(vx1, voffset);
192 vx2 = _mm_subs_epi8(vx2, voffset);
193 vx3 = _mm_subs_epi8(vx3, voffset);
194 vy0 = _mm_xor_si128(vy0, _mm_shuffle_epi8(vtableF, vx0));
195 vy1 = _mm_xor_si128(vy1, _mm_shuffle_epi8(vtableF, vx1));
196 vy2 = _mm_xor_si128(vy2, _mm_shuffle_epi8(vtableF, vx2));
197 vy3 = _mm_xor_si128(vy3, _mm_shuffle_epi8(vtableF, vx3));
198
199 _mm_storeu_si128((__m128i*) output, vy0);
200 _mm_storeu_si128((__m128i*) (output + 16), vy1);
201 _mm_storeu_si128((__m128i*) (output + 32), vy2);
202 _mm_storeu_si128((__m128i*) (output + 48), vy3);
203 output += 64;
204 }
205 for (; batch >= 16 * sizeof(uint8_t); batch -= 16 * sizeof(uint8_t)) {
206 __m128i vx = _mm_loadu_si128((const __m128i*) input);
207 input += 16;
208
209 __m128i vy = _mm_shuffle_epi8(vtable0, vx);
210
211 vx = _mm_sub_epi8(vx, voffset);
212 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable1, vx));
213 vx = _mm_sub_epi8(vx, voffset);
214 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable2, vx));
215 vx = _mm_sub_epi8(vx, voffset);
216 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable3, vx));
217 vx = _mm_sub_epi8(vx, voffset);
218 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable4, vx));
219 vx = _mm_sub_epi8(vx, voffset);
220 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable5, vx));
221 vx = _mm_sub_epi8(vx, voffset);
222 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable6, vx));
223 vx = _mm_sub_epi8(vx, voffset);
224 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable7, vx));
225 vx = _mm_sub_epi8(vx, voffset);
226 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable8, vx));
227
228 vx = _mm_subs_epi8(vx, voffset);
229 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable9, vx));
230 vx = _mm_subs_epi8(vx, voffset);
231 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtableA, vx));
232 vx = _mm_subs_epi8(vx, voffset);
233 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtableB, vx));
234 vx = _mm_subs_epi8(vx, voffset);
235 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtableC, vx));
236 vx = _mm_subs_epi8(vx, voffset);
237 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtableD, vx));
238 vx = _mm_subs_epi8(vx, voffset);
239 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtableE, vx));
240 vx = _mm_subs_epi8(vx, voffset);
241 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtableF, vx));
242
243 _mm_storeu_si128((__m128i*) output, vy);
244 output += 16;
245 }
246 if XNN_UNLIKELY(batch != 0) {
247 __m128i vx = _mm_loadu_si128((const __m128i*) input);
248
249 __m128i vy = _mm_shuffle_epi8(vtable0, vx);
250
251 vx = _mm_sub_epi8(vx, voffset);
252 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable1, vx));
253 vx = _mm_sub_epi8(vx, voffset);
254 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable2, vx));
255 vx = _mm_sub_epi8(vx, voffset);
256 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable3, vx));
257 vx = _mm_sub_epi8(vx, voffset);
258 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable4, vx));
259 vx = _mm_sub_epi8(vx, voffset);
260 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable5, vx));
261 vx = _mm_sub_epi8(vx, voffset);
262 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable6, vx));
263 vx = _mm_sub_epi8(vx, voffset);
264 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable7, vx));
265 vx = _mm_sub_epi8(vx, voffset);
266 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable8, vx));
267
268 vx = _mm_subs_epi8(vx, voffset);
269 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable9, vx));
270 vx = _mm_subs_epi8(vx, voffset);
271 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtableA, vx));
272 vx = _mm_subs_epi8(vx, voffset);
273 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtableB, vx));
274 vx = _mm_subs_epi8(vx, voffset);
275 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtableC, vx));
276 vx = _mm_subs_epi8(vx, voffset);
277 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtableD, vx));
278 vx = _mm_subs_epi8(vx, voffset);
279 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtableE, vx));
280 vx = _mm_subs_epi8(vx, voffset);
281 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtableF, vx));
282
283 if (batch & (8 * sizeof(uint8_t))) {
284 _mm_storel_epi64((__m128i*) output, vy);
285 vy = _mm_unpackhi_epi64(vy, vy);
286 output += 8;
287 }
288 if (batch & (4 * sizeof(uint8_t))) {
289 _mm_storeu_si32(output, vy);
290 vy = _mm_srli_epi64(vy, 32);
291 output += 4;
292 }
293 if (batch & (2 * sizeof(uint8_t))) {
294 _mm_storeu_si16(output, vy);
295 vy = _mm_srli_epi32(vy, 16);
296 output += 2;
297 }
298 if (batch & (1 * sizeof(uint8_t))) {
299 *output = (uint8_t) _mm_extract_epi8(vy, 0);
300 }
301 }
302 }