1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-igemm/MRx4c2s4-wasmsimd-dot16x2.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2021 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/igemm.h>
15 #include <xnnpack/math.h>
16
17
xnn_qc8_igemm_minmax_fp32_ukernel_3x4c2s4__wasmsimd_dot16x2_ld64(size_t mr,size_t nc,size_t kc,size_t ks,const int8_t ** restrict a,const void * restrict w,int8_t * restrict c,size_t cm_stride,size_t cn_stride,size_t a_offset,const int8_t * zero,const union xnn_qc8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])18 void xnn_qc8_igemm_minmax_fp32_ukernel_3x4c2s4__wasmsimd_dot16x2_ld64(
19 size_t mr,
20 size_t nc,
21 size_t kc,
22 size_t ks,
23 const int8_t** restrict a,
24 const void* restrict w,
25 int8_t* restrict c,
26 size_t cm_stride,
27 size_t cn_stride,
28 size_t a_offset,
29 const int8_t* zero,
30 const union xnn_qc8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
31 {
32 assert(mr != 0);
33 assert(mr <= 3);
34 assert(nc != 0);
35 assert(kc != 0);
36 assert(ks != 0);
37 assert(ks % (3 * sizeof(void*)) == 0);
38 assert(a_offset % sizeof(int8_t) == 0);
39 assert(a != NULL);
40 assert(w != NULL);
41 assert(c != NULL);
42
43 int8_t* c0 = c;
44 int8_t* c1 = (int8_t*) ((uintptr_t) c0 + cm_stride);
45 if XNN_UNPREDICTABLE(mr < 2) {
46 c1 = c0;
47 }
48 int8_t* c2 = (int8_t*) ((uintptr_t) c1 + cm_stride);
49 if XNN_UNPREDICTABLE(mr <= 2) {
50 c2 = c1;
51 }
52
53 kc = round_up_po2(kc, 8 * sizeof(int8_t));
54 do {
55 v128_t vacc0x0123 = wasm_v128_load(w);
56 v128_t vacc1x0123 = vacc0x0123;
57 v128_t vacc2x0123 = vacc0x0123;
58 w = (const void*) ((const int32_t*) w + 4);
59
60 size_t p = ks;
61 do {
62 const int8_t* restrict a0 = a[0];
63 if XNN_UNPREDICTABLE(a0 != zero) {
64 a0 = (const int8_t*) ((uintptr_t) a0 + a_offset);
65 }
66 const int8_t* restrict a1 = a[1];
67 if XNN_UNPREDICTABLE(a1 != zero) {
68 a1 = (const int8_t*) ((uintptr_t) a1 + a_offset);
69 }
70 const int8_t* restrict a2 = a[2];
71 if XNN_UNPREDICTABLE(a2 != zero) {
72 a2 = (const int8_t*) ((uintptr_t) a2 + a_offset);
73 }
74 a += 3;
75
76 size_t k = kc;
77 do {
78 v128_t vxa0 = wasm_i16x8_load8x8(a0);
79 a0 += 8;
80 v128_t vxa1 = wasm_i16x8_load8x8(a1);
81 a1 += 8;
82 v128_t vxa2 = wasm_i16x8_load8x8(a2);
83 a2 += 8;
84
85 const v128_t vxb0 = wasm_i16x8_load8x8(w);
86
87 vacc0x0123 = wasm_i32x4_add(vacc0x0123, wasm_i32x4_dot_i16x8(vxa0, vxb0));
88 vxa0 = wasm_v32x4_shuffle(vxa0, vxa0, 1, 2, 3, 4);
89 vacc1x0123 = wasm_i32x4_add(vacc1x0123, wasm_i32x4_dot_i16x8(vxa1, vxb0));
90 vxa1 = wasm_v32x4_shuffle(vxa1, vxa1, 1, 2, 3, 4);
91 vacc2x0123 = wasm_i32x4_add(vacc2x0123, wasm_i32x4_dot_i16x8(vxa2, vxb0));
92 vxa2 = wasm_v32x4_shuffle(vxa2, vxa2, 1, 2, 3, 4);
93 const v128_t vxb1 = wasm_i16x8_load8x8((const int8_t*) w + 8);
94
95 vacc0x0123 = wasm_i32x4_add(vacc0x0123, wasm_i32x4_dot_i16x8(vxa0, vxb1));
96 vxa0 = wasm_v32x4_shuffle(vxa0, vxa0, 1, 2, 3, 4);
97 vacc1x0123 = wasm_i32x4_add(vacc1x0123, wasm_i32x4_dot_i16x8(vxa1, vxb1));
98 vxa1 = wasm_v32x4_shuffle(vxa1, vxa1, 1, 2, 3, 4);
99 vacc2x0123 = wasm_i32x4_add(vacc2x0123, wasm_i32x4_dot_i16x8(vxa2, vxb1));
100 vxa2 = wasm_v32x4_shuffle(vxa2, vxa2, 1, 2, 3, 4);
101 const v128_t vxb2 = wasm_i16x8_load8x8((const int8_t*) w + 16);
102
103 vacc0x0123 = wasm_i32x4_add(vacc0x0123, wasm_i32x4_dot_i16x8(vxa0, vxb2));
104 vxa0 = wasm_v32x4_shuffle(vxa0, vxa0, 1, 2, 3, 4);
105 vacc1x0123 = wasm_i32x4_add(vacc1x0123, wasm_i32x4_dot_i16x8(vxa1, vxb2));
106 vxa1 = wasm_v32x4_shuffle(vxa1, vxa1, 1, 2, 3, 4);
107 vacc2x0123 = wasm_i32x4_add(vacc2x0123, wasm_i32x4_dot_i16x8(vxa2, vxb2));
108 vxa2 = wasm_v32x4_shuffle(vxa2, vxa2, 1, 2, 3, 4);
109 const v128_t vxb3 = wasm_i16x8_load8x8((const int8_t*) w + 24);
110
111 vacc0x0123 = wasm_i32x4_add(vacc0x0123, wasm_i32x4_dot_i16x8(vxa0, vxb3));
112 vacc1x0123 = wasm_i32x4_add(vacc1x0123, wasm_i32x4_dot_i16x8(vxa1, vxb3));
113 vacc2x0123 = wasm_i32x4_add(vacc2x0123, wasm_i32x4_dot_i16x8(vxa2, vxb3));
114
115 w = (const int8_t*) w + 32;
116 k -= 8 * sizeof(int8_t);
117 } while (k != 0);
118 p -= 3 * sizeof(void*);
119 } while (p != 0);
120
121 vacc0x0123 = wasm_f32x4_convert_i32x4(vacc0x0123);
122 vacc1x0123 = wasm_f32x4_convert_i32x4(vacc1x0123);
123 vacc2x0123 = wasm_f32x4_convert_i32x4(vacc2x0123);
124
125 const v128_t vscale0123 = wasm_v128_load(w);
126 w = (const void*) ((const float*) w + 4);
127 vacc0x0123 = wasm_f32x4_mul(vacc0x0123, vscale0123);
128 vacc1x0123 = wasm_f32x4_mul(vacc1x0123, vscale0123);
129 vacc2x0123 = wasm_f32x4_mul(vacc2x0123, vscale0123);
130
131 const v128_t vmagic_bias = wasm_v128_load64_splat(params->fp32_wasmsimd.magic_bias);
132 vacc0x0123 = wasm_f32x4_add(vacc0x0123, vmagic_bias);
133 vacc1x0123 = wasm_f32x4_add(vacc1x0123, vmagic_bias);
134 vacc2x0123 = wasm_f32x4_add(vacc2x0123, vmagic_bias);
135
136 const v128_t vmagic_min = wasm_v128_load64_splat(params->fp32_wasmsimd.magic_min);
137 vacc0x0123 = wasm_i32x4_max(vacc0x0123, vmagic_min);
138 vacc1x0123 = wasm_i32x4_max(vacc1x0123, vmagic_min);
139 vacc2x0123 = wasm_i32x4_max(vacc2x0123, vmagic_min);
140
141 const v128_t vmagic_bias_less_output_zero_point = wasm_v128_load64_splat(params->fp32_wasmsimd.magic_bias_less_output_zero_point);
142 vacc0x0123 = wasm_i32x4_sub(vacc0x0123, vmagic_bias_less_output_zero_point);
143 vacc1x0123 = wasm_i32x4_sub(vacc1x0123, vmagic_bias_less_output_zero_point);
144 vacc2x0123 = wasm_i32x4_sub(vacc2x0123, vmagic_bias_less_output_zero_point);
145
146 v128_t vacc01x0123 = wasm_i16x8_narrow_i32x4(vacc0x0123, vacc1x0123);
147 v128_t vacc22x0123 = wasm_i16x8_narrow_i32x4(vacc2x0123, vacc2x0123);
148
149 v128_t vout = wasm_i8x16_narrow_i16x8(vacc01x0123, vacc22x0123);
150
151 const v128_t voutput_max = wasm_v128_load64_splat(params->fp32_wasmsimd.output_max);
152 vout = wasm_i8x16_min(vout, voutput_max);
153
154 if (nc >= 4) {
155 *((float*) c2) = (float) wasm_f32x4_extract_lane(vout, 2);
156 *((float*) c1) = (float) wasm_f32x4_extract_lane(vout, 1);
157 *((float*) c0) = (float) wasm_f32x4_extract_lane(vout, 0);
158
159 c2 = (int8_t*) ((uintptr_t) c2 + cn_stride);
160 c1 = (int8_t*) ((uintptr_t) c1 + cn_stride);
161 c0 = (int8_t*) ((uintptr_t) c0 + cn_stride);
162
163 a = (const int8_t**restrict) ((uintptr_t) a - ks);
164
165 nc -= 4;
166 } else {
167 uint32_t vout2 = wasm_i32x4_extract_lane(vout, 2);
168 uint32_t vout1 = wasm_i32x4_extract_lane(vout, 1);
169 uint32_t vout0 = wasm_i32x4_extract_lane(vout, 0);
170 if (nc & 2) {
171 *((uint16_t*) c2) = (uint16_t) vout2;
172 vout2 >>= 16;
173 c2 += 2;
174 *((uint16_t*) c1) = (uint16_t) vout1;
175 vout1 >>= 16;
176 c1 += 2;
177 *((uint16_t*) c0) = (uint16_t) vout0;
178 vout0 >>= 16;
179 c0 += 2;
180 }
181 if (nc & 1) {
182 *c2 = (int8_t) vout2;
183 *c1 = (int8_t) vout1;
184 *c0 = (int8_t) vout0;
185 }
186
187 nc = 0;
188 }
189 } while (nc != 0);
190 }
191