Debian Codegraph @

src/x8-packw/gen/x8-packw-x4-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_x4__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 == 4); // This kernel is for NR=4
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 4
47 const int8_t* w0 = (const int8_t*) weights;
48 size_t n = nc;
49 for (;n >= 4; n -= 4) {
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 b += 4;
56 } else {
57 unaligned_store_s32(out + 0 * sizeof(int32_t), 0);
58 unaligned_store_s32(out + 1 * sizeof(int32_t), 0);
59 unaligned_store_s32(out + 2 * sizeof(int32_t), 0);
60 unaligned_store_s32(out + 3 * sizeof(int32_t), 0);
61 }
62 out += 4 * sizeof(uint32_t);
63
64 const int8_t* w1 = w0 + kc;
65 const int8_t* w2 = w1 + kc;
66 const int8_t* w3 = w2 + kc;
67
68 // KC main loop multiple of 4x2
69 size_t k = kc;
70 for (; k >= 2; k -= 2) {
71 const int8_t v00 = w0[0];
72 const int8_t v01 = w0[1];
73 w0 += 2;
74 const int8_t v10 = w1[0];
75 const int8_t v11 = w1[1];
76 w1 += 2;
77 const int8_t v20 = w2[0];
78 const int8_t v21 = w2[1];
79 w2 += 2;
80 const int8_t v30 = w3[0];
81 const int8_t v31 = w3[1];
82 w3 += 2;
83 out[0] = v00;
84 out[1] = v10;
85 out[2] = v20;
86 out[3] = v30;
87 out[4] = v01;
88 out[5] = v11;
89 out[6] = v21;
90 out[7] = v31;
91 out += 8;
92 }
93
94 // KC remainder
95 for (; k != 0; --k) {
96 const int8_t v0 = *w0++;
97 out[0] = v0;
98 const int8_t v1 = *w1++;
99 out[1] = v1;
100 const int8_t v2 = *w2++;
101 out[2] = v2;
102 const int8_t v3 = *w3++;
103 out[3] = v3;
104 out += 4;
105 }
106 out = (int8_t*) ((uintptr_t) out + extra_bytes);
107 w0 = w3;
108 }
109
110 // NC remainder (1..3)
111 if XNN_UNLIKELY(n != 0) {
112 if XNN_LIKELY(b != NULL) {
113 size_t nb = n;
114 do {
115 unaligned_store_s32(out, *b++);
116 out += sizeof(uint32_t);
117 } while (--nb != 0);
118 } else {
119 size_t nb = n;
120 do {
121 unaligned_store_s32(out, 0);
122 out += sizeof(uint32_t);
123 } while (--nb != 0);
124 }
125 out += (4 - n) * sizeof(uint32_t);
126
127 // NR remainder has less than 4 rows so last row is not loaded
128 const int8_t* w1 = w0 + kc;
129 if XNN_UNPREDICTABLE(n < 2) {
130 w1 = w0;
131 }
132 const int8_t* w2 = w1 + kc;
133 if XNN_UNPREDICTABLE(n <= 2) {
134 w2 = w1;
135 }
136
137 // KC main loop multiple of 4x2
138 size_t k = kc;
139 for (; k >= 2; k -= 2) {
140 const int8_t v00 = w0[0];
141 const int8_t v01 = w0[1];
142 w0 += 2;
143 const int8_t v10 = w1[0];
144 const int8_t v11 = w1[1];
145 w1 += 2;
146 const int8_t v20 = w2[0];
147 const int8_t v21 = w2[1];
148 w2 += 2;
149 out[0] = v00;
150 out[1] = v10;
151 out[2] = v20;
152 out[4] = v01;
153 out[5] = v11;
154 out[6] = v21;
155 out += 8;
156 }
157
158 // KC remainder of 1..1
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 out += 4;
167 }
168 out = (int8_t*) ((uintptr_t) out + extra_bytes);
169 }
170 weights += nc * kc;
171 } while (--g != 0);
172 }