Debian Codegraph @

src/x8-packw/gen/x8-packw-x8-gemm-goi-scalar-u2.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_u2(
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 8x2
81 size_t k = kc;
82 for (; k >= 2; k -= 2) {
83 const int8_t v00 = w0[0];
84 const int8_t v01 = w0[1];
85 w0 += 2;
86 const int8_t v10 = w1[0];
87 const int8_t v11 = w1[1];
88 w1 += 2;
89 const int8_t v20 = w2[0];
90 const int8_t v21 = w2[1];
91 w2 += 2;
92 const int8_t v30 = w3[0];
93 const int8_t v31 = w3[1];
94 w3 += 2;
95 const int8_t v40 = w4[0];
96 const int8_t v41 = w4[1];
97 w4 += 2;
98 const int8_t v50 = w5[0];
99 const int8_t v51 = w5[1];
100 w5 += 2;
101 const int8_t v60 = w6[0];
102 const int8_t v61 = w6[1];
103 w6 += 2;
104 const int8_t v70 = w7[0];
105 const int8_t v71 = w7[1];
106 w7 += 2;
107 out[0] = v00;
108 out[1] = v10;
109 out[2] = v20;
110 out[3] = v30;
111 out[4] = v40;
112 out[5] = v50;
113 out[6] = v60;
114 out[7] = v70;
115 out[8] = v01;
116 out[9] = v11;
117 out[10] = v21;
118 out[11] = v31;
119 out[12] = v41;
120 out[13] = v51;
121 out[14] = v61;
122 out[15] = v71;
123 out += 16;
124 }
125
126 // KC remainder
127 for (; k != 0; --k) {
128 const int8_t v0 = *w0++;
129 out[0] = v0;
130 const int8_t v1 = *w1++;
131 out[1] = v1;
132 const int8_t v2 = *w2++;
133 out[2] = v2;
134 const int8_t v3 = *w3++;
135 out[3] = v3;
136 const int8_t v4 = *w4++;
137 out[4] = v4;
138 const int8_t v5 = *w5++;
139 out[5] = v5;
140 const int8_t v6 = *w6++;
141 out[6] = v6;
142 const int8_t v7 = *w7++;
143 out[7] = v7;
144 out += 8;
145 }
146 out = (int8_t*) ((uintptr_t) out + extra_bytes);
147 w0 = w7;
148 }
149
150 // NC remainder (1..7)
151 if XNN_UNLIKELY(n != 0) {
152 if XNN_LIKELY(b != NULL) {
153 size_t nb = n;
154 do {
155 unaligned_store_s32(out, *b++);
156 out += sizeof(uint32_t);
157 } while (--nb != 0);
158 } else {
159 size_t nb = n;
160 do {
161 unaligned_store_s32(out, 0);
162 out += sizeof(uint32_t);
163 } while (--nb != 0);
164 }
165 out += (8 - n) * sizeof(uint32_t);
166
167 // NR remainder has less than 8 rows so last row is not loaded
168 const int8_t* w1 = w0 + kc;
169 if XNN_UNPREDICTABLE(n < 2) {
170 w1 = w0;
171 }
172 const int8_t* w2 = w1 + kc;
173 if XNN_UNPREDICTABLE(n <= 2) {
174 w2 = w1;
175 }
176 const int8_t* w3 = w2 + kc;
177 if XNN_UNPREDICTABLE(n < 4) {
178 w3 = w2;
179 }
180 const int8_t* w4 = w3 + kc;
181 if XNN_UNPREDICTABLE(n <= 4) {
182 w4 = w3;
183 }
184 const int8_t* w5 = w4 + kc;
185 if XNN_UNPREDICTABLE(n < 6) {
186 w5 = w4;
187 }
188 const int8_t* w6 = w5 + kc;
189 if XNN_UNPREDICTABLE(n <= 6) {
190 w6 = w5;
191 }
192
193 // KC main loop multiple of 8x2
194 size_t k = kc;
195 for (; k >= 2; k -= 2) {
196 const int8_t v00 = w0[0];
197 const int8_t v01 = w0[1];
198 w0 += 2;
199 const int8_t v10 = w1[0];
200 const int8_t v11 = w1[1];
201 w1 += 2;
202 const int8_t v20 = w2[0];
203 const int8_t v21 = w2[1];
204 w2 += 2;
205 const int8_t v30 = w3[0];
206 const int8_t v31 = w3[1];
207 w3 += 2;
208 const int8_t v40 = w4[0];
209 const int8_t v41 = w4[1];
210 w4 += 2;
211 const int8_t v50 = w5[0];
212 const int8_t v51 = w5[1];
213 w5 += 2;
214 const int8_t v60 = w6[0];
215 const int8_t v61 = w6[1];
216 w6 += 2;
217 out[0] = v00;
218 out[1] = v10;
219 out[2] = v20;
220 out[3] = v30;
221 out[4] = v40;
222 out[5] = v50;
223 out[6] = v60;
224 out[8] = v01;
225 out[9] = v11;
226 out[10] = v21;
227 out[11] = v31;
228 out[12] = v41;
229 out[13] = v51;
230 out[14] = v61;
231 out += 16;
232 }
233
234 // KC remainder of 1..1
235 for (; k != 0; --k) {
236 const int8_t v0 = *w0++;
237 out[0] = v0;
238 const int8_t v1 = *w1++;
239 out[1] = v1;
240 const int8_t v2 = *w2++;
241 out[2] = v2;
242 const int8_t v3 = *w3++;
243 out[3] = v3;
244 const int8_t v4 = *w4++;
245 out[4] = v4;
246 const int8_t v5 = *w5++;
247 out[5] = v5;
248 const int8_t v6 = *w6++;
249 out[6] = v6;
250 out += 8;
251 }
252 out = (int8_t*) ((uintptr_t) out + extra_bytes);
253 }
254 weights += nc * kc;
255 } while (--g != 0);
256 }