Debian Codegraph @

src/qd8-f32-qc8w-gemm/gen/qd8-f32-qc8w-gemm-2x4-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_qc8w_gemm_minmax_ukernel_2x4__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 union xnn_f32_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 <= 2);
31 assert(nc != 0);
32 assert(kc != 0);
33
34 const int8_t* a0 = a;
35 float* c0 = c;
36 const int8_t* a1 = (const int8_t*) ((uintptr_t) a0 + a_stride);
37 float* c1 = (float*) ((uintptr_t) c0 + cm_stride);
38 if XNN_UNPREDICTABLE(mr != 2) {
39 a1 = a0;
40 c1 = c0;
41 }
42
43
44 do {
45 const int32_t vksum0 = ((const int32_t*) w)[0];
46 const int32_t vksum1 = ((const int32_t*) w)[1];
47 const int32_t vksum2 = ((const int32_t*) w)[2];
48 const int32_t vksum3 = ((const int32_t*) w)[3];
49 const int32_t vinput_zero_point0 = quantization_params[0].zero_point;
50 int32_t vacc0x0 = vksum0 * vinput_zero_point0;
51 int32_t vacc0x1 = vksum1 * vinput_zero_point0;
52 int32_t vacc0x2 = vksum2 * vinput_zero_point0;
53 int32_t vacc0x3 = vksum3 * vinput_zero_point0;
54 const int32_t vinput_zero_point1 = quantization_params[1].zero_point;
55 int32_t vacc1x0 = vksum0 * vinput_zero_point1;
56 int32_t vacc1x1 = vksum1 * vinput_zero_point1;
57 int32_t vacc1x2 = vksum2 * vinput_zero_point1;
58 int32_t vacc1x3 = vksum3 * vinput_zero_point1;
59 w = (const int32_t*) w + 4;
60
61 size_t k = kc;
62 do {
63 const int32_t va0 = (int32_t) *a0++;
64 const int32_t va1 = (int32_t) *a1++;
65
66 const int32_t vb0 = (int32_t) ((const int8_t*) w)[0];
67 const int32_t vb1 = (int32_t) ((const int8_t*) w)[1];
68 const int32_t vb2 = (int32_t) ((const int8_t*) w)[2];
69 const int32_t vb3 = (int32_t) ((const int8_t*) w)[3];
70 w = (const int8_t*) w + 4;
71
72 vacc0x0 += va0 * vb0;
73 vacc0x1 += va0 * vb1;
74 vacc0x2 += va0 * vb2;
75 vacc0x3 += va0 * vb3;
76 vacc1x0 += va1 * vb0;
77 vacc1x1 += va1 * vb1;
78 vacc1x2 += va1 * vb2;
79 vacc1x3 += va1 * vb3;
80
81 k -= sizeof(int8_t);
82 } while (k != 0);
83
84 float vout0x0 = (float) vacc0x0;
85 float vout0x1 = (float) vacc0x1;
86 float vout0x2 = (float) vacc0x2;
87 float vout0x3 = (float) vacc0x3;
88 float vout1x0 = (float) vacc1x0;
89 float vout1x1 = (float) vacc1x1;
90 float vout1x2 = (float) vacc1x2;
91 float vout1x3 = (float) vacc1x3;
92
93 const float vinput_scale0 = quantization_params[0].inv_scale;
94 vout0x0 *= vinput_scale0;
95 vout0x1 *= vinput_scale0;
96 vout0x2 *= vinput_scale0;
97 vout0x3 *= vinput_scale0;
98 const float vinput_scale1 = quantization_params[1].inv_scale;
99 vout1x0 *= vinput_scale1;
100 vout1x1 *= vinput_scale1;
101 vout1x2 *= vinput_scale1;
102 vout1x3 *= vinput_scale1;
103
104 const float vfilter_output_scale0 = ((const float*) w)[0];
105 vout0x0 *= vfilter_output_scale0;
106 vout1x0 *= vfilter_output_scale0;
107 const float vfilter_output_scale1 = ((const float*) w)[1];
108 vout0x1 *= vfilter_output_scale1;
109 vout1x1 *= vfilter_output_scale1;
110 const float vfilter_output_scale2 = ((const float*) w)[2];
111 vout0x2 *= vfilter_output_scale2;
112 vout1x2 *= vfilter_output_scale2;
113 const float vfilter_output_scale3 = ((const float*) w)[3];
114 vout0x3 *= vfilter_output_scale3;
115 vout1x3 *= vfilter_output_scale3;
116
117 const float vbias0 = ((const float*) w)[4];
118 vout0x0 += vbias0;
119 vout1x0 += vbias0;
120 const float vbias1 = ((const float*) w)[5];
121 vout0x1 += vbias1;
122 vout1x1 += vbias1;
123 const float vbias2 = ((const float*) w)[6];
124 vout0x2 += vbias2;
125 vout1x2 += vbias2;
126 const float vbias3 = ((const float*) w)[7];
127 vout0x3 += vbias3;
128 vout1x3 += vbias3;
129
130 w = (const float*) w + 8;
131
132 const float voutput_min = params->scalar.min;
133 vout0x0 = __builtin_wasm_max_f32(vout0x0, voutput_min);
134 vout1x0 = __builtin_wasm_max_f32(vout1x0, voutput_min);
135 vout0x1 = __builtin_wasm_max_f32(vout0x1, voutput_min);
136 vout1x1 = __builtin_wasm_max_f32(vout1x1, voutput_min);
137 vout0x2 = __builtin_wasm_max_f32(vout0x2, voutput_min);
138 vout1x2 = __builtin_wasm_max_f32(vout1x2, voutput_min);
139 vout0x3 = __builtin_wasm_max_f32(vout0x3, voutput_min);
140 vout1x3 = __builtin_wasm_max_f32(vout1x3, voutput_min);
141
142 const float voutput_max = params->scalar.max;
143 vout0x0 = __builtin_wasm_min_f32(vout0x0, voutput_max);
144 vout1x0 = __builtin_wasm_min_f32(vout1x0, voutput_max);
145 vout0x1 = __builtin_wasm_min_f32(vout0x1, voutput_max);
146 vout1x1 = __builtin_wasm_min_f32(vout1x1, voutput_max);
147 vout0x2 = __builtin_wasm_min_f32(vout0x2, voutput_max);
148 vout1x2 = __builtin_wasm_min_f32(vout1x2, voutput_max);
149 vout0x3 = __builtin_wasm_min_f32(vout0x3, voutput_max);
150 vout1x3 = __builtin_wasm_min_f32(vout1x3, voutput_max);
151
152 if XNN_LIKELY(nc >= 4) {
153 c0[0] = vout0x0;
154 c0[1] = vout0x1;
155 c0[2] = vout0x2;
156 c0[3] = vout0x3;
157 c1[0] = vout1x0;
158 c1[1] = vout1x1;
159 c1[2] = vout1x2;
160 c1[3] = vout1x3;
161
162 a0 = (const int8_t*) ((uintptr_t) a0 - kc);
163 a1 = (const int8_t*) ((uintptr_t) a1 - kc);
164
165 c0 = (float*) ((uintptr_t) c0 + cn_stride);
166 c1 = (float*) ((uintptr_t) c1 + cn_stride);
167
168 nc -= 4;
169 } else {
170 if (nc & 2) {
171 c0[0] = vout0x0;
172 c0[1] = vout0x1;
173 vout0x0 = vout0x2;
174 c0 += 2;
175 c1[0] = vout1x0;
176 c1[1] = vout1x1;
177 vout1x0 = vout1x2;
178 c1 += 2;
179 }
180 if (nc & 1) {
181 c0[0] = vout0x0;
182 c1[0] = vout1x0;
183 }
184
185 nc = 0;
186 }
187 } while (nc != 0);
188 }