Debian Codegraph @

src/x8-packw/gen/x8-packw-x2-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_x2__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 == 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 2x2
63 size_t k = kc;
64 for (; k >= 2; k -= 2) {
65 const int8_t v00 = w0[0];
66 const int8_t v01 = w0[1];
67 w0 += 2;
68 const int8_t v10 = w1[0];
69 const int8_t v11 = w1[1];
70 w1 += 2;
71 out[0] = v00;
72 out[1] = v10;
73 out[2] = v01;
74 out[3] = v11;
75 out += 4;
76 }
77
78 // KC remainder
79 for (; k != 0; --k) {
80 const int8_t v0 = *w0++;
81 out[0] = v0;
82 const int8_t v1 = *w1++;
83 out[1] = v1;
84 out += 2;
85 }
86 out = (int8_t*) ((uintptr_t) out + extra_bytes);
87 w0 = w1;
88 }
89
90 // NC remainder (1..1)
91 if XNN_UNLIKELY(n != 0) {
92 if XNN_LIKELY(b != NULL) {
93 size_t nb = n;
94 do {
95 unaligned_store_s32(out, *b++);
96 out += sizeof(uint32_t);
97 } while (--nb != 0);
98 } else {
99 size_t nb = n;
100 do {
101 unaligned_store_s32(out, 0);
102 out += sizeof(uint32_t);
103 } while (--nb != 0);
104 }
105 out += (2 - n) * sizeof(uint32_t);
106
107
108 // KC main loop multiple of 2x2
109 size_t k = kc;
110 for (; k >= 2; k -= 2) {
111 const int8_t v00 = w0[0];
112 const int8_t v01 = w0[1];
113 w0 += 2;
114 out[0] = v00;
115 out[2] = v01;
116 out += 4;
117 }
118
119 // KC remainder of 1..1
120 for (; k != 0; --k) {
121 const int8_t v0 = *w0++;
122 out[0] = v0;
123 out += 2;
124 }
125 out = (int8_t*) ((uintptr_t) out + extra_bytes);
126 }
127 weights += nc * kc;
128 } while (--g != 0);
129 }