Debian Codegraph @

src/qd8-f32-qc8w-gemm/gen/qd8-f32-qc8w-gemm-1x8-minmax-scalar.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_1x8__scalar(
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 <= 1);
31 assert(nc != 0);
32 assert(kc != 0);
33
34 const int8_t* a0 = a;
35 float* c0 = c;
36
37
38 do {
39 const int32_t vksum0 = ((const int32_t*) w)[0];
40 const int32_t vksum1 = ((const int32_t*) w)[1];
41 const int32_t vksum2 = ((const int32_t*) w)[2];
42 const int32_t vksum3 = ((const int32_t*) w)[3];
43 const int32_t vksum4 = ((const int32_t*) w)[4];
44 const int32_t vksum5 = ((const int32_t*) w)[5];
45 const int32_t vksum6 = ((const int32_t*) w)[6];
46 const int32_t vksum7 = ((const int32_t*) w)[7];
47 const int32_t vinput_zero_point0 = quantization_params[0].zero_point;
48 int32_t vacc0x0 = vksum0 * vinput_zero_point0;
49 int32_t vacc0x1 = vksum1 * vinput_zero_point0;
50 int32_t vacc0x2 = vksum2 * vinput_zero_point0;
51 int32_t vacc0x3 = vksum3 * vinput_zero_point0;
52 int32_t vacc0x4 = vksum4 * vinput_zero_point0;
53 int32_t vacc0x5 = vksum5 * vinput_zero_point0;
54 int32_t vacc0x6 = vksum6 * vinput_zero_point0;
55 int32_t vacc0x7 = vksum7 * vinput_zero_point0;
56 w = (const int32_t*) w + 8;
57
58 size_t k = kc;
59 do {
60 const int32_t va0 = (int32_t) *a0++;
61
62 const int32_t vb0 = (int32_t) ((const int8_t*) w)[0];
63 const int32_t vb1 = (int32_t) ((const int8_t*) w)[1];
64 const int32_t vb2 = (int32_t) ((const int8_t*) w)[2];
65 const int32_t vb3 = (int32_t) ((const int8_t*) w)[3];
66 const int32_t vb4 = (int32_t) ((const int8_t*) w)[4];
67 const int32_t vb5 = (int32_t) ((const int8_t*) w)[5];
68 const int32_t vb6 = (int32_t) ((const int8_t*) w)[6];
69 const int32_t vb7 = (int32_t) ((const int8_t*) w)[7];
70 w = (const int8_t*) w + 8;
71
72 vacc0x0 += va0 * vb0;
73 vacc0x1 += va0 * vb1;
74 vacc0x2 += va0 * vb2;
75 vacc0x3 += va0 * vb3;
76 vacc0x4 += va0 * vb4;
77 vacc0x5 += va0 * vb5;
78 vacc0x6 += va0 * vb6;
79 vacc0x7 += va0 * vb7;
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 vout0x4 = (float) vacc0x4;
89 float vout0x5 = (float) vacc0x5;
90 float vout0x6 = (float) vacc0x6;
91 float vout0x7 = (float) vacc0x7;
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 vout0x4 *= vinput_scale0;
99 vout0x5 *= vinput_scale0;
100 vout0x6 *= vinput_scale0;
101 vout0x7 *= vinput_scale0;
102
103 const float vfilter_output_scale0 = ((const float*) w)[0];
104 vout0x0 *= vfilter_output_scale0;
105 const float vfilter_output_scale1 = ((const float*) w)[1];
106 vout0x1 *= vfilter_output_scale1;
107 const float vfilter_output_scale2 = ((const float*) w)[2];
108 vout0x2 *= vfilter_output_scale2;
109 const float vfilter_output_scale3 = ((const float*) w)[3];
110 vout0x3 *= vfilter_output_scale3;
111 const float vfilter_output_scale4 = ((const float*) w)[4];
112 vout0x4 *= vfilter_output_scale4;
113 const float vfilter_output_scale5 = ((const float*) w)[5];
114 vout0x5 *= vfilter_output_scale5;
115 const float vfilter_output_scale6 = ((const float*) w)[6];
116 vout0x6 *= vfilter_output_scale6;
117 const float vfilter_output_scale7 = ((const float*) w)[7];
118 vout0x7 *= vfilter_output_scale7;
119
120 const float vbias0 = ((const float*) w)[8];
121 vout0x0 += vbias0;
122 const float vbias1 = ((const float*) w)[9];
123 vout0x1 += vbias1;
124 const float vbias2 = ((const float*) w)[10];
125 vout0x2 += vbias2;
126 const float vbias3 = ((const float*) w)[11];
127 vout0x3 += vbias3;
128 const float vbias4 = ((const float*) w)[12];
129 vout0x4 += vbias4;
130 const float vbias5 = ((const float*) w)[13];
131 vout0x5 += vbias5;
132 const float vbias6 = ((const float*) w)[14];
133 vout0x6 += vbias6;
134 const float vbias7 = ((const float*) w)[15];
135 vout0x7 += vbias7;
136
137 w = (const float*) w + 16;
138
139 const float voutput_min = params->scalar.min;
140 vout0x0 = math_max_f32(vout0x0, voutput_min);
141 vout0x1 = math_max_f32(vout0x1, voutput_min);
142 vout0x2 = math_max_f32(vout0x2, voutput_min);
143 vout0x3 = math_max_f32(vout0x3, voutput_min);
144 vout0x4 = math_max_f32(vout0x4, voutput_min);
145 vout0x5 = math_max_f32(vout0x5, voutput_min);
146 vout0x6 = math_max_f32(vout0x6, voutput_min);
147 vout0x7 = math_max_f32(vout0x7, voutput_min);
148
149 const float voutput_max = params->scalar.max;
150 vout0x0 = math_min_f32(vout0x0, voutput_max);
151 vout0x1 = math_min_f32(vout0x1, voutput_max);
152 vout0x2 = math_min_f32(vout0x2, voutput_max);
153 vout0x3 = math_min_f32(vout0x3, voutput_max);
154 vout0x4 = math_min_f32(vout0x4, voutput_max);
155 vout0x5 = math_min_f32(vout0x5, voutput_max);
156 vout0x6 = math_min_f32(vout0x6, voutput_max);
157 vout0x7 = math_min_f32(vout0x7, voutput_max);
158
159 if XNN_LIKELY(nc >= 8) {
160 c0[0] = vout0x0;
161 c0[1] = vout0x1;
162 c0[2] = vout0x2;
163 c0[3] = vout0x3;
164 c0[4] = vout0x4;
165 c0[5] = vout0x5;
166 c0[6] = vout0x6;
167 c0[7] = vout0x7;
168
169 a0 = (const int8_t*) ((uintptr_t) a0 - kc);
170
171 c0 = (float*) ((uintptr_t) c0 + cn_stride);
172
173 nc -= 8;
174 } else {
175 if (nc & 4) {
176 c0[0] = vout0x0;
177 c0[1] = vout0x1;
178 c0[2] = vout0x2;
179 c0[3] = vout0x3;
180 vout0x0 = vout0x4;
181 vout0x1 = vout0x5;
182 vout0x2 = vout0x6;
183 c0 += 4;
184 }
185 if (nc & 2) {
186 c0[0] = vout0x0;
187 c0[1] = vout0x1;
188 vout0x0 = vout0x2;
189 vout0x1 = vout0x3;
190 vout0x2 = vout0x4;
191 vout0x3 = vout0x5;
192 vout0x4 = vout0x6;
193 c0 += 2;
194 }
195 if (nc & 1) {
196 c0[0] = vout0x0;
197 }
198
199 nc = 0;
200 }
201 } while (nc != 0);
202 }