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