Debian Codegraph @

src/x8-lut/gen/x8-lut-avx-u32.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_u32(
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 >= 32 * sizeof(uint8_t); batch -= 32 * sizeof(uint8_t)) {
66 __m128i vx0 = _mm_loadu_si128((const __m128i*) input);
67 __m128i vx1 = _mm_loadu_si128((const __m128i*) (input + 16));
68 input += 32;
69
70 __m128i vy0 = _mm_shuffle_epi8(vtable0, vx0);
71 __m128i vy1 = _mm_shuffle_epi8(vtable0, vx1);
72
73 vx0 = _mm_sub_epi8(vx0, voffset);
74 vx1 = _mm_sub_epi8(vx1, voffset);
75 vy0 = _mm_xor_si128(vy0, _mm_shuffle_epi8(vtable1, vx0));
76 vy1 = _mm_xor_si128(vy1, _mm_shuffle_epi8(vtable1, vx1));
77 vx0 = _mm_sub_epi8(vx0, voffset);
78 vx1 = _mm_sub_epi8(vx1, voffset);
79 vy0 = _mm_xor_si128(vy0, _mm_shuffle_epi8(vtable2, vx0));
80 vy1 = _mm_xor_si128(vy1, _mm_shuffle_epi8(vtable2, vx1));
81 vx0 = _mm_sub_epi8(vx0, voffset);
82 vx1 = _mm_sub_epi8(vx1, voffset);
83 vy0 = _mm_xor_si128(vy0, _mm_shuffle_epi8(vtable3, vx0));
84 vy1 = _mm_xor_si128(vy1, _mm_shuffle_epi8(vtable3, vx1));
85 vx0 = _mm_sub_epi8(vx0, voffset);
86 vx1 = _mm_sub_epi8(vx1, voffset);
87 vy0 = _mm_xor_si128(vy0, _mm_shuffle_epi8(vtable4, vx0));
88 vy1 = _mm_xor_si128(vy1, _mm_shuffle_epi8(vtable4, vx1));
89 vx0 = _mm_sub_epi8(vx0, voffset);
90 vx1 = _mm_sub_epi8(vx1, voffset);
91 vy0 = _mm_xor_si128(vy0, _mm_shuffle_epi8(vtable5, vx0));
92 vy1 = _mm_xor_si128(vy1, _mm_shuffle_epi8(vtable5, vx1));
93 vx0 = _mm_sub_epi8(vx0, voffset);
94 vx1 = _mm_sub_epi8(vx1, voffset);
95 vy0 = _mm_xor_si128(vy0, _mm_shuffle_epi8(vtable6, vx0));
96 vy1 = _mm_xor_si128(vy1, _mm_shuffle_epi8(vtable6, vx1));
97 vx0 = _mm_sub_epi8(vx0, voffset);
98 vx1 = _mm_sub_epi8(vx1, voffset);
99 vy0 = _mm_xor_si128(vy0, _mm_shuffle_epi8(vtable7, vx0));
100 vy1 = _mm_xor_si128(vy1, _mm_shuffle_epi8(vtable7, vx1));
101 vx0 = _mm_sub_epi8(vx0, voffset);
102 vx1 = _mm_sub_epi8(vx1, voffset);
103 vy0 = _mm_xor_si128(vy0, _mm_shuffle_epi8(vtable8, vx0));
104 vy1 = _mm_xor_si128(vy1, _mm_shuffle_epi8(vtable8, vx1));
105
106 vx0 = _mm_subs_epi8(vx0, voffset);
107 vx1 = _mm_subs_epi8(vx1, voffset);
108 vy0 = _mm_xor_si128(vy0, _mm_shuffle_epi8(vtable9, vx0));
109 vy1 = _mm_xor_si128(vy1, _mm_shuffle_epi8(vtable9, vx1));
110 vx0 = _mm_subs_epi8(vx0, voffset);
111 vx1 = _mm_subs_epi8(vx1, voffset);
112 vy0 = _mm_xor_si128(vy0, _mm_shuffle_epi8(vtableA, vx0));
113 vy1 = _mm_xor_si128(vy1, _mm_shuffle_epi8(vtableA, vx1));
114 vx0 = _mm_subs_epi8(vx0, voffset);
115 vx1 = _mm_subs_epi8(vx1, voffset);
116 vy0 = _mm_xor_si128(vy0, _mm_shuffle_epi8(vtableB, vx0));
117 vy1 = _mm_xor_si128(vy1, _mm_shuffle_epi8(vtableB, vx1));
118 vx0 = _mm_subs_epi8(vx0, voffset);
119 vx1 = _mm_subs_epi8(vx1, voffset);
120 vy0 = _mm_xor_si128(vy0, _mm_shuffle_epi8(vtableC, vx0));
121 vy1 = _mm_xor_si128(vy1, _mm_shuffle_epi8(vtableC, vx1));
122 vx0 = _mm_subs_epi8(vx0, voffset);
123 vx1 = _mm_subs_epi8(vx1, voffset);
124 vy0 = _mm_xor_si128(vy0, _mm_shuffle_epi8(vtableD, vx0));
125 vy1 = _mm_xor_si128(vy1, _mm_shuffle_epi8(vtableD, vx1));
126 vx0 = _mm_subs_epi8(vx0, voffset);
127 vx1 = _mm_subs_epi8(vx1, voffset);
128 vy0 = _mm_xor_si128(vy0, _mm_shuffle_epi8(vtableE, vx0));
129 vy1 = _mm_xor_si128(vy1, _mm_shuffle_epi8(vtableE, vx1));
130 vx0 = _mm_subs_epi8(vx0, voffset);
131 vx1 = _mm_subs_epi8(vx1, voffset);
132 vy0 = _mm_xor_si128(vy0, _mm_shuffle_epi8(vtableF, vx0));
133 vy1 = _mm_xor_si128(vy1, _mm_shuffle_epi8(vtableF, vx1));
134
135 _mm_storeu_si128((__m128i*) output, vy0);
136 _mm_storeu_si128((__m128i*) (output + 16), vy1);
137 output += 32;
138 }
139 for (; batch >= 16 * sizeof(uint8_t); batch -= 16 * sizeof(uint8_t)) {
140 __m128i vx = _mm_loadu_si128((const __m128i*) input);
141 input += 16;
142
143 __m128i vy = _mm_shuffle_epi8(vtable0, vx);
144
145 vx = _mm_sub_epi8(vx, voffset);
146 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable1, vx));
147 vx = _mm_sub_epi8(vx, voffset);
148 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable2, vx));
149 vx = _mm_sub_epi8(vx, voffset);
150 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable3, vx));
151 vx = _mm_sub_epi8(vx, voffset);
152 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable4, vx));
153 vx = _mm_sub_epi8(vx, voffset);
154 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable5, vx));
155 vx = _mm_sub_epi8(vx, voffset);
156 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable6, vx));
157 vx = _mm_sub_epi8(vx, voffset);
158 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable7, vx));
159 vx = _mm_sub_epi8(vx, voffset);
160 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable8, vx));
161
162 vx = _mm_subs_epi8(vx, voffset);
163 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable9, vx));
164 vx = _mm_subs_epi8(vx, voffset);
165 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtableA, vx));
166 vx = _mm_subs_epi8(vx, voffset);
167 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtableB, vx));
168 vx = _mm_subs_epi8(vx, voffset);
169 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtableC, vx));
170 vx = _mm_subs_epi8(vx, voffset);
171 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtableD, vx));
172 vx = _mm_subs_epi8(vx, voffset);
173 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtableE, vx));
174 vx = _mm_subs_epi8(vx, voffset);
175 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtableF, vx));
176
177 _mm_storeu_si128((__m128i*) output, vy);
178 output += 16;
179 }
180 if XNN_UNLIKELY(batch != 0) {
181 __m128i vx = _mm_loadu_si128((const __m128i*) input);
182
183 __m128i vy = _mm_shuffle_epi8(vtable0, vx);
184
185 vx = _mm_sub_epi8(vx, voffset);
186 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable1, vx));
187 vx = _mm_sub_epi8(vx, voffset);
188 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable2, vx));
189 vx = _mm_sub_epi8(vx, voffset);
190 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable3, vx));
191 vx = _mm_sub_epi8(vx, voffset);
192 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable4, vx));
193 vx = _mm_sub_epi8(vx, voffset);
194 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable5, vx));
195 vx = _mm_sub_epi8(vx, voffset);
196 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable6, vx));
197 vx = _mm_sub_epi8(vx, voffset);
198 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable7, vx));
199 vx = _mm_sub_epi8(vx, voffset);
200 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable8, vx));
201
202 vx = _mm_subs_epi8(vx, voffset);
203 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtable9, vx));
204 vx = _mm_subs_epi8(vx, voffset);
205 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtableA, vx));
206 vx = _mm_subs_epi8(vx, voffset);
207 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtableB, vx));
208 vx = _mm_subs_epi8(vx, voffset);
209 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtableC, vx));
210 vx = _mm_subs_epi8(vx, voffset);
211 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtableD, vx));
212 vx = _mm_subs_epi8(vx, voffset);
213 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtableE, vx));
214 vx = _mm_subs_epi8(vx, voffset);
215 vy = _mm_xor_si128(vy, _mm_shuffle_epi8(vtableF, vx));
216
217 if (batch & (8 * sizeof(uint8_t))) {
218 _mm_storel_epi64((__m128i*) output, vy);
219 vy = _mm_unpackhi_epi64(vy, vy);
220 output += 8;
221 }
222 if (batch & (4 * sizeof(uint8_t))) {
223 _mm_storeu_si32(output, vy);
224 vy = _mm_srli_epi64(vy, 32);
225 output += 4;
226 }
227 if (batch & (2 * sizeof(uint8_t))) {
228 _mm_storeu_si16(output, vy);
229 vy = _mm_srli_epi32(vy, 16);
230 output += 2;
231 }
232 if (batch & (1 * sizeof(uint8_t))) {
233 *output = (uint8_t) _mm_extract_epi8(vy, 0);
234 }
235 }
236 }