Debian Codegraph @

src/qs8-dwconv/gen/qs8-dwconv-5f5m5l8c8s8r-minmax-fp32-wasmsimd-mul16.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-dwconv/multipass-wasmsimd-mul16.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2023 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 <wasm_simd128.h>
13
14 #include "xnnpack/dwconv.h"
15 #include "xnnpack/math.h"
16
17
18 void xnn_qs8_dwconv_minmax_fp32_ukernel_5f5m5l8c8s8r__wasmsimd_mul16(
19 size_t channels,
20 size_t output_width,
21 const int8_t** input,
22 const void* weights,
23 int8_t* output,
24 intptr_t input_stride,
25 size_t output_increment,
26 size_t input_offset,
27 const int8_t* zero,
28 size_t kernel_size,
29 int32_t* buffer,
30 const union xnn_qs8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
31 {
32 assert(channels != 0);
33 assert(output_width != 0);
34 assert(kernel_size > 5);
35
36
37 const v128_t vscale = wasm_v128_load32_splat(&params->fp32_scalar.scale);
38 XNN_FORCE_REALIZATION(vscale);
39
40 const v128_t vmagic_bias = wasm_f32x4_const_splat(12582912.0f);
41 const int32_t output_min_less_zero_point = (int32_t) params->fp32_scalar.output_min - (int32_t) params->fp32_scalar.output_zero_point;
42 const v128_t vmagic_min = wasm_i32x4_splat((int32_t) float_as_uint32(12582912.0f + output_min_less_zero_point));
43 const v128_t vmagic_bias_less_output_zero_point = wasm_i32x4_splat(INT32_C(0x4B400000) - (int32_t) params->fp32_scalar.output_zero_point);
44 const v128_t voutput_max = wasm_i8x16_splat(params->fp32_scalar.output_max);
45 XNN_FORCE_REALIZATION(vmagic_bias);
46 XNN_FORCE_REALIZATION(vmagic_min);
47 XNN_FORCE_REALIZATION(vmagic_bias_less_output_zero_point);
48 XNN_FORCE_REALIZATION(voutput_max);
49
50 do {
51 const void* w = weights;
52
53 // First pass to process 5 inputs.
54 {
55 int32_t* b = buffer;
56 const int8_t* i0 = input[0];
57 assert(i0 != NULL);
58 if XNN_UNPREDICTABLE(i0 != zero) {
59 i0 = (const int8_t*) ((uintptr_t) i0 + input_offset);
60 }
61 const int8_t* i1 = input[1];
62 assert(i1 != NULL);
63 if XNN_UNPREDICTABLE(i1 != zero) {
64 i1 = (const int8_t*) ((uintptr_t) i1 + input_offset);
65 }
66 const int8_t* i2 = input[2];
67 assert(i2 != NULL);
68 if XNN_UNPREDICTABLE(i2 != zero) {
69 i2 = (const int8_t*) ((uintptr_t) i2 + input_offset);
70 }
71 const int8_t* i3 = input[3];
72 assert(i3 != NULL);
73 if XNN_UNPREDICTABLE(i3 != zero) {
74 i3 = (const int8_t*) ((uintptr_t) i3 + input_offset);
75 }
76 const int8_t* i4 = input[4];
77 assert(i4 != NULL);
78 if XNN_UNPREDICTABLE(i4 != zero) {
79 i4 = (const int8_t*) ((uintptr_t) i4 + input_offset);
80 }
81 input += 5;
82
83 size_t c = round_up_po2(channels, 8);
84
85 for (; c >= 8; c -= 8) {
86 v128_t vacc0123 = wasm_v128_load(w);
87 v128_t vacc4567 = wasm_v128_load((const void*) ((uintptr_t) w + 4 * sizeof(int32_t)));
88
89 const v128_t vi0x01234567 = wasm_i16x8_load8x8(i0);
90 v128_t vk0x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 8 * sizeof(int32_t) + 0 * sizeof(int8_t)));
91 i0 += 8;
92
93 v128_t vprod01234567 = wasm_i16x8_mul(vi0x01234567, vk0x01234567);
94
95 vacc0123 = wasm_i32x4_add(vacc0123, wasm_i32x4_extend_low_i16x8(vprod01234567));
96 vacc4567 = wasm_i32x4_add(vacc4567, wasm_i32x4_extend_high_i16x8(vprod01234567));
97
98 const v128_t vi1x01234567 = wasm_i16x8_load8x8(i1);
99 v128_t vk1x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 8 * sizeof(int32_t) + 8 * sizeof(int8_t)));
100 i1 += 8;
101
102 vprod01234567 = wasm_i16x8_mul(vi1x01234567, vk1x01234567);
103
104 vacc0123 = wasm_i32x4_add(vacc0123, wasm_i32x4_extend_low_i16x8(vprod01234567));
105 vacc4567 = wasm_i32x4_add(vacc4567, wasm_i32x4_extend_high_i16x8(vprod01234567));
106
107 const v128_t vi2x01234567 = wasm_i16x8_load8x8(i2);
108 v128_t vk2x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 8 * sizeof(int32_t) + 16 * sizeof(int8_t)));
109 i2 += 8;
110
111 vprod01234567 = wasm_i16x8_mul(vi2x01234567, vk2x01234567);
112
113 vacc0123 = wasm_i32x4_add(vacc0123, wasm_i32x4_extend_low_i16x8(vprod01234567));
114 vacc4567 = wasm_i32x4_add(vacc4567, wasm_i32x4_extend_high_i16x8(vprod01234567));
115
116 const v128_t vi3x01234567 = wasm_i16x8_load8x8(i3);
117 v128_t vk3x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 8 * sizeof(int32_t) + 24 * sizeof(int8_t)));
118 i3 += 8;
119
120 vprod01234567 = wasm_i16x8_mul(vi3x01234567, vk3x01234567);
121
122 vacc0123 = wasm_i32x4_add(vacc0123, wasm_i32x4_extend_low_i16x8(vprod01234567));
123 vacc4567 = wasm_i32x4_add(vacc4567, wasm_i32x4_extend_high_i16x8(vprod01234567));
124
125 const v128_t vi4x01234567 = wasm_i16x8_load8x8(i4);
126 v128_t vk4x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 8 * sizeof(int32_t) + 32 * sizeof(int8_t)));
127 i4 += 8;
128
129 vprod01234567 = wasm_i16x8_mul(vi4x01234567, vk4x01234567);
130
131 vacc0123 = wasm_i32x4_add(vacc0123, wasm_i32x4_extend_low_i16x8(vprod01234567));
132 vacc4567 = wasm_i32x4_add(vacc4567, wasm_i32x4_extend_high_i16x8(vprod01234567));
133
134 w = (const void*) ((uintptr_t) w + 8 * sizeof(int32_t) + 40 * sizeof(int8_t));
135
136 wasm_v128_store(b, vacc0123);
137 wasm_v128_store(b + 4, vacc4567);
138 b += 8;
139 }
140
141 assert(c == 0);
142 }
143
144
145 // Middle pass to process 5 inputs in each iteration.
146 for (size_t ks = kernel_size - 5; ks > 5; ks -= 5) {
147 int32_t* b = buffer;
148 const int8_t* i0 = input[0];
149 assert(i0 != NULL);
150 if XNN_UNPREDICTABLE(i0 != zero) {
151 i0 = (const int8_t*) ((uintptr_t) i0 + input_offset);
152 }
153 const int8_t* i1 = input[1];
154 assert(i1 != NULL);
155 if XNN_UNPREDICTABLE(i1 != zero) {
156 i1 = (const int8_t*) ((uintptr_t) i1 + input_offset);
157 }
158 const int8_t* i2 = input[2];
159 assert(i2 != NULL);
160 if XNN_UNPREDICTABLE(i2 != zero) {
161 i2 = (const int8_t*) ((uintptr_t) i2 + input_offset);
162 }
163 const int8_t* i3 = input[3];
164 assert(i3 != NULL);
165 if XNN_UNPREDICTABLE(i3 != zero) {
166 i3 = (const int8_t*) ((uintptr_t) i3 + input_offset);
167 }
168 const int8_t* i4 = input[4];
169 assert(i4 != NULL);
170 if XNN_UNPREDICTABLE(i4 != zero) {
171 i4 = (const int8_t*) ((uintptr_t) i4 + input_offset);
172 }
173 input += 5;
174
175 size_t c = round_up_po2(channels, 8);
176
177 for (; c >= 8; c -= 8) {
178 v128_t vacc0123 = wasm_v128_load(b);
179 v128_t vacc4567 = wasm_v128_load(b + 4);
180
181 const v128_t vi0x01234567 = wasm_i16x8_load8x8(i0);
182 v128_t vk0x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 0 * sizeof(int8_t)));
183 i0 += 8;
184
185 v128_t vprod01234567 = wasm_i16x8_mul(vi0x01234567, vk0x01234567);
186
187 vacc0123 = wasm_i32x4_add(vacc0123, wasm_i32x4_extend_low_i16x8(vprod01234567));
188 vacc4567 = wasm_i32x4_add(vacc4567, wasm_i32x4_extend_high_i16x8(vprod01234567));
189
190 const v128_t vi1x01234567 = wasm_i16x8_load8x8(i1);
191 v128_t vk1x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 8 * sizeof(int8_t)));
192 i1 += 8;
193
194 vprod01234567 = wasm_i16x8_mul(vi1x01234567, vk1x01234567);
195
196 vacc0123 = wasm_i32x4_add(vacc0123, wasm_i32x4_extend_low_i16x8(vprod01234567));
197 vacc4567 = wasm_i32x4_add(vacc4567, wasm_i32x4_extend_high_i16x8(vprod01234567));
198
199 const v128_t vi2x01234567 = wasm_i16x8_load8x8(i2);
200 v128_t vk2x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 16 * sizeof(int8_t)));
201 i2 += 8;
202
203 vprod01234567 = wasm_i16x8_mul(vi2x01234567, vk2x01234567);
204
205 vacc0123 = wasm_i32x4_add(vacc0123, wasm_i32x4_extend_low_i16x8(vprod01234567));
206 vacc4567 = wasm_i32x4_add(vacc4567, wasm_i32x4_extend_high_i16x8(vprod01234567));
207
208 const v128_t vi3x01234567 = wasm_i16x8_load8x8(i3);
209 v128_t vk3x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 24 * sizeof(int8_t)));
210 i3 += 8;
211
212 vprod01234567 = wasm_i16x8_mul(vi3x01234567, vk3x01234567);
213
214 vacc0123 = wasm_i32x4_add(vacc0123, wasm_i32x4_extend_low_i16x8(vprod01234567));
215 vacc4567 = wasm_i32x4_add(vacc4567, wasm_i32x4_extend_high_i16x8(vprod01234567));
216
217 const v128_t vi4x01234567 = wasm_i16x8_load8x8(i4);
218 v128_t vk4x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 32 * sizeof(int8_t)));
219 i4 += 8;
220
221 vprod01234567 = wasm_i16x8_mul(vi4x01234567, vk4x01234567);
222
223 vacc0123 = wasm_i32x4_add(vacc0123, wasm_i32x4_extend_low_i16x8(vprod01234567));
224 vacc4567 = wasm_i32x4_add(vacc4567, wasm_i32x4_extend_high_i16x8(vprod01234567));
225
226 w = (const void*) ((uintptr_t) w + 40 * sizeof(int8_t));
227
228 wasm_v128_store(b, vacc0123);
229 wasm_v128_store(b + 4, vacc4567);
230 b += 8;
231 }
232
233 assert(c == 0);
234 }
235
236 // Last pass to process up to 5 inputs.
237 {
238 const int32_t* b = buffer;
239 const int8_t* i0 = input[0];
240 assert(i0 != NULL);
241 if XNN_UNPREDICTABLE(i0 != zero) {
242 i0 = (const int8_t*) ((uintptr_t) i0 + input_offset);
243 }
244 const int8_t* i1 = input[1];
245 assert(i1 != NULL);
246 if XNN_UNPREDICTABLE(i1 != zero) {
247 i1 = (const int8_t*) ((uintptr_t) i1 + input_offset);
248 }
249 const int8_t* i2 = input[2];
250 assert(i2 != NULL);
251 if XNN_UNPREDICTABLE(i2 != zero) {
252 i2 = (const int8_t*) ((uintptr_t) i2 + input_offset);
253 }
254 const int8_t* i3 = input[3];
255 assert(i3 != NULL);
256 if XNN_UNPREDICTABLE(i3 != zero) {
257 i3 = (const int8_t*) ((uintptr_t) i3 + input_offset);
258 }
259 const int8_t* i4 = input[4];
260 assert(i4 != NULL);
261 if XNN_UNPREDICTABLE(i4 != zero) {
262 i4 = (const int8_t*) ((uintptr_t) i4 + input_offset);
263 }
264
265 size_t c = channels;
266
267 for (; c >= 8; c -= 8) {
268 v128_t vacc0123 = wasm_v128_load(b);
269 v128_t vacc4567 = wasm_v128_load(b + 4);
270 b += 8;
271
272 const v128_t vi0x01234567 = wasm_i16x8_load8x8(i0);
273 v128_t vk0x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 0 * sizeof(int8_t)));
274 i0 += 8;
275
276 v128_t vprod01234567 = wasm_i16x8_mul(vi0x01234567, vk0x01234567);
277
278 vacc0123 = wasm_i32x4_add(vacc0123, wasm_i32x4_extend_low_i16x8(vprod01234567));
279 vacc4567 = wasm_i32x4_add(vacc4567, wasm_i32x4_extend_high_i16x8(vprod01234567));
280
281 const v128_t vi1x01234567 = wasm_i16x8_load8x8(i1);
282 v128_t vk1x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 8 * sizeof(int8_t)));
283 i1 += 8;
284
285 vprod01234567 = wasm_i16x8_mul(vi1x01234567, vk1x01234567);
286
287 vacc0123 = wasm_i32x4_add(vacc0123, wasm_i32x4_extend_low_i16x8(vprod01234567));
288 vacc4567 = wasm_i32x4_add(vacc4567, wasm_i32x4_extend_high_i16x8(vprod01234567));
289
290 const v128_t vi2x01234567 = wasm_i16x8_load8x8(i2);
291 v128_t vk2x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 16 * sizeof(int8_t)));
292 i2 += 8;
293
294 vprod01234567 = wasm_i16x8_mul(vi2x01234567, vk2x01234567);
295
296 vacc0123 = wasm_i32x4_add(vacc0123, wasm_i32x4_extend_low_i16x8(vprod01234567));
297 vacc4567 = wasm_i32x4_add(vacc4567, wasm_i32x4_extend_high_i16x8(vprod01234567));
298
299 const v128_t vi3x01234567 = wasm_i16x8_load8x8(i3);
300 v128_t vk3x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 24 * sizeof(int8_t)));
301 i3 += 8;
302
303 vprod01234567 = wasm_i16x8_mul(vi3x01234567, vk3x01234567);
304
305 vacc0123 = wasm_i32x4_add(vacc0123, wasm_i32x4_extend_low_i16x8(vprod01234567));
306 vacc4567 = wasm_i32x4_add(vacc4567, wasm_i32x4_extend_high_i16x8(vprod01234567));
307
308 const v128_t vi4x01234567 = wasm_i16x8_load8x8(i4);
309 v128_t vk4x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 32 * sizeof(int8_t)));
310 i4 += 8;
311
312 vprod01234567 = wasm_i16x8_mul(vi4x01234567, vk4x01234567);
313
314 vacc0123 = wasm_i32x4_add(vacc0123, wasm_i32x4_extend_low_i16x8(vprod01234567));
315 vacc4567 = wasm_i32x4_add(vacc4567, wasm_i32x4_extend_high_i16x8(vprod01234567));
316
317
318 w = (const void*) ((uintptr_t) w + 40 * sizeof(int8_t));
319
320 vacc0123 = wasm_f32x4_convert_i32x4(vacc0123);
321 vacc4567 = wasm_f32x4_convert_i32x4(vacc4567);
322
323 vacc0123 = wasm_f32x4_mul(vacc0123, vscale);
324 vacc4567 = wasm_f32x4_mul(vacc4567, vscale);
325
326 vacc0123 = wasm_f32x4_add(vacc0123, vmagic_bias);
327 vacc4567 = wasm_f32x4_add(vacc4567, vmagic_bias);
328
329 vacc0123 = wasm_i32x4_max(vacc0123, vmagic_min);
330 vacc4567 = wasm_i32x4_max(vacc4567, vmagic_min);
331
332 vacc0123 = wasm_i32x4_sub(vacc0123, vmagic_bias_less_output_zero_point);
333 vacc4567 = wasm_i32x4_sub(vacc4567, vmagic_bias_less_output_zero_point);
334
335 v128_t vout01234567 = wasm_i16x8_narrow_i32x4(vacc0123, vacc4567);
336
337 v128_t vout0123456701234567 = wasm_i8x16_narrow_i16x8(vout01234567, vout01234567);
338
339 vout0123456701234567 = wasm_i8x16_min(vout0123456701234567, voutput_max);
340
341 wasm_v128_store64_lane(output, vout0123456701234567, 0);
342 output += 8;
343 }
344
345 if XNN_UNLIKELY(c != 0) {
346 {
347 v128_t vacc0123 = wasm_v128_load(b);
348 v128_t vacc4567 = wasm_v128_load(b + 4);
349
350 const v128_t vi0x01234567 = wasm_i16x8_load8x8(i0);
351 v128_t vk0x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w));
352
353 v128_t vprod01234567 = wasm_i16x8_mul(vi0x01234567, vk0x01234567);
354
355 vacc0123 = wasm_i32x4_add(vacc0123, wasm_i32x4_extend_low_i16x8(vprod01234567));
356 vacc4567 = wasm_i32x4_add(vacc4567, wasm_i32x4_extend_high_i16x8(vprod01234567));
357
358 const v128_t vi1x01234567 = wasm_i16x8_load8x8(i1);
359 v128_t vk1x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 8 * sizeof(int8_t)));
360
361 vprod01234567 = wasm_i16x8_mul(vi1x01234567, vk1x01234567);
362
363 vacc0123 = wasm_i32x4_add(vacc0123, wasm_i32x4_extend_low_i16x8(vprod01234567));
364 vacc4567 = wasm_i32x4_add(vacc4567, wasm_i32x4_extend_high_i16x8(vprod01234567));
365
366 const v128_t vi2x01234567 = wasm_i16x8_load8x8(i2);
367 v128_t vk2x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 16 * sizeof(int8_t)));
368
369 vprod01234567 = wasm_i16x8_mul(vi2x01234567, vk2x01234567);
370
371 vacc0123 = wasm_i32x4_add(vacc0123, wasm_i32x4_extend_low_i16x8(vprod01234567));
372 vacc4567 = wasm_i32x4_add(vacc4567, wasm_i32x4_extend_high_i16x8(vprod01234567));
373
374 const v128_t vi3x01234567 = wasm_i16x8_load8x8(i3);
375 v128_t vk3x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 24 * sizeof(int8_t)));
376
377 vprod01234567 = wasm_i16x8_mul(vi3x01234567, vk3x01234567);
378
379 vacc0123 = wasm_i32x4_add(vacc0123, wasm_i32x4_extend_low_i16x8(vprod01234567));
380 vacc4567 = wasm_i32x4_add(vacc4567, wasm_i32x4_extend_high_i16x8(vprod01234567));
381
382 const v128_t vi4x01234567 = wasm_i16x8_load8x8(i4);
383 v128_t vk4x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 32 * sizeof(int8_t)));
384
385 vprod01234567 = wasm_i16x8_mul(vi4x01234567, vk4x01234567);
386
387 vacc0123 = wasm_i32x4_add(vacc0123, wasm_i32x4_extend_low_i16x8(vprod01234567));
388 vacc4567 = wasm_i32x4_add(vacc4567, wasm_i32x4_extend_high_i16x8(vprod01234567));
389
390
391 vacc0123 = wasm_f32x4_convert_i32x4(vacc0123);
392 vacc4567 = wasm_f32x4_convert_i32x4(vacc4567);
393
394 vacc0123 = wasm_f32x4_mul(vacc0123, vscale);
395 vacc4567 = wasm_f32x4_mul(vacc4567, vscale);
396
397
398 vacc0123 = wasm_f32x4_add(vacc0123, vmagic_bias);
399 vacc4567 = wasm_f32x4_add(vacc4567, vmagic_bias);
400
401 vacc0123 = wasm_i32x4_max(vacc0123, vmagic_min);
402 vacc4567 = wasm_i32x4_max(vacc4567, vmagic_min);
403
404 vacc0123 = wasm_i32x4_sub(vacc0123, vmagic_bias_less_output_zero_point);
405 vacc4567 = wasm_i32x4_sub(vacc4567, vmagic_bias_less_output_zero_point);
406
407 v128_t vout01234567 = wasm_i16x8_narrow_i32x4(vacc0123, vacc4567);
408 v128_t vout0123456701234567 = wasm_i8x16_narrow_i16x8(vout01234567, vout01234567);
409
410 vout0123456701234567 = wasm_i8x16_min(vout0123456701234567, voutput_max);
411
412 if (c & 4) {
413 wasm_v128_store32_lane(output, vout0123456701234567, 0);
414 vout0123456701234567 = wasm_u64x2_shr(vout0123456701234567, 32);
415 output += 4;
416 }
417 if (c & 2) {
418 wasm_v128_store16_lane(output, vout0123456701234567, 0);
419 vout0123456701234567 = wasm_u32x4_shr(vout0123456701234567, 16);
420 output += 2;
421 }
422 if (c & 1) {
423 wasm_v128_store8_lane(output, vout0123456701234567, 0);
424 output += 1;
425 }
426 }
427 }
428 }
429
430 input = (const int8_t**) ((uintptr_t) input + input_stride);
431 output = (int8_t*) ((uintptr_t) output + output_increment);
432 } while (--output_width != 0);
433 }