Debian Codegraph @

src/qs8-dwconv/gen/qs8-dwconv-5f5m5l8c8s8r-minmax-fp32-wasmsimd-mul16-add16.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_add16(
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
96 const v128_t vi1x01234567 = wasm_i16x8_load8x8(i1);
97 v128_t vk1x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 8 * sizeof(int32_t) + 8 * sizeof(int8_t)));
98 i1 += 8;
99
100 vprod01234567 = wasm_i16x8_add(vprod01234567, wasm_i16x8_mul(vi1x01234567, vk1x01234567));
101
102 vacc0123 = wasm_i32x4_add(vacc0123, wasm_i32x4_extend_low_i16x8(vprod01234567));
103 vacc4567 = wasm_i32x4_add(vacc4567, wasm_i32x4_extend_high_i16x8(vprod01234567));
104
105 const v128_t vi2x01234567 = wasm_i16x8_load8x8(i2);
106 v128_t vk2x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 8 * sizeof(int32_t) + 16 * sizeof(int8_t)));
107 i2 += 8;
108
109 vprod01234567 = wasm_i16x8_mul(vi2x01234567, vk2x01234567);
110
111
112 const v128_t vi3x01234567 = wasm_i16x8_load8x8(i3);
113 v128_t vk3x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 8 * sizeof(int32_t) + 24 * sizeof(int8_t)));
114 i3 += 8;
115
116 vprod01234567 = wasm_i16x8_add(vprod01234567, wasm_i16x8_mul(vi3x01234567, vk3x01234567));
117
118 vacc0123 = wasm_i32x4_add(vacc0123, wasm_i32x4_extend_low_i16x8(vprod01234567));
119 vacc4567 = wasm_i32x4_add(vacc4567, wasm_i32x4_extend_high_i16x8(vprod01234567));
120
121 const v128_t vi4x01234567 = wasm_i16x8_load8x8(i4);
122 v128_t vk4x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 8 * sizeof(int32_t) + 32 * sizeof(int8_t)));
123 i4 += 8;
124
125 vprod01234567 = wasm_i16x8_mul(vi4x01234567, vk4x01234567);
126
127 vacc0123 = wasm_i32x4_add(vacc0123, wasm_i32x4_extend_low_i16x8(vprod01234567));
128 vacc4567 = wasm_i32x4_add(vacc4567, wasm_i32x4_extend_high_i16x8(vprod01234567));
129
130 w = (const void*) ((uintptr_t) w + 8 * sizeof(int32_t) + 40 * sizeof(int8_t));
131
132 wasm_v128_store(b, vacc0123);
133 wasm_v128_store(b + 4, vacc4567);
134 b += 8;
135 }
136
137 assert(c == 0);
138 }
139
140
141 // Middle pass to process 5 inputs in each iteration.
142 for (size_t ks = kernel_size - 5; ks > 5; ks -= 5) {
143 int32_t* b = buffer;
144 const int8_t* i0 = input[0];
145 assert(i0 != NULL);
146 if XNN_UNPREDICTABLE(i0 != zero) {
147 i0 = (const int8_t*) ((uintptr_t) i0 + input_offset);
148 }
149 const int8_t* i1 = input[1];
150 assert(i1 != NULL);
151 if XNN_UNPREDICTABLE(i1 != zero) {
152 i1 = (const int8_t*) ((uintptr_t) i1 + input_offset);
153 }
154 const int8_t* i2 = input[2];
155 assert(i2 != NULL);
156 if XNN_UNPREDICTABLE(i2 != zero) {
157 i2 = (const int8_t*) ((uintptr_t) i2 + input_offset);
158 }
159 const int8_t* i3 = input[3];
160 assert(i3 != NULL);
161 if XNN_UNPREDICTABLE(i3 != zero) {
162 i3 = (const int8_t*) ((uintptr_t) i3 + input_offset);
163 }
164 const int8_t* i4 = input[4];
165 assert(i4 != NULL);
166 if XNN_UNPREDICTABLE(i4 != zero) {
167 i4 = (const int8_t*) ((uintptr_t) i4 + input_offset);
168 }
169 input += 5;
170
171 size_t c = round_up_po2(channels, 8);
172
173 for (; c >= 8; c -= 8) {
174 v128_t vacc0123 = wasm_v128_load(b);
175 v128_t vacc4567 = wasm_v128_load(b + 4);
176
177 const v128_t vi0x01234567 = wasm_i16x8_load8x8(i0);
178 v128_t vk0x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 0 * sizeof(int8_t)));
179 i0 += 8;
180
181 v128_t vprod01234567 = wasm_i16x8_mul(vi0x01234567, vk0x01234567);
182
183
184 const v128_t vi1x01234567 = wasm_i16x8_load8x8(i1);
185 v128_t vk1x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 8 * sizeof(int8_t)));
186 i1 += 8;
187
188 vprod01234567 = wasm_i16x8_add(vprod01234567, wasm_i16x8_mul(vi1x01234567, vk1x01234567));
189
190 vacc0123 = wasm_i32x4_add(vacc0123, wasm_i32x4_extend_low_i16x8(vprod01234567));
191 vacc4567 = wasm_i32x4_add(vacc4567, wasm_i32x4_extend_high_i16x8(vprod01234567));
192
193 const v128_t vi2x01234567 = wasm_i16x8_load8x8(i2);
194 v128_t vk2x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 16 * sizeof(int8_t)));
195 i2 += 8;
196
197 vprod01234567 = wasm_i16x8_mul(vi2x01234567, vk2x01234567);
198
199
200 const v128_t vi3x01234567 = wasm_i16x8_load8x8(i3);
201 v128_t vk3x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 24 * sizeof(int8_t)));
202 i3 += 8;
203
204 vprod01234567 = wasm_i16x8_add(vprod01234567, wasm_i16x8_mul(vi3x01234567, vk3x01234567));
205
206 vacc0123 = wasm_i32x4_add(vacc0123, wasm_i32x4_extend_low_i16x8(vprod01234567));
207 vacc4567 = wasm_i32x4_add(vacc4567, wasm_i32x4_extend_high_i16x8(vprod01234567));
208
209 const v128_t vi4x01234567 = wasm_i16x8_load8x8(i4);
210 v128_t vk4x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 32 * sizeof(int8_t)));
211 i4 += 8;
212
213 vprod01234567 = wasm_i16x8_mul(vi4x01234567, vk4x01234567);
214
215 vacc0123 = wasm_i32x4_add(vacc0123, wasm_i32x4_extend_low_i16x8(vprod01234567));
216 vacc4567 = wasm_i32x4_add(vacc4567, wasm_i32x4_extend_high_i16x8(vprod01234567));
217
218 w = (const void*) ((uintptr_t) w + 40 * sizeof(int8_t));
219
220 wasm_v128_store(b, vacc0123);
221 wasm_v128_store(b + 4, vacc4567);
222 b += 8;
223 }
224
225 assert(c == 0);
226 }
227
228 // Last pass to process up to 5 inputs.
229 {
230 const int32_t* b = buffer;
231 const int8_t* i0 = input[0];
232 assert(i0 != NULL);
233 if XNN_UNPREDICTABLE(i0 != zero) {
234 i0 = (const int8_t*) ((uintptr_t) i0 + input_offset);
235 }
236 const int8_t* i1 = input[1];
237 assert(i1 != NULL);
238 if XNN_UNPREDICTABLE(i1 != zero) {
239 i1 = (const int8_t*) ((uintptr_t) i1 + input_offset);
240 }
241 const int8_t* i2 = input[2];
242 assert(i2 != NULL);
243 if XNN_UNPREDICTABLE(i2 != zero) {
244 i2 = (const int8_t*) ((uintptr_t) i2 + input_offset);
245 }
246 const int8_t* i3 = input[3];
247 assert(i3 != NULL);
248 if XNN_UNPREDICTABLE(i3 != zero) {
249 i3 = (const int8_t*) ((uintptr_t) i3 + input_offset);
250 }
251 const int8_t* i4 = input[4];
252 assert(i4 != NULL);
253 if XNN_UNPREDICTABLE(i4 != zero) {
254 i4 = (const int8_t*) ((uintptr_t) i4 + input_offset);
255 }
256
257 size_t c = channels;
258
259 for (; c >= 8; c -= 8) {
260 v128_t vacc0123 = wasm_v128_load(b);
261 v128_t vacc4567 = wasm_v128_load(b + 4);
262 b += 8;
263
264 const v128_t vi0x01234567 = wasm_i16x8_load8x8(i0);
265 v128_t vk0x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 0 * sizeof(int8_t)));
266 i0 += 8;
267
268 v128_t vprod01234567 = wasm_i16x8_mul(vi0x01234567, vk0x01234567);
269
270
271 const v128_t vi1x01234567 = wasm_i16x8_load8x8(i1);
272 v128_t vk1x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 8 * sizeof(int8_t)));
273 i1 += 8;
274
275 vprod01234567 = wasm_i16x8_add(vprod01234567, wasm_i16x8_mul(vi1x01234567, vk1x01234567));
276
277 vacc0123 = wasm_i32x4_add(vacc0123, wasm_i32x4_extend_low_i16x8(vprod01234567));
278 vacc4567 = wasm_i32x4_add(vacc4567, wasm_i32x4_extend_high_i16x8(vprod01234567));
279
280 const v128_t vi2x01234567 = wasm_i16x8_load8x8(i2);
281 v128_t vk2x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 16 * sizeof(int8_t)));
282 i2 += 8;
283
284 vprod01234567 = wasm_i16x8_mul(vi2x01234567, vk2x01234567);
285
286
287 const v128_t vi3x01234567 = wasm_i16x8_load8x8(i3);
288 v128_t vk3x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 24 * sizeof(int8_t)));
289 i3 += 8;
290
291 vprod01234567 = wasm_i16x8_add(vprod01234567, wasm_i16x8_mul(vi3x01234567, vk3x01234567));
292
293 vacc0123 = wasm_i32x4_add(vacc0123, wasm_i32x4_extend_low_i16x8(vprod01234567));
294 vacc4567 = wasm_i32x4_add(vacc4567, wasm_i32x4_extend_high_i16x8(vprod01234567));
295
296 const v128_t vi4x01234567 = wasm_i16x8_load8x8(i4);
297 v128_t vk4x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 32 * sizeof(int8_t)));
298 i4 += 8;
299
300 vprod01234567 = wasm_i16x8_mul(vi4x01234567, vk4x01234567);
301
302 vacc0123 = wasm_i32x4_add(vacc0123, wasm_i32x4_extend_low_i16x8(vprod01234567));
303 vacc4567 = wasm_i32x4_add(vacc4567, wasm_i32x4_extend_high_i16x8(vprod01234567));
304
305
306 w = (const void*) ((uintptr_t) w + 40 * sizeof(int8_t));
307
308 vacc0123 = wasm_f32x4_convert_i32x4(vacc0123);
309 vacc4567 = wasm_f32x4_convert_i32x4(vacc4567);
310
311 vacc0123 = wasm_f32x4_mul(vacc0123, vscale);
312 vacc4567 = wasm_f32x4_mul(vacc4567, vscale);
313
314 vacc0123 = wasm_f32x4_add(vacc0123, vmagic_bias);
315 vacc4567 = wasm_f32x4_add(vacc4567, vmagic_bias);
316
317 vacc0123 = wasm_i32x4_max(vacc0123, vmagic_min);
318 vacc4567 = wasm_i32x4_max(vacc4567, vmagic_min);
319
320 vacc0123 = wasm_i32x4_sub(vacc0123, vmagic_bias_less_output_zero_point);
321 vacc4567 = wasm_i32x4_sub(vacc4567, vmagic_bias_less_output_zero_point);
322
323 v128_t vout01234567 = wasm_i16x8_narrow_i32x4(vacc0123, vacc4567);
324
325 v128_t vout0123456701234567 = wasm_i8x16_narrow_i16x8(vout01234567, vout01234567);
326
327 vout0123456701234567 = wasm_i8x16_min(vout0123456701234567, voutput_max);
328
329 wasm_v128_store64_lane(output, vout0123456701234567, 0);
330 output += 8;
331 }
332
333 if XNN_UNLIKELY(c != 0) {
334 {
335 v128_t vacc0123 = wasm_v128_load(b);
336 v128_t vacc4567 = wasm_v128_load(b + 4);
337
338 const v128_t vi0x01234567 = wasm_i16x8_load8x8(i0);
339 v128_t vk0x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w));
340
341 v128_t vprod01234567 = wasm_i16x8_mul(vi0x01234567, vk0x01234567);
342
343
344 const v128_t vi1x01234567 = wasm_i16x8_load8x8(i1);
345 v128_t vk1x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 8 * sizeof(int8_t)));
346
347 vprod01234567 = wasm_i16x8_add(vprod01234567, wasm_i16x8_mul(vi1x01234567, vk1x01234567));
348
349 vacc0123 = wasm_i32x4_add(vacc0123, wasm_i32x4_extend_low_i16x8(vprod01234567));
350 vacc4567 = wasm_i32x4_add(vacc4567, wasm_i32x4_extend_high_i16x8(vprod01234567));
351
352 const v128_t vi2x01234567 = wasm_i16x8_load8x8(i2);
353 v128_t vk2x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 16 * sizeof(int8_t)));
354
355 vprod01234567 = wasm_i16x8_mul(vi2x01234567, vk2x01234567);
356
357
358 const v128_t vi3x01234567 = wasm_i16x8_load8x8(i3);
359 v128_t vk3x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 24 * sizeof(int8_t)));
360
361 vprod01234567 = wasm_i16x8_add(vprod01234567, wasm_i16x8_mul(vi3x01234567, vk3x01234567));
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 vi4x01234567 = wasm_i16x8_load8x8(i4);
367 v128_t vk4x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 32 * sizeof(int8_t)));
368
369 vprod01234567 = wasm_i16x8_mul(vi4x01234567, vk4x01234567);
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
375 vacc0123 = wasm_f32x4_convert_i32x4(vacc0123);
376 vacc4567 = wasm_f32x4_convert_i32x4(vacc4567);
377
378 vacc0123 = wasm_f32x4_mul(vacc0123, vscale);
379 vacc4567 = wasm_f32x4_mul(vacc4567, vscale);
380
381
382 vacc0123 = wasm_f32x4_add(vacc0123, vmagic_bias);
383 vacc4567 = wasm_f32x4_add(vacc4567, vmagic_bias);
384
385 vacc0123 = wasm_i32x4_max(vacc0123, vmagic_min);
386 vacc4567 = wasm_i32x4_max(vacc4567, vmagic_min);
387
388 vacc0123 = wasm_i32x4_sub(vacc0123, vmagic_bias_less_output_zero_point);
389 vacc4567 = wasm_i32x4_sub(vacc4567, vmagic_bias_less_output_zero_point);
390
391 v128_t vout01234567 = wasm_i16x8_narrow_i32x4(vacc0123, vacc4567);
392 v128_t vout0123456701234567 = wasm_i8x16_narrow_i16x8(vout01234567, vout01234567);
393
394 vout0123456701234567 = wasm_i8x16_min(vout0123456701234567, voutput_max);
395
396 if (c & 4) {
397 wasm_v128_store32_lane(output, vout0123456701234567, 0);
398 vout0123456701234567 = wasm_u64x2_shr(vout0123456701234567, 32);
399 output += 4;
400 }
401 if (c & 2) {
402 wasm_v128_store16_lane(output, vout0123456701234567, 0);
403 vout0123456701234567 = wasm_u32x4_shr(vout0123456701234567, 16);
404 output += 2;
405 }
406 if (c & 1) {
407 wasm_v128_store8_lane(output, vout0123456701234567, 0);
408 output += 1;
409 }
410 }
411 }
412 }
413
414 input = (const int8_t**) ((uintptr_t) input + input_stride);
415 output = (int8_t*) ((uintptr_t) output + output_increment);
416 } while (--output_width != 0);
417 }