Debian Codegraph @

src/x8-packw/gen/x8-packw-x8-gemm-goi-scalar-u4.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/x8-packw/scalar.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2023 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
11 #include <assert.h>
12 #include <stddef.h>
13 #include <stdint.h>
14
15 #include "xnnpack/math.h"
16 #include "xnnpack/packw.h"
17 #include "xnnpack/unaligned.h"
18
19 void xnn_x8_packw_gemm_goi_ukernel_x8__scalar_u4(
20 size_t g,
21 size_t nc,
22 size_t kc,
23 size_t nr,
24 size_t kr,
25 size_t sr,
26 const int8_t* weights,
27 const uint32_t* bias,
28 const void* scale,
29 int8_t* packed_weights,
30 size_t extra_bytes,
31 const void* params)
32 {
33 assert(g != 0);
34 assert(nc != 0);
35 assert(kc != 0);
36 assert(nr == 8); // This kernel is for NR=8
37 assert(kr == 1);
38 assert(sr == 1);
39 assert(weights != NULL);
40 assert(packed_weights != NULL);
41
42 int8_t* out = (int8_t*) packed_weights;
43 const uint32_t* b = (const uint32_t*) bias;
44
45 do {
46 // NC main loop multiple of 8
47 const int8_t* w0 = (const int8_t*) weights;
48 size_t n = nc;
49 for (;n >= 8; n -= 8) {
50 if XNN_LIKELY(b != NULL) {
51 unaligned_store_s32(out + 0 * sizeof(int32_t), b[0]);
52 unaligned_store_s32(out + 1 * sizeof(int32_t), b[1]);
53 unaligned_store_s32(out + 2 * sizeof(int32_t), b[2]);
54 unaligned_store_s32(out + 3 * sizeof(int32_t), b[3]);
55 unaligned_store_s32(out + 4 * sizeof(int32_t), b[4]);
56 unaligned_store_s32(out + 5 * sizeof(int32_t), b[5]);
57 unaligned_store_s32(out + 6 * sizeof(int32_t), b[6]);
58 unaligned_store_s32(out + 7 * sizeof(int32_t), b[7]);
59 b += 8;
60 } else {
61 unaligned_store_s32(out + 0 * sizeof(int32_t), 0);
62 unaligned_store_s32(out + 1 * sizeof(int32_t), 0);
63 unaligned_store_s32(out + 2 * sizeof(int32_t), 0);
64 unaligned_store_s32(out + 3 * sizeof(int32_t), 0);
65 unaligned_store_s32(out + 4 * sizeof(int32_t), 0);
66 unaligned_store_s32(out + 5 * sizeof(int32_t), 0);
67 unaligned_store_s32(out + 6 * sizeof(int32_t), 0);
68 unaligned_store_s32(out + 7 * sizeof(int32_t), 0);
69 }
70 out += 8 * sizeof(uint32_t);
71
72 const int8_t* w1 = w0 + kc;
73 const int8_t* w2 = w1 + kc;
74 const int8_t* w3 = w2 + kc;
75 const int8_t* w4 = w3 + kc;
76 const int8_t* w5 = w4 + kc;
77 const int8_t* w6 = w5 + kc;
78 const int8_t* w7 = w6 + kc;
79
80 // KC main loop multiple of 8x4
81 size_t k = kc;
82 for (; k >= 4; k -= 4) {
83 const int8_t v00 = w0[0];
84 const int8_t v01 = w0[1];
85 const int8_t v02 = w0[2];
86 const int8_t v03 = w0[3];
87 w0 += 4;
88 const int8_t v10 = w1[0];
89 const int8_t v11 = w1[1];
90 const int8_t v12 = w1[2];
91 const int8_t v13 = w1[3];
92 w1 += 4;
93 const int8_t v20 = w2[0];
94 const int8_t v21 = w2[1];
95 const int8_t v22 = w2[2];
96 const int8_t v23 = w2[3];
97 w2 += 4;
98 const int8_t v30 = w3[0];
99 const int8_t v31 = w3[1];
100 const int8_t v32 = w3[2];
101 const int8_t v33 = w3[3];
102 w3 += 4;
103 const int8_t v40 = w4[0];
104 const int8_t v41 = w4[1];
105 const int8_t v42 = w4[2];
106 const int8_t v43 = w4[3];
107 w4 += 4;
108 const int8_t v50 = w5[0];
109 const int8_t v51 = w5[1];
110 const int8_t v52 = w5[2];
111 const int8_t v53 = w5[3];
112 w5 += 4;
113 const int8_t v60 = w6[0];
114 const int8_t v61 = w6[1];
115 const int8_t v62 = w6[2];
116 const int8_t v63 = w6[3];
117 w6 += 4;
118 const int8_t v70 = w7[0];
119 const int8_t v71 = w7[1];
120 const int8_t v72 = w7[2];
121 const int8_t v73 = w7[3];
122 w7 += 4;
123 out[0] = v00;
124 out[1] = v10;
125 out[2] = v20;
126 out[3] = v30;
127 out[4] = v40;
128 out[5] = v50;
129 out[6] = v60;
130 out[7] = v70;
131 out[8] = v01;
132 out[9] = v11;
133 out[10] = v21;
134 out[11] = v31;
135 out[12] = v41;
136 out[13] = v51;
137 out[14] = v61;
138 out[15] = v71;
139 out[16] = v02;
140 out[17] = v12;
141 out[18] = v22;
142 out[19] = v32;
143 out[20] = v42;
144 out[21] = v52;
145 out[22] = v62;
146 out[23] = v72;
147 out[24] = v03;
148 out[25] = v13;
149 out[26] = v23;
150 out[27] = v33;
151 out[28] = v43;
152 out[29] = v53;
153 out[30] = v63;
154 out[31] = v73;
155 out += 32;
156 }
157
158 // KC remainder
159 for (; k != 0; --k) {
160 const int8_t v0 = *w0++;
161 out[0] = v0;
162 const int8_t v1 = *w1++;
163 out[1] = v1;
164 const int8_t v2 = *w2++;
165 out[2] = v2;
166 const int8_t v3 = *w3++;
167 out[3] = v3;
168 const int8_t v4 = *w4++;
169 out[4] = v4;
170 const int8_t v5 = *w5++;
171 out[5] = v5;
172 const int8_t v6 = *w6++;
173 out[6] = v6;
174 const int8_t v7 = *w7++;
175 out[7] = v7;
176 out += 8;
177 }
178 out = (int8_t*) ((uintptr_t) out + extra_bytes);
179 w0 = w7;
180 }
181
182 // NC remainder (1..7)
183 if XNN_UNLIKELY(n != 0) {
184 if XNN_LIKELY(b != NULL) {
185 size_t nb = n;
186 do {
187 unaligned_store_s32(out, *b++);
188 out += sizeof(uint32_t);
189 } while (--nb != 0);
190 } else {
191 size_t nb = n;
192 do {
193 unaligned_store_s32(out, 0);
194 out += sizeof(uint32_t);
195 } while (--nb != 0);
196 }
197 out += (8 - n) * sizeof(uint32_t);
198
199 // NR remainder has less than 8 rows so last row is not loaded
200 const int8_t* w1 = w0 + kc;
201 if XNN_UNPREDICTABLE(n < 2) {
202 w1 = w0;
203 }
204 const int8_t* w2 = w1 + kc;
205 if XNN_UNPREDICTABLE(n <= 2) {
206 w2 = w1;
207 }
208 const int8_t* w3 = w2 + kc;
209 if XNN_UNPREDICTABLE(n < 4) {
210 w3 = w2;
211 }
212 const int8_t* w4 = w3 + kc;
213 if XNN_UNPREDICTABLE(n <= 4) {
214 w4 = w3;
215 }
216 const int8_t* w5 = w4 + kc;
217 if XNN_UNPREDICTABLE(n < 6) {
218 w5 = w4;
219 }
220 const int8_t* w6 = w5 + kc;
221 if XNN_UNPREDICTABLE(n <= 6) {
222 w6 = w5;
223 }
224
225 // KC main loop multiple of 8x4
226 size_t k = kc;
227 for (; k >= 4; k -= 4) {
228 const int8_t v00 = w0[0];
229 const int8_t v01 = w0[1];
230 const int8_t v02 = w0[2];
231 const int8_t v03 = w0[3];
232 w0 += 4;
233 const int8_t v10 = w1[0];
234 const int8_t v11 = w1[1];
235 const int8_t v12 = w1[2];
236 const int8_t v13 = w1[3];
237 w1 += 4;
238 const int8_t v20 = w2[0];
239 const int8_t v21 = w2[1];
240 const int8_t v22 = w2[2];
241 const int8_t v23 = w2[3];
242 w2 += 4;
243 const int8_t v30 = w3[0];
244 const int8_t v31 = w3[1];
245 const int8_t v32 = w3[2];
246 const int8_t v33 = w3[3];
247 w3 += 4;
248 const int8_t v40 = w4[0];
249 const int8_t v41 = w4[1];
250 const int8_t v42 = w4[2];
251 const int8_t v43 = w4[3];
252 w4 += 4;
253 const int8_t v50 = w5[0];
254 const int8_t v51 = w5[1];
255 const int8_t v52 = w5[2];
256 const int8_t v53 = w5[3];
257 w5 += 4;
258 const int8_t v60 = w6[0];
259 const int8_t v61 = w6[1];
260 const int8_t v62 = w6[2];
261 const int8_t v63 = w6[3];
262 w6 += 4;
263 out[0] = v00;
264 out[1] = v10;
265 out[2] = v20;
266 out[3] = v30;
267 out[4] = v40;
268 out[5] = v50;
269 out[6] = v60;
270 out[8] = v01;
271 out[9] = v11;
272 out[10] = v21;
273 out[11] = v31;
274 out[12] = v41;
275 out[13] = v51;
276 out[14] = v61;
277 out[16] = v02;
278 out[17] = v12;
279 out[18] = v22;
280 out[19] = v32;
281 out[20] = v42;
282 out[21] = v52;
283 out[22] = v62;
284 out[24] = v03;
285 out[25] = v13;
286 out[26] = v23;
287 out[27] = v33;
288 out[28] = v43;
289 out[29] = v53;
290 out[30] = v63;
291 out += 32;
292 }
293
294 // KC remainder of 1..3
295 for (; k != 0; --k) {
296 const int8_t v0 = *w0++;
297 out[0] = v0;
298 const int8_t v1 = *w1++;
299 out[1] = v1;
300 const int8_t v2 = *w2++;
301 out[2] = v2;
302 const int8_t v3 = *w3++;
303 out[3] = v3;
304 const int8_t v4 = *w4++;
305 out[4] = v4;
306 const int8_t v5 = *w5++;
307 out[5] = v5;
308 const int8_t v6 = *w6++;
309 out[6] = v6;
310 out += 8;
311 }
312 out = (int8_t*) ((uintptr_t) out + extra_bytes);
313 }
314 weights += nc * kc;
315 } while (--g != 0);
316 }