Debian Codegraph @

src/qd8-f32-qc4w-gemm/gen/qd8-f32-qc4w-gemm-1x8-minmax-wasm.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-gemm/scalar.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 "xnnpack/gemm.h"
13 #include "xnnpack/math.h"
14
15
16 void xnn_qd8_f32_qc4w_gemm_minmax_ukernel_1x8__wasm(
17 size_t mr,
18 size_t nc,
19 size_t kc,
20 const int8_t* restrict a,
21 size_t a_stride,
22 const void* restrict w,
23 float* restrict c,
24 size_t cm_stride,
25 size_t cn_stride,
26 const struct xnn_f32_qc4w_minmax_params params[restrict XNN_MIN_ELEMENTS(1)],
27 const struct xnn_qd8_quantization_params quantization_params[restrict XNN_MIN_ELEMENTS(1)])
28 {
29 assert(mr != 0);
30 assert(mr <= 1);
31 assert(nc != 0);
32 assert(kc != 0);
33
34 const int8_t* a0 = a;
35 float* c0 = c;
36
37
38 kc = round_up_po2(kc, 2);
39 do {
40 const int32_t vksum0 = ((const int32_t*) w)[0];
41 const int32_t vksum1 = ((const int32_t*) w)[1];
42 const int32_t vksum2 = ((const int32_t*) w)[2];
43 const int32_t vksum3 = ((const int32_t*) w)[3];
44 const int32_t vksum4 = ((const int32_t*) w)[4];
45 const int32_t vksum5 = ((const int32_t*) w)[5];
46 const int32_t vksum6 = ((const int32_t*) w)[6];
47 const int32_t vksum7 = ((const int32_t*) w)[7];
48 const int32_t vinput_zero_point0 = quantization_params[0].zero_point;
49 int32_t vacc0x0 = vksum0 * vinput_zero_point0;
50 int32_t vacc0x1 = vksum1 * vinput_zero_point0;
51 int32_t vacc0x2 = vksum2 * vinput_zero_point0;
52 int32_t vacc0x3 = vksum3 * vinput_zero_point0;
53 int32_t vacc0x4 = vksum4 * vinput_zero_point0;
54 int32_t vacc0x5 = vksum5 * vinput_zero_point0;
55 int32_t vacc0x6 = vksum6 * vinput_zero_point0;
56 int32_t vacc0x7 = vksum7 * vinput_zero_point0;
57 w = (const int32_t*) w + 8;
58
59 size_t k = kc;
60 for (; k >= 2 * sizeof(uint8_t); k -= 2 * sizeof(uint8_t)) {
61 const int32_t va0c0 = (int32_t) a0[0];
62 const int32_t va0c1 = (int32_t) a0[1];
63 a0 += 2;
64
65 const uint8_t vbi0 = ((const uint8_t*) w)[0];
66 const uint8_t vbi1 = ((const uint8_t*) w)[1];
67 const uint8_t vbi2 = ((const uint8_t*) w)[2];
68 const uint8_t vbi3 = ((const uint8_t*) w)[3];
69 const uint8_t vbi4 = ((const uint8_t*) w)[4];
70 const uint8_t vbi5 = ((const uint8_t*) w)[5];
71 const uint8_t vbi6 = ((const uint8_t*) w)[6];
72 const uint8_t vbi7 = ((const uint8_t*) w)[7];
73 w = (const uint8_t*) w + 8;
74 const int32_t vb0c0 = (int32_t) (int8_t) (vbi0 << 4);
75 const int32_t vb0c1 = (int32_t) (int8_t) (vbi0 & 0xF0);
76 const int32_t vb1c0 = (int32_t) (int8_t) (vbi1 << 4);
77 const int32_t vb1c1 = (int32_t) (int8_t) (vbi1 & 0xF0);
78 const int32_t vb2c0 = (int32_t) (int8_t) (vbi2 << 4);
79 const int32_t vb2c1 = (int32_t) (int8_t) (vbi2 & 0xF0);
80 const int32_t vb3c0 = (int32_t) (int8_t) (vbi3 << 4);
81 const int32_t vb3c1 = (int32_t) (int8_t) (vbi3 & 0xF0);
82 const int32_t vb4c0 = (int32_t) (int8_t) (vbi4 << 4);
83 const int32_t vb4c1 = (int32_t) (int8_t) (vbi4 & 0xF0);
84 const int32_t vb5c0 = (int32_t) (int8_t) (vbi5 << 4);
85 const int32_t vb5c1 = (int32_t) (int8_t) (vbi5 & 0xF0);
86 const int32_t vb6c0 = (int32_t) (int8_t) (vbi6 << 4);
87 const int32_t vb6c1 = (int32_t) (int8_t) (vbi6 & 0xF0);
88 const int32_t vb7c0 = (int32_t) (int8_t) (vbi7 << 4);
89 const int32_t vb7c1 = (int32_t) (int8_t) (vbi7 & 0xF0);
90
91 vacc0x0 += va0c0 * vb0c0;
92 vacc0x1 += va0c0 * vb1c0;
93 vacc0x2 += va0c0 * vb2c0;
94 vacc0x3 += va0c0 * vb3c0;
95 vacc0x4 += va0c0 * vb4c0;
96 vacc0x5 += va0c0 * vb5c0;
97 vacc0x6 += va0c0 * vb6c0;
98 vacc0x7 += va0c0 * vb7c0;
99 vacc0x0 += va0c1 * vb0c1;
100 vacc0x1 += va0c1 * vb1c1;
101 vacc0x2 += va0c1 * vb2c1;
102 vacc0x3 += va0c1 * vb3c1;
103 vacc0x4 += va0c1 * vb4c1;
104 vacc0x5 += va0c1 * vb5c1;
105 vacc0x6 += va0c1 * vb6c1;
106 vacc0x7 += va0c1 * vb7c1;
107 }
108
109 float vout0x0 = (float) math_asr_s32(vacc0x0, 4);
110 float vout0x1 = (float) math_asr_s32(vacc0x1, 4);
111 float vout0x2 = (float) math_asr_s32(vacc0x2, 4);
112 float vout0x3 = (float) math_asr_s32(vacc0x3, 4);
113 float vout0x4 = (float) math_asr_s32(vacc0x4, 4);
114 float vout0x5 = (float) math_asr_s32(vacc0x5, 4);
115 float vout0x6 = (float) math_asr_s32(vacc0x6, 4);
116 float vout0x7 = (float) math_asr_s32(vacc0x7, 4);
117
118 const float vinput_scale0 = quantization_params[0].inv_scale;
119 vout0x0 *= vinput_scale0;
120 vout0x1 *= vinput_scale0;
121 vout0x2 *= vinput_scale0;
122 vout0x3 *= vinput_scale0;
123 vout0x4 *= vinput_scale0;
124 vout0x5 *= vinput_scale0;
125 vout0x6 *= vinput_scale0;
126 vout0x7 *= vinput_scale0;
127
128 const float vfilter_output_scale0 = ((const float*) w)[0];
129 vout0x0 *= vfilter_output_scale0;
130 const float vfilter_output_scale1 = ((const float*) w)[1];
131 vout0x1 *= vfilter_output_scale1;
132 const float vfilter_output_scale2 = ((const float*) w)[2];
133 vout0x2 *= vfilter_output_scale2;
134 const float vfilter_output_scale3 = ((const float*) w)[3];
135 vout0x3 *= vfilter_output_scale3;
136 const float vfilter_output_scale4 = ((const float*) w)[4];
137 vout0x4 *= vfilter_output_scale4;
138 const float vfilter_output_scale5 = ((const float*) w)[5];
139 vout0x5 *= vfilter_output_scale5;
140 const float vfilter_output_scale6 = ((const float*) w)[6];
141 vout0x6 *= vfilter_output_scale6;
142 const float vfilter_output_scale7 = ((const float*) w)[7];
143 vout0x7 *= vfilter_output_scale7;
144
145 const float vbias0 = ((const float*) w)[8];
146 vout0x0 += vbias0;
147 const float vbias1 = ((const float*) w)[9];
148 vout0x1 += vbias1;
149 const float vbias2 = ((const float*) w)[10];
150 vout0x2 += vbias2;
151 const float vbias3 = ((const float*) w)[11];
152 vout0x3 += vbias3;
153 const float vbias4 = ((const float*) w)[12];
154 vout0x4 += vbias4;
155 const float vbias5 = ((const float*) w)[13];
156 vout0x5 += vbias5;
157 const float vbias6 = ((const float*) w)[14];
158 vout0x6 += vbias6;
159 const float vbias7 = ((const float*) w)[15];
160 vout0x7 += vbias7;
161
162 w = (const float*) w + 16;
163
164 const float voutput_min = params->scalar.min;
165 vout0x0 = __builtin_wasm_max_f32(vout0x0, voutput_min);
166 vout0x1 = __builtin_wasm_max_f32(vout0x1, voutput_min);
167 vout0x2 = __builtin_wasm_max_f32(vout0x2, voutput_min);
168 vout0x3 = __builtin_wasm_max_f32(vout0x3, voutput_min);
169 vout0x4 = __builtin_wasm_max_f32(vout0x4, voutput_min);
170 vout0x5 = __builtin_wasm_max_f32(vout0x5, voutput_min);
171 vout0x6 = __builtin_wasm_max_f32(vout0x6, voutput_min);
172 vout0x7 = __builtin_wasm_max_f32(vout0x7, voutput_min);
173
174 const float voutput_max = params->scalar.max;
175 vout0x0 = __builtin_wasm_min_f32(vout0x0, voutput_max);
176 vout0x1 = __builtin_wasm_min_f32(vout0x1, voutput_max);
177 vout0x2 = __builtin_wasm_min_f32(vout0x2, voutput_max);
178 vout0x3 = __builtin_wasm_min_f32(vout0x3, voutput_max);
179 vout0x4 = __builtin_wasm_min_f32(vout0x4, voutput_max);
180 vout0x5 = __builtin_wasm_min_f32(vout0x5, voutput_max);
181 vout0x6 = __builtin_wasm_min_f32(vout0x6, voutput_max);
182 vout0x7 = __builtin_wasm_min_f32(vout0x7, voutput_max);
183
184 if XNN_LIKELY(nc >= 8) {
185 c0[0] = vout0x0;
186 c0[1] = vout0x1;
187 c0[2] = vout0x2;
188 c0[3] = vout0x3;
189 c0[4] = vout0x4;
190 c0[5] = vout0x5;
191 c0[6] = vout0x6;
192 c0[7] = vout0x7;
193
194 a0 = (const int8_t*) ((uintptr_t) a0 - kc);
195
196 c0 = (float*) ((uintptr_t) c0 + cn_stride);
197
198 nc -= 8;
199 } else {
200 if (nc & 4) {
201 c0[0] = vout0x0;
202 c0[1] = vout0x1;
203 c0[2] = vout0x2;
204 c0[3] = vout0x3;
205 vout0x0 = vout0x4;
206 vout0x1 = vout0x5;
207 vout0x2 = vout0x6;
208 c0 += 4;
209 }
210 if (nc & 2) {
211 c0[0] = vout0x0;
212 c0[1] = vout0x1;
213 vout0x0 = vout0x2;
214 vout0x1 = vout0x3;
215 vout0x2 = vout0x4;
216 vout0x3 = vout0x5;
217 vout0x4 = vout0x6;
218 c0 += 2;
219 }
220 if (nc & 1) {
221 c0[0] = vout0x0;
222 }
223
224 nc = 0;
225 }
226 } while (nc != 0);
227 }