Debian Codegraph @

src/x8-lut/gen/x8-lut-avx512skx-vpshufb-u128.c

raw symbols SCIP
1 // Auto-generated file. Do not edit!
2 // Template: src/x8-lut/avx512skx-vpshufb.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/intrinsics-polyfill.h"
15 #include "xnnpack/lut.h"
16 #include "xnnpack/common.h"
17
18
19 void xnn_x8_lut_ukernel__avx512skx_vpshufb_u128(
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 __m512i vt0 = _mm512_broadcast_i32x4(_mm_load_si128((const __m128i*) table));
31 const __m512i vt1 = _mm512_broadcast_i32x4(_mm_load_si128((const __m128i*) (table + 16)));
32 const __m512i vt2 = _mm512_broadcast_i32x4(_mm_load_si128((const __m128i*) (table + 32)));
33 const __m512i vt3 = _mm512_broadcast_i32x4(_mm_load_si128((const __m128i*) (table + 48)));
34 const __m512i vt4 = _mm512_broadcast_i32x4(_mm_load_si128((const __m128i*) (table + 64)));
35 const __m512i vt5 = _mm512_broadcast_i32x4(_mm_load_si128((const __m128i*) (table + 80)));
36 const __m512i vt6 = _mm512_broadcast_i32x4(_mm_load_si128((const __m128i*) (table + 96)));
37 const __m512i vt7 = _mm512_broadcast_i32x4(_mm_load_si128((const __m128i*) (table + 112)));
38 const __m512i vt8 = _mm512_broadcast_i32x4(_mm_load_si128((const __m128i*) (table + 128)));
39 const __m512i vt9 = _mm512_broadcast_i32x4(_mm_load_si128((const __m128i*) (table + 144)));
40 const __m512i vtA = _mm512_broadcast_i32x4(_mm_load_si128((const __m128i*) (table + 160)));
41 const __m512i vtB = _mm512_broadcast_i32x4(_mm_load_si128((const __m128i*) (table + 176)));
42 const __m512i vtC = _mm512_broadcast_i32x4(_mm_load_si128((const __m128i*) (table + 192)));
43 const __m512i vtD = _mm512_broadcast_i32x4(_mm_load_si128((const __m128i*) (table + 208)));
44 const __m512i vtE = _mm512_broadcast_i32x4(_mm_load_si128((const __m128i*) (table + 224)));
45 const __m512i vtF = _mm512_broadcast_i32x4(_mm_load_si128((const __m128i*) (table + 240)));
46
47 const __m512i vtable0 = vt0;
48 const __m512i vtable1 = _mm512_xor_si512(vt0, vt1);
49 const __m512i vtable2 = _mm512_xor_si512(vt1, vt2);
50 const __m512i vtable3 = _mm512_xor_si512(vt2, vt3);
51 const __m512i vtable4 = _mm512_xor_si512(vt3, vt4);
52 const __m512i vtable5 = _mm512_xor_si512(vt4, vt5);
53 const __m512i vtable6 = _mm512_xor_si512(vt5, vt6);
54 const __m512i vtable7 = _mm512_xor_si512(vt6, vt7);
55 const __m512i vtable8 = _mm512_xor_si512(_mm512_xor_si512(vt7, vt8), vtable0);
56 const __m512i vtable9 = _mm512_xor_si512(_mm512_xor_si512(vt8, vt9), vtable1);
57 const __m512i vtableA = _mm512_xor_si512(_mm512_xor_si512(vt9, vtA), vtable2);
58 const __m512i vtableB = _mm512_xor_si512(_mm512_xor_si512(vtA, vtB), vtable3);
59 const __m512i vtableC = _mm512_xor_si512(_mm512_xor_si512(vtB, vtC), vtable4);
60 const __m512i vtableD = _mm512_xor_si512(_mm512_xor_si512(vtC, vtD), vtable5);
61 const __m512i vtableE = _mm512_xor_si512(_mm512_xor_si512(vtD, vtE), vtable6);
62 const __m512i vtableF = _mm512_xor_si512(_mm512_xor_si512(vtE, vtF), vtable7);
63
64 const __m512i voffset = _mm512_set1_epi8(16);
65 for (; batch >= 128 * sizeof(uint8_t); batch -= 128 * sizeof(uint8_t)) {
66 __m512i vx0 = _mm512_loadu_si512(input);
67 __m512i vx1 = _mm512_loadu_si512(input + 64);
68 input += 128;
69
70 __m512i vy0 = _mm512_shuffle_epi8(vtable0, vx0);
71 __m512i vy1 = _mm512_shuffle_epi8(vtable0, vx1);
72
73 vx0 = _mm512_sub_epi8(vx0, voffset);
74 vx1 = _mm512_sub_epi8(vx1, voffset);
75 vy0 = _mm512_xor_si512(vy0, _mm512_shuffle_epi8(vtable1, vx0));
76 vy1 = _mm512_xor_si512(vy1, _mm512_shuffle_epi8(vtable1, vx1));
77 vx0 = _mm512_sub_epi8(vx0, voffset);
78 vx1 = _mm512_sub_epi8(vx1, voffset);
79 vy0 = _mm512_xor_si512(vy0, _mm512_shuffle_epi8(vtable2, vx0));
80 vy1 = _mm512_xor_si512(vy1, _mm512_shuffle_epi8(vtable2, vx1));
81 vx0 = _mm512_sub_epi8(vx0, voffset);
82 vx1 = _mm512_sub_epi8(vx1, voffset);
83 vy0 = _mm512_xor_si512(vy0, _mm512_shuffle_epi8(vtable3, vx0));
84 vy1 = _mm512_xor_si512(vy1, _mm512_shuffle_epi8(vtable3, vx1));
85 vx0 = _mm512_sub_epi8(vx0, voffset);
86 vx1 = _mm512_sub_epi8(vx1, voffset);
87 vy0 = _mm512_xor_si512(vy0, _mm512_shuffle_epi8(vtable4, vx0));
88 vy1 = _mm512_xor_si512(vy1, _mm512_shuffle_epi8(vtable4, vx1));
89 vx0 = _mm512_sub_epi8(vx0, voffset);
90 vx1 = _mm512_sub_epi8(vx1, voffset);
91 vy0 = _mm512_xor_si512(vy0, _mm512_shuffle_epi8(vtable5, vx0));
92 vy1 = _mm512_xor_si512(vy1, _mm512_shuffle_epi8(vtable5, vx1));
93 vx0 = _mm512_sub_epi8(vx0, voffset);
94 vx1 = _mm512_sub_epi8(vx1, voffset);
95 vy0 = _mm512_xor_si512(vy0, _mm512_shuffle_epi8(vtable6, vx0));
96 vy1 = _mm512_xor_si512(vy1, _mm512_shuffle_epi8(vtable6, vx1));
97 vx0 = _mm512_sub_epi8(vx0, voffset);
98 vx1 = _mm512_sub_epi8(vx1, voffset);
99 vy0 = _mm512_xor_si512(vy0, _mm512_shuffle_epi8(vtable7, vx0));
100 vy1 = _mm512_xor_si512(vy1, _mm512_shuffle_epi8(vtable7, vx1));
101 vx0 = _mm512_sub_epi8(vx0, voffset);
102 vx1 = _mm512_sub_epi8(vx1, voffset);
103 vy0 = _mm512_xor_si512(vy0, _mm512_shuffle_epi8(vtable8, vx0));
104 vy1 = _mm512_xor_si512(vy1, _mm512_shuffle_epi8(vtable8, vx1));
105
106 vx0 = _mm512_subs_epi8(vx0, voffset);
107 vx1 = _mm512_subs_epi8(vx1, voffset);
108 vy0 = _mm512_xor_si512(vy0, _mm512_shuffle_epi8(vtable9, vx0));
109 vy1 = _mm512_xor_si512(vy1, _mm512_shuffle_epi8(vtable9, vx1));
110 vx0 = _mm512_subs_epi8(vx0, voffset);
111 vx1 = _mm512_subs_epi8(vx1, voffset);
112 vy0 = _mm512_xor_si512(vy0, _mm512_shuffle_epi8(vtableA, vx0));
113 vy1 = _mm512_xor_si512(vy1, _mm512_shuffle_epi8(vtableA, vx1));
114 vx0 = _mm512_subs_epi8(vx0, voffset);
115 vx1 = _mm512_subs_epi8(vx1, voffset);
116 vy0 = _mm512_xor_si512(vy0, _mm512_shuffle_epi8(vtableB, vx0));
117 vy1 = _mm512_xor_si512(vy1, _mm512_shuffle_epi8(vtableB, vx1));
118 vx0 = _mm512_subs_epi8(vx0, voffset);
119 vx1 = _mm512_subs_epi8(vx1, voffset);
120 vy0 = _mm512_xor_si512(vy0, _mm512_shuffle_epi8(vtableC, vx0));
121 vy1 = _mm512_xor_si512(vy1, _mm512_shuffle_epi8(vtableC, vx1));
122 vx0 = _mm512_subs_epi8(vx0, voffset);
123 vx1 = _mm512_subs_epi8(vx1, voffset);
124 vy0 = _mm512_xor_si512(vy0, _mm512_shuffle_epi8(vtableD, vx0));
125 vy1 = _mm512_xor_si512(vy1, _mm512_shuffle_epi8(vtableD, vx1));
126 vx0 = _mm512_subs_epi8(vx0, voffset);
127 vx1 = _mm512_subs_epi8(vx1, voffset);
128 vy0 = _mm512_xor_si512(vy0, _mm512_shuffle_epi8(vtableE, vx0));
129 vy1 = _mm512_xor_si512(vy1, _mm512_shuffle_epi8(vtableE, vx1));
130 vx0 = _mm512_subs_epi8(vx0, voffset);
131 vx1 = _mm512_subs_epi8(vx1, voffset);
132 vy0 = _mm512_xor_si512(vy0, _mm512_shuffle_epi8(vtableF, vx0));
133 vy1 = _mm512_xor_si512(vy1, _mm512_shuffle_epi8(vtableF, vx1));
134
135 _mm512_storeu_si512(output, vy0);
136 _mm512_storeu_si512(output + 64, vy1);
137 output += 128;
138 }
139 for (; batch >= 64 * sizeof(uint8_t); batch -= 64 * sizeof(uint8_t)) {
140 __m512i vx = _mm512_loadu_si512(input);
141 input += 64;
142
143 __m512i vy = _mm512_shuffle_epi8(vtable0, vx);
144
145 vx = _mm512_sub_epi8(vx, voffset);
146 vy = _mm512_xor_si512(vy, _mm512_shuffle_epi8(vtable1, vx));
147 vx = _mm512_sub_epi8(vx, voffset);
148 vy = _mm512_xor_si512(vy, _mm512_shuffle_epi8(vtable2, vx));
149 vx = _mm512_sub_epi8(vx, voffset);
150 vy = _mm512_xor_si512(vy, _mm512_shuffle_epi8(vtable3, vx));
151 vx = _mm512_sub_epi8(vx, voffset);
152 vy = _mm512_xor_si512(vy, _mm512_shuffle_epi8(vtable4, vx));
153 vx = _mm512_sub_epi8(vx, voffset);
154 vy = _mm512_xor_si512(vy, _mm512_shuffle_epi8(vtable5, vx));
155 vx = _mm512_sub_epi8(vx, voffset);
156 vy = _mm512_xor_si512(vy, _mm512_shuffle_epi8(vtable6, vx));
157 vx = _mm512_sub_epi8(vx, voffset);
158 vy = _mm512_xor_si512(vy, _mm512_shuffle_epi8(vtable7, vx));
159 vx = _mm512_sub_epi8(vx, voffset);
160 vy = _mm512_xor_si512(vy, _mm512_shuffle_epi8(vtable8, vx));
161
162 vx = _mm512_subs_epi8(vx, voffset);
163 vy = _mm512_xor_si512(vy, _mm512_shuffle_epi8(vtable9, vx));
164 vx = _mm512_subs_epi8(vx, voffset);
165 vy = _mm512_xor_si512(vy, _mm512_shuffle_epi8(vtableA, vx));
166 vx = _mm512_subs_epi8(vx, voffset);
167 vy = _mm512_xor_si512(vy, _mm512_shuffle_epi8(vtableB, vx));
168 vx = _mm512_subs_epi8(vx, voffset);
169 vy = _mm512_xor_si512(vy, _mm512_shuffle_epi8(vtableC, vx));
170 vx = _mm512_subs_epi8(vx, voffset);
171 vy = _mm512_xor_si512(vy, _mm512_shuffle_epi8(vtableD, vx));
172 vx = _mm512_subs_epi8(vx, voffset);
173 vy = _mm512_xor_si512(vy, _mm512_shuffle_epi8(vtableE, vx));
174 vx = _mm512_subs_epi8(vx, voffset);
175 vy = _mm512_xor_si512(vy, _mm512_shuffle_epi8(vtableF, vx));
176
177 _mm512_storeu_si512(output, vy);
178 output += 64;
179 }
180 if XNN_UNLIKELY(batch != 0) {
181 assert(batch < 64);
182 const __mmask64 vmask = _cvtu64_mask64((uint64_t) ((UINT64_C(1) << batch) - UINT64_C(1)));
183
184 __m512i vx = _mm512_maskz_loadu_epi8(vmask, input);
185
186 __m512i vy = _mm512_shuffle_epi8(vtable0, vx);
187
188 vx = _mm512_sub_epi8(vx, voffset);
189 vy = _mm512_xor_si512(vy, _mm512_shuffle_epi8(vtable1, vx));
190 vx = _mm512_sub_epi8(vx, voffset);
191 vy = _mm512_xor_si512(vy, _mm512_shuffle_epi8(vtable2, vx));
192 vx = _mm512_sub_epi8(vx, voffset);
193 vy = _mm512_xor_si512(vy, _mm512_shuffle_epi8(vtable3, vx));
194 vx = _mm512_sub_epi8(vx, voffset);
195 vy = _mm512_xor_si512(vy, _mm512_shuffle_epi8(vtable4, vx));
196 vx = _mm512_sub_epi8(vx, voffset);
197 vy = _mm512_xor_si512(vy, _mm512_shuffle_epi8(vtable5, vx));
198 vx = _mm512_sub_epi8(vx, voffset);
199 vy = _mm512_xor_si512(vy, _mm512_shuffle_epi8(vtable6, vx));
200 vx = _mm512_sub_epi8(vx, voffset);
201 vy = _mm512_xor_si512(vy, _mm512_shuffle_epi8(vtable7, vx));
202 vx = _mm512_sub_epi8(vx, voffset);
203 vy = _mm512_xor_si512(vy, _mm512_shuffle_epi8(vtable8, vx));
204
205 vx = _mm512_subs_epi8(vx, voffset);
206 vy = _mm512_xor_si512(vy, _mm512_shuffle_epi8(vtable9, vx));
207 vx = _mm512_subs_epi8(vx, voffset);
208 vy = _mm512_xor_si512(vy, _mm512_shuffle_epi8(vtableA, vx));
209 vx = _mm512_subs_epi8(vx, voffset);
210 vy = _mm512_xor_si512(vy, _mm512_shuffle_epi8(vtableB, vx));
211 vx = _mm512_subs_epi8(vx, voffset);
212 vy = _mm512_xor_si512(vy, _mm512_shuffle_epi8(vtableC, vx));
213 vx = _mm512_subs_epi8(vx, voffset);
214 vy = _mm512_xor_si512(vy, _mm512_shuffle_epi8(vtableD, vx));
215 vx = _mm512_subs_epi8(vx, voffset);
216 vy = _mm512_xor_si512(vy, _mm512_shuffle_epi8(vtableE, vx));
217 vx = _mm512_subs_epi8(vx, voffset);
218 vy = _mm512_xor_si512(vy, _mm512_shuffle_epi8(vtableF, vx));
219
220 _mm512_mask_storeu_epi8(output, vmask, vy);
221 }
222 }