Debian Codegraph @

src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-2x4-minmax-fp32-wasm-fmagic.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_qs8_qc8w_igemm_minmax_fp32_ukernel_2x4__wasm_fmagic(
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 int8_t* restrict c,
24 size_t cm_stride,
25 size_t cn_stride,
26 size_t a_offset,
27 const int8_t* zero,
28 const union xnn_qs8_qc8w_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)])
29 {
30 assert(mr != 0);
31 assert(mr <= 2);
32 assert(nc != 0);
33 assert(kc != 0);
34 assert(ks != 0);
35 assert(ks % (2 * sizeof(void*)) == 0);
36 assert(a != NULL);
37 assert(w != NULL);
38 assert(c != NULL);
39
40 int8_t* c0 = c;
41 int8_t* c1 = (int8_t*) ((uintptr_t) c0 + cm_stride);
42 if XNN_UNPREDICTABLE(mr != 2) {
43 c1 = c0;
44 }
45
46 const int32_t output_min_less_zero_point = (int32_t) params->fp32_scalar.output_min - (int32_t) params->fp32_scalar.output_zero_point;
47 const int32_t output_max_less_zero_point = (int32_t) params->fp32_scalar.output_max - (int32_t) params->fp32_scalar.output_zero_point;
48 const float voutput_min_less_zero_point = output_min_less_zero_point;
49 const float voutput_max_less_zero_point = output_max_less_zero_point;
50 const float vmagic_bias = 12582912.0f;
51 const int32_t vmagic_bias_less_output_zero_point = INT32_C(0x4B400000) - (int32_t) params->fp32_scalar.output_zero_point;
52
53 do {
54 int32_t vacc0x0 = ((const int32_t*) w)[0];
55 int32_t vacc0x1 = ((const int32_t*) w)[1];
56 int32_t vacc0x2 = ((const int32_t*) w)[2];
57 int32_t vacc0x3 = ((const int32_t*) w)[3];
58 int32_t vacc1x0 = vacc0x0;
59 int32_t vacc1x1 = vacc0x1;
60 int32_t vacc1x2 = vacc0x2;
61 int32_t vacc1x3 = vacc0x3;
62 w = (const void*) ((const int32_t*) w + 4);
63
64 size_t p = ks;
65 do {
66 const int8_t* restrict a0 = a[0];
67 assert(a0 != NULL);
68 if XNN_UNPREDICTABLE(a0 != zero) {
69 a0 = (const int8_t*) ((uintptr_t) a0 + a_offset);
70 }
71 const int8_t* restrict a1 = a[1];
72 assert(a1 != NULL);
73 if XNN_UNPREDICTABLE(a1 != zero) {
74 a1 = (const int8_t*) ((uintptr_t) a1 + a_offset);
75 }
76 a += 2;
77
78 size_t k = kc;
79 do {
80 const int32_t va0 = (int32_t) *a0++;
81 const int32_t va1 = (int32_t) *a1++;
82
83 const int32_t vb0 = (int32_t) ((const int8_t*) w)[0];
84 const int32_t vb1 = (int32_t) ((const int8_t*) w)[1];
85 const int32_t vb2 = (int32_t) ((const int8_t*) w)[2];
86 const int32_t vb3 = (int32_t) ((const int8_t*) w)[3];
87 w = (const void*) ((const int8_t*) w + 4);
88
89 vacc0x0 += va0 * vb0;
90 vacc0x1 += va0 * vb1;
91 vacc0x2 += va0 * vb2;
92 vacc0x3 += va0 * vb3;
93 vacc1x0 += va1 * vb0;
94 vacc1x1 += va1 * vb1;
95 vacc1x2 += va1 * vb2;
96 vacc1x3 += va1 * vb3;
97
98 k -= sizeof(int8_t);
99 } while (k != 0);
100 p -= 2 * sizeof(void*);
101 } while (p != 0);
102
103 float vfpacc0x0 = (float) vacc0x0;
104 float vfpacc0x1 = (float) vacc0x1;
105 float vfpacc0x2 = (float) vacc0x2;
106 float vfpacc0x3 = (float) vacc0x3;
107 float vfpacc1x0 = (float) vacc1x0;
108 float vfpacc1x1 = (float) vacc1x1;
109 float vfpacc1x2 = (float) vacc1x2;
110 float vfpacc1x3 = (float) vacc1x3;
111
112 const float vscale0 = ((const float*) w)[0];
113 vfpacc0x0 *= vscale0;
114 vfpacc1x0 *= vscale0;
115 const float vscale1 = ((const float*) w)[1];
116 vfpacc0x1 *= vscale1;
117 vfpacc1x1 *= vscale1;
118 const float vscale2 = ((const float*) w)[2];
119 vfpacc0x2 *= vscale2;
120 vfpacc1x2 *= vscale2;
121 const float vscale3 = ((const float*) w)[3];
122 vfpacc0x3 *= vscale3;
123 vfpacc1x3 *= vscale3;
124 w = (const void*) ((const float*) w + 4);
125
126 vfpacc0x0 = __builtin_wasm_max_f32(vfpacc0x0, voutput_min_less_zero_point);
127 vfpacc0x1 = __builtin_wasm_max_f32(vfpacc0x1, voutput_min_less_zero_point);
128 vfpacc0x2 = __builtin_wasm_max_f32(vfpacc0x2, voutput_min_less_zero_point);
129 vfpacc0x3 = __builtin_wasm_max_f32(vfpacc0x3, voutput_min_less_zero_point);
130 vfpacc1x0 = __builtin_wasm_max_f32(vfpacc1x0, voutput_min_less_zero_point);
131 vfpacc1x1 = __builtin_wasm_max_f32(vfpacc1x1, voutput_min_less_zero_point);
132 vfpacc1x2 = __builtin_wasm_max_f32(vfpacc1x2, voutput_min_less_zero_point);
133 vfpacc1x3 = __builtin_wasm_max_f32(vfpacc1x3, voutput_min_less_zero_point);
134
135 vfpacc0x0 = __builtin_wasm_min_f32(vfpacc0x0, voutput_max_less_zero_point);
136 vfpacc0x1 = __builtin_wasm_min_f32(vfpacc0x1, voutput_max_less_zero_point);
137 vfpacc0x2 = __builtin_wasm_min_f32(vfpacc0x2, voutput_max_less_zero_point);
138 vfpacc0x3 = __builtin_wasm_min_f32(vfpacc0x3, voutput_max_less_zero_point);
139 vfpacc1x0 = __builtin_wasm_min_f32(vfpacc1x0, voutput_max_less_zero_point);
140 vfpacc1x1 = __builtin_wasm_min_f32(vfpacc1x1, voutput_max_less_zero_point);
141 vfpacc1x2 = __builtin_wasm_min_f32(vfpacc1x2, voutput_max_less_zero_point);
142 vfpacc1x3 = __builtin_wasm_min_f32(vfpacc1x3, voutput_max_less_zero_point);
143
144 vfpacc0x0 += vmagic_bias;
145 vfpacc0x1 += vmagic_bias;
146 vfpacc0x2 += vmagic_bias;
147 vfpacc0x3 += vmagic_bias;
148 vfpacc1x0 += vmagic_bias;
149 vfpacc1x1 += vmagic_bias;
150 vfpacc1x2 += vmagic_bias;
151 vfpacc1x3 += vmagic_bias;
152
153 int32_t vout0x0 = (int32_t) float_as_uint32(vfpacc0x0) - vmagic_bias_less_output_zero_point;
154 int32_t vout0x1 = (int32_t) float_as_uint32(vfpacc0x1) - vmagic_bias_less_output_zero_point;
155 int32_t vout0x2 = (int32_t) float_as_uint32(vfpacc0x2) - vmagic_bias_less_output_zero_point;
156 int32_t vout0x3 = (int32_t) float_as_uint32(vfpacc0x3) - vmagic_bias_less_output_zero_point;
157 int32_t vout1x0 = (int32_t) float_as_uint32(vfpacc1x0) - vmagic_bias_less_output_zero_point;
158 int32_t vout1x1 = (int32_t) float_as_uint32(vfpacc1x1) - vmagic_bias_less_output_zero_point;
159 int32_t vout1x2 = (int32_t) float_as_uint32(vfpacc1x2) - vmagic_bias_less_output_zero_point;
160 int32_t vout1x3 = (int32_t) float_as_uint32(vfpacc1x3) - vmagic_bias_less_output_zero_point;
161
162 if XNN_LIKELY(nc >= 4) {
163 c1[0] = (int8_t) vout1x0;
164 c1[1] = (int8_t) vout1x1;
165 c1[2] = (int8_t) vout1x2;
166 c1[3] = (int8_t) vout1x3;
167 c0[0] = (int8_t) vout0x0;
168 c0[1] = (int8_t) vout0x1;
169 c0[2] = (int8_t) vout0x2;
170 c0[3] = (int8_t) vout0x3;
171
172 c1 = (int8_t*) ((uintptr_t) c1 + cn_stride);
173 c0 = (int8_t*) ((uintptr_t) c0 + cn_stride);
174
175 a = (const int8_t**restrict) ((uintptr_t) a - ks);
176 nc -= 4;
177 } else {
178 if (nc & 2) {
179 c1[0] = (int8_t) vout1x0;
180 c1[1] = (int8_t) vout1x1;
181 vout1x0 = vout1x2;
182 c1 += 2;
183 c0[0] = (int8_t) vout0x0;
184 c0[1] = (int8_t) vout0x1;
185 vout0x0 = vout0x2;
186 c0 += 2;
187 }
188 if (nc & 1) {
189 c1[0] = (int8_t) vout1x0;
190 c0[0] = (int8_t) vout0x0;
191 }
192
193 nc = 0;
194 }
195 } while (nc != 0);
196 }