Debian Codegraph @

src/qd8-f32-qc8w-igemm/gen/qd8-f32-qc8w-igemm-1x8-minmax-wasm.c

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