Debian Codegraph @

src/x8-packw/gen/x8-packw-x2-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_x2__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 == 2); // This kernel is for NR=2
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 2
47 const int8_t* w0 = (const int8_t*) weights;
48 size_t n = nc;
49 for (;n >= 2; n -= 2) {
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 b += 2;
54 } else {
55 unaligned_store_s32(out + 0 * sizeof(int32_t), 0);
56 unaligned_store_s32(out + 1 * sizeof(int32_t), 0);
57 }
58 out += 2 * sizeof(uint32_t);
59
60 const int8_t* w1 = w0 + kc;
61
62 // KC main loop multiple of 2x4
63 size_t k = kc;
64 for (; k >= 4; k -= 4) {
65 const int8_t v00 = w0[0];
66 const int8_t v01 = w0[1];
67 const int8_t v02 = w0[2];
68 const int8_t v03 = w0[3];
69 w0 += 4;
70 const int8_t v10 = w1[0];
71 const int8_t v11 = w1[1];
72 const int8_t v12 = w1[2];
73 const int8_t v13 = w1[3];
74 w1 += 4;
75 out[0] = v00;
76 out[1] = v10;
77 out[2] = v01;
78 out[3] = v11;
79 out[4] = v02;
80 out[5] = v12;
81 out[6] = v03;
82 out[7] = v13;
83 out += 8;
84 }
85
86 // KC remainder
87 for (; k != 0; --k) {
88 const int8_t v0 = *w0++;
89 out[0] = v0;
90 const int8_t v1 = *w1++;
91 out[1] = v1;
92 out += 2;
93 }
94 out = (int8_t*) ((uintptr_t) out + extra_bytes);
95 w0 = w1;
96 }
97
98 // NC remainder (1..1)
99 if XNN_UNLIKELY(n != 0) {
100 if XNN_LIKELY(b != NULL) {
101 size_t nb = n;
102 do {
103 unaligned_store_s32(out, *b++);
104 out += sizeof(uint32_t);
105 } while (--nb != 0);
106 } else {
107 size_t nb = n;
108 do {
109 unaligned_store_s32(out, 0);
110 out += sizeof(uint32_t);
111 } while (--nb != 0);
112 }
113 out += (2 - n) * sizeof(uint32_t);
114
115
116 // KC main loop multiple of 2x4
117 size_t k = kc;
118 for (; k >= 4; k -= 4) {
119 const int8_t v00 = w0[0];
120 const int8_t v01 = w0[1];
121 const int8_t v02 = w0[2];
122 const int8_t v03 = w0[3];
123 w0 += 4;
124 out[0] = v00;
125 out[2] = v01;
126 out[4] = v02;
127 out[6] = v03;
128 out += 8;
129 }
130
131 // KC remainder of 1..3
132 for (; k != 0; --k) {
133 const int8_t v0 = *w0++;
134 out[0] = v0;
135 out += 2;
136 }
137 out = (int8_t*) ((uintptr_t) out + extra_bytes);
138 }
139 weights += nc * kc;
140 } while (--g != 0);
141 }