Debian Codegraph @

src/qs8-dwconv/gen/qs8-dwconv-9p8c-minmax-fp32-wasmsimd-mul16.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-dwconv/unipass-wasmsimd-mul16.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2020 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_9p8c__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 const union xnn_qs8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
29 {
30 assert(channels != 0);
31 assert(output_width != 0);
32
33
34 const v128_t vscale = wasm_v128_load32_splat(&params->fp32_scalar.scale);
35 XNN_FORCE_REALIZATION(vscale);
36 const v128_t vmagic_bias = wasm_f32x4_const_splat(12582912.0f);
37 const int32_t output_min_less_zero_point = (int32_t) params->fp32_scalar.output_min - (int32_t) params->fp32_scalar.output_zero_point;
38 const v128_t vmagic_min = wasm_i32x4_splat((int32_t) float_as_uint32(12582912.0f + output_min_less_zero_point));
39 const v128_t vmagic_bias_less_output_zero_point = wasm_i32x4_splat(INT32_C(0x4B400000) - (int32_t) params->fp32_scalar.output_zero_point);
40 const v128_t voutput_max = wasm_i8x16_splat(params->fp32_scalar.output_max);
41 XNN_FORCE_REALIZATION(vmagic_bias);
42 XNN_FORCE_REALIZATION(vmagic_min);
43 XNN_FORCE_REALIZATION(vmagic_bias_less_output_zero_point);
44 XNN_FORCE_REALIZATION(voutput_max);
45
46 do {
47 const int8_t* i0 = input[0];
48 assert(i0 != NULL);
49 if XNN_UNPREDICTABLE(i0 != zero) {
50 i0 = (const int8_t*) ((uintptr_t) i0 + input_offset);
51 }
52 const int8_t* i1 = input[1];
53 assert(i1 != NULL);
54 if XNN_UNPREDICTABLE(i1 != zero) {
55 i1 = (const int8_t*) ((uintptr_t) i1 + input_offset);
56 }
57 const int8_t* i2 = input[2];
58 assert(i2 != NULL);
59 if XNN_UNPREDICTABLE(i2 != zero) {
60 i2 = (const int8_t*) ((uintptr_t) i2 + input_offset);
61 }
62 const int8_t* i3 = input[3];
63 assert(i3 != NULL);
64 if XNN_UNPREDICTABLE(i3 != zero) {
65 i3 = (const int8_t*) ((uintptr_t) i3 + input_offset);
66 }
67 const int8_t* i4 = input[4];
68 assert(i4 != NULL);
69 if XNN_UNPREDICTABLE(i4 != zero) {
70 i4 = (const int8_t*) ((uintptr_t) i4 + input_offset);
71 }
72 const int8_t* i5 = input[5];
73 assert(i5 != NULL);
74 if XNN_UNPREDICTABLE(i5 != zero) {
75 i5 = (const int8_t*) ((uintptr_t) i5 + input_offset);
76 }
77 const int8_t* i6 = input[6];
78 assert(i6 != NULL);
79 if XNN_UNPREDICTABLE(i6 != zero) {
80 i6 = (const int8_t*) ((uintptr_t) i6 + input_offset);
81 }
82 const int8_t* i7 = input[7];
83 assert(i7 != NULL);
84 if XNN_UNPREDICTABLE(i7 != zero) {
85 i7 = (const int8_t*) ((uintptr_t) i7 + input_offset);
86 }
87 const int8_t* i8 = input[8];
88 assert(i8 != NULL);
89 if XNN_UNPREDICTABLE(i8 != zero) {
90 i8 = (const int8_t*) ((uintptr_t) i8 + input_offset);
91 }
92 input = (const int8_t**) ((uintptr_t) input + input_stride);
93
94 size_t c = channels;
95 const void* w = weights;
96 for (; c >= 8; c -= 8) {
97 v128_t vacc0123 = wasm_v128_load(w);
98 v128_t vacc4567 = wasm_v128_load((const void*) ((uintptr_t) w + 4 * sizeof(int32_t)));
99
100
101 const v128_t vi0x01234567 = wasm_i16x8_load8x8(i0);
102 const v128_t vk0x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 8 * sizeof(int32_t) + 0 * sizeof(int8_t)));
103 i0 += 8;
104
105 v128_t vprod01234567 = wasm_i16x8_mul(vi0x01234567, vk0x01234567);
106
107 vacc0123 = wasm_i32x4_add(vacc0123, wasm_i32x4_extend_low_i16x8(vprod01234567));
108 vacc4567 = wasm_i32x4_add(vacc4567, wasm_i32x4_extend_high_i16x8(vprod01234567));
109
110 const v128_t vi1x01234567 = wasm_i16x8_load8x8(i1);
111 const v128_t vk1x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 8 * sizeof(int32_t) + 8 * sizeof(int8_t)));
112 i1 += 8;
113
114 vprod01234567 = wasm_i16x8_mul(vi1x01234567, vk1x01234567);
115
116 vacc0123 = wasm_i32x4_add(vacc0123, wasm_i32x4_extend_low_i16x8(vprod01234567));
117 vacc4567 = wasm_i32x4_add(vacc4567, wasm_i32x4_extend_high_i16x8(vprod01234567));
118
119 const v128_t vi2x01234567 = wasm_i16x8_load8x8(i2);
120 const v128_t vk2x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 8 * sizeof(int32_t) + 16 * sizeof(int8_t)));
121 i2 += 8;
122
123 vprod01234567 = wasm_i16x8_mul(vi2x01234567, vk2x01234567);
124
125 vacc0123 = wasm_i32x4_add(vacc0123, wasm_i32x4_extend_low_i16x8(vprod01234567));
126 vacc4567 = wasm_i32x4_add(vacc4567, wasm_i32x4_extend_high_i16x8(vprod01234567));
127
128 const v128_t vi3x01234567 = wasm_i16x8_load8x8(i3);
129 const v128_t vk3x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 8 * sizeof(int32_t) + 24 * sizeof(int8_t)));
130 i3 += 8;
131
132 vprod01234567 = wasm_i16x8_mul(vi3x01234567, vk3x01234567);
133
134 vacc0123 = wasm_i32x4_add(vacc0123, wasm_i32x4_extend_low_i16x8(vprod01234567));
135 vacc4567 = wasm_i32x4_add(vacc4567, wasm_i32x4_extend_high_i16x8(vprod01234567));
136
137 const v128_t vi4x01234567 = wasm_i16x8_load8x8(i4);
138 const v128_t vk4x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 8 * sizeof(int32_t) + 32 * sizeof(int8_t)));
139 i4 += 8;
140
141 vprod01234567 = wasm_i16x8_mul(vi4x01234567, vk4x01234567);
142
143 vacc0123 = wasm_i32x4_add(vacc0123, wasm_i32x4_extend_low_i16x8(vprod01234567));
144 vacc4567 = wasm_i32x4_add(vacc4567, wasm_i32x4_extend_high_i16x8(vprod01234567));
145
146 const v128_t vi5x01234567 = wasm_i16x8_load8x8(i5);
147 const v128_t vk5x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 8 * sizeof(int32_t) + 40 * sizeof(int8_t)));
148 i5 += 8;
149
150 vprod01234567 = wasm_i16x8_mul(vi5x01234567, vk5x01234567);
151
152 vacc0123 = wasm_i32x4_add(vacc0123, wasm_i32x4_extend_low_i16x8(vprod01234567));
153 vacc4567 = wasm_i32x4_add(vacc4567, wasm_i32x4_extend_high_i16x8(vprod01234567));
154
155 const v128_t vi6x01234567 = wasm_i16x8_load8x8(i6);
156 const v128_t vk6x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 8 * sizeof(int32_t) + 48 * sizeof(int8_t)));
157 i6 += 8;
158
159 vprod01234567 = wasm_i16x8_mul(vi6x01234567, vk6x01234567);
160
161 vacc0123 = wasm_i32x4_add(vacc0123, wasm_i32x4_extend_low_i16x8(vprod01234567));
162 vacc4567 = wasm_i32x4_add(vacc4567, wasm_i32x4_extend_high_i16x8(vprod01234567));
163
164 const v128_t vi7x01234567 = wasm_i16x8_load8x8(i7);
165 const v128_t vk7x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 8 * sizeof(int32_t) + 56 * sizeof(int8_t)));
166 i7 += 8;
167
168 vprod01234567 = wasm_i16x8_mul(vi7x01234567, vk7x01234567);
169
170 vacc0123 = wasm_i32x4_add(vacc0123, wasm_i32x4_extend_low_i16x8(vprod01234567));
171 vacc4567 = wasm_i32x4_add(vacc4567, wasm_i32x4_extend_high_i16x8(vprod01234567));
172
173 const v128_t vi8x01234567 = wasm_i16x8_load8x8(i8);
174 const v128_t vk8x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 8 * sizeof(int32_t) + 64 * sizeof(int8_t)));
175 i8 += 8;
176
177 vprod01234567 = wasm_i16x8_mul(vi8x01234567, vk8x01234567);
178
179 vacc0123 = wasm_i32x4_add(vacc0123, wasm_i32x4_extend_low_i16x8(vprod01234567));
180 vacc4567 = wasm_i32x4_add(vacc4567, wasm_i32x4_extend_high_i16x8(vprod01234567));
181
182
183 w = (const void*) ((uintptr_t) w + 8 * sizeof(int32_t) + 72 * sizeof(int8_t));
184
185 vacc0123 = wasm_f32x4_convert_i32x4(vacc0123);
186 vacc4567 = wasm_f32x4_convert_i32x4(vacc4567);
187
188 vacc0123 = wasm_f32x4_mul(vacc0123, vscale);
189 vacc4567 = wasm_f32x4_mul(vacc4567, vscale);
190
191 vacc0123 = wasm_f32x4_add(vacc0123, vmagic_bias);
192 vacc4567 = wasm_f32x4_add(vacc4567, vmagic_bias);
193
194 vacc0123 = wasm_i32x4_max(vacc0123, vmagic_min);
195 vacc4567 = wasm_i32x4_max(vacc4567, vmagic_min);
196
197 vacc0123 = wasm_i32x4_sub(vacc0123, vmagic_bias_less_output_zero_point);
198 vacc4567 = wasm_i32x4_sub(vacc4567, vmagic_bias_less_output_zero_point);
199
200 v128_t vout01234567 = wasm_i16x8_narrow_i32x4(vacc0123, vacc4567);
201
202 v128_t vout0123456701234567 = wasm_i8x16_narrow_i16x8(vout01234567, vout01234567);
203
204 vout0123456701234567 = wasm_i8x16_min(vout0123456701234567, voutput_max);
205
206 wasm_v128_store64_lane(output, vout0123456701234567, 0);
207 output += 8;
208 }
209 if XNN_UNLIKELY(c != 0) {
210 {
211 v128_t vacc0123 = wasm_v128_load(w);
212 v128_t vacc4567 = wasm_v128_load((const void*) ((uintptr_t) w + 4 * sizeof(int32_t)));
213
214
215 const v128_t vi0x01234567 = wasm_i16x8_load8x8(i0);
216 const v128_t vk0x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 8 * sizeof(int32_t) + 0 * sizeof(int8_t)));
217
218 v128_t vprod01234567 = wasm_i16x8_mul(vi0x01234567, vk0x01234567);
219
220 vacc0123 = wasm_i32x4_add(vacc0123, wasm_i32x4_extend_low_i16x8(vprod01234567));
221 vacc4567 = wasm_i32x4_add(vacc4567, wasm_i32x4_extend_high_i16x8(vprod01234567));
222
223 const v128_t vi1x01234567 = wasm_i16x8_load8x8(i1);
224 const v128_t vk1x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 8 * sizeof(int32_t) + 8 * sizeof(int8_t)));
225
226 vprod01234567 = wasm_i16x8_mul(vi1x01234567, vk1x01234567);
227
228 vacc0123 = wasm_i32x4_add(vacc0123, wasm_i32x4_extend_low_i16x8(vprod01234567));
229 vacc4567 = wasm_i32x4_add(vacc4567, wasm_i32x4_extend_high_i16x8(vprod01234567));
230
231 const v128_t vi2x01234567 = wasm_i16x8_load8x8(i2);
232 const v128_t vk2x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 8 * sizeof(int32_t) + 16 * sizeof(int8_t)));
233
234 vprod01234567 = wasm_i16x8_mul(vi2x01234567, vk2x01234567);
235
236 vacc0123 = wasm_i32x4_add(vacc0123, wasm_i32x4_extend_low_i16x8(vprod01234567));
237 vacc4567 = wasm_i32x4_add(vacc4567, wasm_i32x4_extend_high_i16x8(vprod01234567));
238
239 const v128_t vi3x01234567 = wasm_i16x8_load8x8(i3);
240 const v128_t vk3x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 8 * sizeof(int32_t) + 24 * sizeof(int8_t)));
241
242 vprod01234567 = wasm_i16x8_mul(vi3x01234567, vk3x01234567);
243
244 vacc0123 = wasm_i32x4_add(vacc0123, wasm_i32x4_extend_low_i16x8(vprod01234567));
245 vacc4567 = wasm_i32x4_add(vacc4567, wasm_i32x4_extend_high_i16x8(vprod01234567));
246
247 const v128_t vi4x01234567 = wasm_i16x8_load8x8(i4);
248 const v128_t vk4x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 8 * sizeof(int32_t) + 32 * sizeof(int8_t)));
249
250 vprod01234567 = wasm_i16x8_mul(vi4x01234567, vk4x01234567);
251
252 vacc0123 = wasm_i32x4_add(vacc0123, wasm_i32x4_extend_low_i16x8(vprod01234567));
253 vacc4567 = wasm_i32x4_add(vacc4567, wasm_i32x4_extend_high_i16x8(vprod01234567));
254
255 const v128_t vi5x01234567 = wasm_i16x8_load8x8(i5);
256 const v128_t vk5x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 8 * sizeof(int32_t) + 40 * sizeof(int8_t)));
257
258 vprod01234567 = wasm_i16x8_mul(vi5x01234567, vk5x01234567);
259
260 vacc0123 = wasm_i32x4_add(vacc0123, wasm_i32x4_extend_low_i16x8(vprod01234567));
261 vacc4567 = wasm_i32x4_add(vacc4567, wasm_i32x4_extend_high_i16x8(vprod01234567));
262
263 const v128_t vi6x01234567 = wasm_i16x8_load8x8(i6);
264 const v128_t vk6x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 8 * sizeof(int32_t) + 48 * sizeof(int8_t)));
265
266 vprod01234567 = wasm_i16x8_mul(vi6x01234567, vk6x01234567);
267
268 vacc0123 = wasm_i32x4_add(vacc0123, wasm_i32x4_extend_low_i16x8(vprod01234567));
269 vacc4567 = wasm_i32x4_add(vacc4567, wasm_i32x4_extend_high_i16x8(vprod01234567));
270
271 const v128_t vi7x01234567 = wasm_i16x8_load8x8(i7);
272 const v128_t vk7x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 8 * sizeof(int32_t) + 56 * sizeof(int8_t)));
273
274 vprod01234567 = wasm_i16x8_mul(vi7x01234567, vk7x01234567);
275
276 vacc0123 = wasm_i32x4_add(vacc0123, wasm_i32x4_extend_low_i16x8(vprod01234567));
277 vacc4567 = wasm_i32x4_add(vacc4567, wasm_i32x4_extend_high_i16x8(vprod01234567));
278
279 const v128_t vi8x01234567 = wasm_i16x8_load8x8(i8);
280 const v128_t vk8x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 8 * sizeof(int32_t) + 64 * sizeof(int8_t)));
281
282 vprod01234567 = wasm_i16x8_mul(vi8x01234567, vk8x01234567);
283
284 vacc0123 = wasm_i32x4_add(vacc0123, wasm_i32x4_extend_low_i16x8(vprod01234567));
285 vacc4567 = wasm_i32x4_add(vacc4567, wasm_i32x4_extend_high_i16x8(vprod01234567));
286
287
288
289 vacc0123 = wasm_f32x4_convert_i32x4(vacc0123);
290 vacc4567 = wasm_f32x4_convert_i32x4(vacc4567);
291
292 vacc0123 = wasm_f32x4_mul(vacc0123, vscale);
293 vacc4567 = wasm_f32x4_mul(vacc4567, vscale);
294
295 vacc0123 = wasm_f32x4_add(vacc0123, vmagic_bias);
296 vacc4567 = wasm_f32x4_add(vacc4567, vmagic_bias);
297
298 vacc0123 = wasm_i32x4_max(vacc0123, vmagic_min);
299 vacc4567 = wasm_i32x4_max(vacc4567, vmagic_min);
300
301 vacc0123 = wasm_i32x4_sub(vacc0123, vmagic_bias_less_output_zero_point);
302 vacc4567 = wasm_i32x4_sub(vacc4567, vmagic_bias_less_output_zero_point);
303
304 v128_t vout01234567 = wasm_i16x8_narrow_i32x4(vacc0123, vacc4567);
305 v128_t vout0123456701234567 = wasm_i8x16_narrow_i16x8(vout01234567, vout01234567);
306
307 vout0123456701234567 = wasm_i8x16_min(vout0123456701234567, voutput_max);
308
309
310 if (c & 4) {
311 wasm_v128_store32_lane(output, vout0123456701234567, 0);
312 vout0123456701234567 = wasm_u64x2_shr(vout0123456701234567, 32);
313 output += 4;
314 }
315 if (c & 2) {
316 wasm_v128_store16_lane(output, vout0123456701234567, 0);
317 vout0123456701234567 = wasm_u32x4_shr(vout0123456701234567, 16);
318 output += 2;
319 }
320 if (c & 1) {
321 wasm_v128_store8_lane(output, vout0123456701234567, 0);
322 output += 1;
323 }
324 }
325 }
326
327 output = (int8_t*) ((uintptr_t) output + output_increment);
328 } while (--output_width != 0);
329 }