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_qc8_dwconv_minmax_fp32_ukernel_up16x3__wasmsimd_mul16_add16(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_qc8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])17 void xnn_qc8_dwconv_minmax_fp32_ukernel_up16x3__wasmsimd_mul16_add16(
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_qc8_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 input = (const int8_t**) ((uintptr_t) input + input_stride);
49
50 size_t c = channels;
51 const void* w = weights;
52 for (; c >= 16; c -= 16) {
53 v128_t vacc0123 = wasm_v128_load(w);
54 v128_t vacc4567 = wasm_v128_load((const void*) ((uintptr_t) w + 4 * sizeof(int32_t)));
55 v128_t vacc89AB = wasm_v128_load((const void*) ((uintptr_t) w + 8 * sizeof(int32_t)));
56 v128_t vaccCDEF = wasm_v128_load((const void*) ((uintptr_t) w + 12 * sizeof(int32_t)));
57
58
59 const v128_t vi0x01234567 = wasm_i16x8_load8x8(i0);
60 const v128_t vk0x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 16 * sizeof(int32_t) + 0 * sizeof(int8_t)));
61 const v128_t vi0x89ABCDEF = wasm_i16x8_load8x8(i0 + 8);
62 const v128_t vk0x89ABCDEF = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 16 * sizeof(int32_t) + 8 * sizeof(int8_t)));
63 i0 += 16;
64
65 v128_t vprod01234567 = wasm_i16x8_mul(vi0x01234567, vk0x01234567);
66 v128_t vprod89ABCDEF = wasm_i16x8_mul(vi0x89ABCDEF, vk0x89ABCDEF);
67
68
69 const v128_t vi1x01234567 = wasm_i16x8_load8x8(i1);
70 const v128_t vk1x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 16 * sizeof(int32_t) + 16 * sizeof(int8_t)));
71 const v128_t vi1x89ABCDEF = wasm_i16x8_load8x8(i1 + 8);
72 const v128_t vk1x89ABCDEF = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 16 * sizeof(int32_t) + 24 * sizeof(int8_t)));
73 i1 += 16;
74
75 vprod01234567 = wasm_i16x8_add(vprod01234567, wasm_i16x8_mul(vi1x01234567, vk1x01234567));
76 vprod89ABCDEF = wasm_i16x8_add(vprod89ABCDEF, wasm_i16x8_mul(vi1x89ABCDEF, vk1x89ABCDEF));
77
78 vacc0123 = wasm_i32x4_add(vacc0123, wasm_i32x4_extend_low_i16x8(vprod01234567));
79 vacc4567 = wasm_i32x4_add(vacc4567, wasm_i32x4_extend_high_i16x8(vprod01234567));
80 vacc89AB = wasm_i32x4_add(vacc89AB, wasm_i32x4_extend_low_i16x8(vprod89ABCDEF));
81 vaccCDEF = wasm_i32x4_add(vaccCDEF, wasm_i32x4_extend_high_i16x8(vprod89ABCDEF));
82
83 const v128_t vi2x01234567 = wasm_i16x8_load8x8(i2);
84 const v128_t vk2x01234567 = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 16 * sizeof(int32_t) + 32 * sizeof(int8_t)));
85 const v128_t vi2x89ABCDEF = wasm_i16x8_load8x8(i2 + 8);
86 const v128_t vk2x89ABCDEF = wasm_i16x8_load8x8((const void*) ((uintptr_t) w + 16 * sizeof(int32_t) + 40 * sizeof(int8_t)));
87 i2 += 16;
88
89 vprod01234567 = wasm_i16x8_mul(vi2x01234567, vk2x01234567);
90 vprod89ABCDEF = wasm_i16x8_mul(vi2x89ABCDEF, vk2x89ABCDEF);
91
92 vacc0123 = wasm_i32x4_add(vacc0123, wasm_i32x4_extend_low_i16x8(vprod01234567));
93 vacc4567 = wasm_i32x4_add(vacc4567, wasm_i32x4_extend_high_i16x8(vprod01234567));
94 vacc89AB = wasm_i32x4_add(vacc89AB, wasm_i32x4_extend_low_i16x8(vprod89ABCDEF));
95 vaccCDEF = wasm_i32x4_add(vaccCDEF, wasm_i32x4_extend_high_i16x8(vprod89ABCDEF));
96
97
98 w = (const void*) ((uintptr_t) w + 16 * sizeof(int32_t) + 48 * sizeof(int8_t));
99
100 vacc0123 = wasm_f32x4_convert_i32x4(vacc0123);
101 vacc4567 = wasm_f32x4_convert_i32x4(vacc4567);
102 vacc89AB = wasm_f32x4_convert_i32x4(vacc89AB);
103 vaccCDEF = wasm_f32x4_convert_i32x4(vaccCDEF);
104
105 const v128_t vscale0123 = wasm_v128_load(w);
106 const v128_t vscale4567 = wasm_v128_load((const float*) w + 4);
107 const v128_t vscale89AB = wasm_v128_load((const float*) w + 8);
108 const v128_t vscaleCDEF = wasm_v128_load((const float*) w + 12);
109 w = (const void*) ((const float*) w + 16);
110
111 vacc0123 = wasm_f32x4_mul(vacc0123, vscale0123);
112 vacc4567 = wasm_f32x4_mul(vacc4567, vscale4567);
113 vacc89AB = wasm_f32x4_mul(vacc89AB, vscale89AB);
114 vaccCDEF = wasm_f32x4_mul(vaccCDEF, vscaleCDEF);
115
116 const v128_t vmagic_bias = wasm_v128_load64_splat(params->fp32_wasmsimd.magic_bias);
117 vacc0123 = wasm_f32x4_add(vacc0123, vmagic_bias);
118 vacc4567 = wasm_f32x4_add(vacc4567, vmagic_bias);
119 vacc89AB = wasm_f32x4_add(vacc89AB, vmagic_bias);
120 vaccCDEF = wasm_f32x4_add(vaccCDEF, vmagic_bias);
121
122 const v128_t vmagic_min = wasm_v128_load64_splat(params->fp32_wasmsimd.magic_min);
123 vacc0123 = wasm_i32x4_max(vacc0123, vmagic_min);
124 vacc4567 = wasm_i32x4_max(vacc4567, vmagic_min);
125 vacc89AB = wasm_i32x4_max(vacc89AB, vmagic_min);
126 vaccCDEF = wasm_i32x4_max(vaccCDEF, vmagic_min);
127
128 const v128_t vmagic_bias_less_output_zero_point = wasm_v128_load64_splat(params->fp32_wasmsimd.magic_bias_less_output_zero_point);
129 vacc0123 = wasm_i32x4_sub(vacc0123, vmagic_bias_less_output_zero_point);
130 vacc4567 = wasm_i32x4_sub(vacc4567, vmagic_bias_less_output_zero_point);
131 vacc89AB = wasm_i32x4_sub(vacc89AB, vmagic_bias_less_output_zero_point);
132 vaccCDEF = wasm_i32x4_sub(vaccCDEF, vmagic_bias_less_output_zero_point);
133
134 v128_t vout01234567 = wasm_i16x8_narrow_i32x4(vacc0123, vacc4567);
135 v128_t vout89ABCDEF = wasm_i16x8_narrow_i32x4(vacc89AB, vaccCDEF);
136
137 v128_t vout0123456789ABCDEF = wasm_i8x16_narrow_i16x8(vout01234567, vout89ABCDEF);
138
139 const v128_t voutput_max = wasm_v128_load64_splat(params->fp32_wasmsimd.output_max);
140 vout0123456789ABCDEF = wasm_i8x16_min(vout0123456789ABCDEF, voutput_max);
141
142 wasm_v128_store(output, vout0123456789ABCDEF);
143 output += 16;
144 }
145 if XNN_UNLIKELY(c != 0) {
146 const int8_t* k = (const int8_t*) ((uintptr_t) w + 16 * sizeof(int32_t));
147 do {
148 v128_t vacc0123 = wasm_v128_load(w);
149 v128_t vacc4567 = wasm_v128_load((const void*) ((uintptr_t) w + 4 * sizeof(int32_t)));
150
151
152 const v128_t vi0x01234567 = wasm_i16x8_load8x8(i0);
153 const v128_t vk0x01234567 = wasm_i16x8_load8x8(k);
154 i0 += 8;
155
156 v128_t vprod01234567 = wasm_i16x8_mul(vi0x01234567, vk0x01234567);
157
158
159 const v128_t vi1x01234567 = wasm_i16x8_load8x8(i1);
160 const v128_t vk1x01234567 = wasm_i16x8_load8x8((const void*) (k + 16));
161 i1 += 8;
162
163 vprod01234567 = wasm_i16x8_add(vprod01234567, wasm_i16x8_mul(vi1x01234567, vk1x01234567));
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 const v128_t vi2x01234567 = wasm_i16x8_load8x8(i2);
169 const v128_t vk2x01234567 = wasm_i16x8_load8x8((const void*) (k + 32));
170 i2 += 8;
171
172 vprod01234567 = wasm_i16x8_mul(vi2x01234567, vk2x01234567);
173
174 vacc0123 = wasm_i32x4_add(vacc0123, wasm_i32x4_extend_low_i16x8(vprod01234567));
175 vacc4567 = wasm_i32x4_add(vacc4567, wasm_i32x4_extend_high_i16x8(vprod01234567));
176
177 k += 8;
178
179
180 vacc0123 = wasm_f32x4_convert_i32x4(vacc0123);
181 vacc4567 = wasm_f32x4_convert_i32x4(vacc4567);
182
183 const v128_t vscale0123 = wasm_v128_load((const float*) ((uintptr_t) w + 16 * sizeof(int32_t) + 48 * sizeof(int8_t)));
184 const v128_t vscale4567 = wasm_v128_load((const float*) ((uintptr_t) w + 16 * sizeof(int32_t) + 48 * sizeof(int8_t) + 4 * sizeof(float)));
185
186 vacc0123 = wasm_f32x4_mul(vacc0123, vscale0123);
187 vacc4567 = wasm_f32x4_mul(vacc4567, vscale4567);
188
189 const v128_t vmagic_bias = wasm_v128_load64_splat(params->fp32_wasmsimd.magic_bias);
190 vacc0123 = wasm_f32x4_add(vacc0123, vmagic_bias);
191 vacc4567 = wasm_f32x4_add(vacc4567, vmagic_bias);
192
193 const v128_t vmagic_min = wasm_v128_load64_splat(params->fp32_wasmsimd.magic_min);
194 vacc0123 = wasm_i32x4_max(vacc0123, vmagic_min);
195 vacc4567 = wasm_i32x4_max(vacc4567, vmagic_min);
196
197 const v128_t vmagic_bias_less_output_zero_point = wasm_v128_load64_splat(params->fp32_wasmsimd.magic_bias_less_output_zero_point);
198 vacc0123 = wasm_i32x4_sub(vacc0123, vmagic_bias_less_output_zero_point);
199 vacc4567 = wasm_i32x4_sub(vacc4567, vmagic_bias_less_output_zero_point);
200
201 v128_t vout01234567 = wasm_i16x8_narrow_i32x4(vacc0123, vacc4567);
202 v128_t vout0123456701234567 = wasm_i8x16_narrow_i16x8(vout01234567, vout01234567);
203
204 const v128_t voutput_max = wasm_v128_load64_splat(params->fp32_wasmsimd.output_max);
205 vout0123456701234567 = wasm_i8x16_min(vout0123456701234567, voutput_max);
206
207 w = (const void*) ((uintptr_t) w + 8 * sizeof(int32_t));
208
209 if XNN_LIKELY(c >= 8) {
210 *((double*) output) = wasm_f64x2_extract_lane(vout0123456701234567, 0);
211 output += 8;
212 c -= 8;
213 } else {
214 if (c & 4) {
215 *((float*) output) = wasm_f32x4_extract_lane(vout0123456701234567, 0);
216 vout0123456701234567 = wasm_u64x2_shr(vout0123456701234567, 32);
217 output += 4;
218 }
219 uint32_t vout0123 = wasm_i32x4_extract_lane(vout0123456701234567, 0);
220 if (c & 2) {
221 *((uint16_t*) output) = (uint16_t) vout0123;
222 vout0123 >>= 16;
223 output += 2;
224 }
225 if (c & 1) {
226 *output = (int8_t) vout0123;
227 output += 1;
228 }
229 c = 0;
230 }
231 } while (c != 0);
232 }
233
234 output = (int8_t*) ((uintptr_t) output + output_increment);
235 } while (--output_width != 0);
236 }
237