Debian Codegraph @

src/x32-packw/gen/x32-packw-x2-gemm-goi-scalar-float-u4.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/x32-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
18
19
20 void xnn_x32_packw_gemm_goi_ukernel_x2__scalar_float_u4(
21 size_t g,
22 size_t nc,
23 size_t kc,
24 size_t nr,
25 size_t kr,
26 size_t sr,
27 const uint32_t* weights,
28 const uint32_t* bias,
29 const void* scale,
30 uint32_t* packed_weights,
31 size_t extra_bytes,
32 const void* params)
33 {
34 assert(g != 0);
35 assert(nc != 0);
36 assert(kc != 0);
37 assert(nr == 2);
38 assert(kr == 1);
39 assert(sr == 1);
40 assert(weights != NULL);
41 assert(packed_weights != NULL);
42
43 float* out = (float*) packed_weights;
44 const float* b = (const float*) bias;
45
46 do {
47 // NC main loop multiple of 2
48 const float* w0 = (const float*) weights;
49 size_t n = nc;
50 for (;n >= 2; n -= 2) {
51 if XNN_LIKELY(b != NULL) {
52 out[0] = b[0];
53 out[1] = b[1];
54 b += 2;
55 } else {
56 out[0] = 0;
57 out[1] = 0;
58 }
59 out += 2;
60
61 const float* w1 = w0 + kc;
62
63 // KC main loop multiple of 2x4
64 size_t k = kc;
65 for (; k >= 4; k -= 4) {
66 const float v00 = w0[0];
67 const float v01 = w0[1];
68 const float v02 = w0[2];
69 const float v03 = w0[3];
70 w0 += 4;
71 const float v10 = w1[0];
72 const float v11 = w1[1];
73 const float v12 = w1[2];
74 const float v13 = w1[3];
75 w1 += 4;
76 out[0] = v00;
77 out[1] = v10;
78 out[2] = v01;
79 out[3] = v11;
80 out[4] = v02;
81 out[5] = v12;
82 out[6] = v03;
83 out[7] = v13;
84 out += 8;
85 }
86
87 // KC remainder
88 for (; k != 0; --k) {
89 const float v0 = *w0++;
90 out[0] = v0;
91 const float v1 = *w1++;
92 out[1] = v1;
93 out += 2;
94 }
95 out = (float*) ((uintptr_t) out + extra_bytes);
96 w0 = w1;
97 }
98
99 // NC remainder (1..1)
100 if XNN_UNLIKELY(n != 0) {
101 if XNN_LIKELY(b != NULL) {
102 size_t nb = n;
103 do {
104 *out++ = *b++;
105 } while (--nb != 0);
106 } else {
107 size_t nb = n;
108 do {
109 *out++ = 0;
110 } while (--nb != 0);
111 }
112 out += (2 - n);
113
114
115 // KC main loop multiple of 2x4
116 size_t k = kc;
117 for (; k >= 4; k -= 4) {
118 const float v00 = w0[0];
119 const float v01 = w0[1];
120 const float v02 = w0[2];
121 const float v03 = w0[3];
122 w0 += 4;
123 out[0] = v00;
124 out[2] = v01;
125 out[4] = v02;
126 out[6] = v03;
127 out += 8;
128 }
129
130 // KC remainder of 1..3
131 for (; k != 0; --k) {
132 const float v0 = *w0++;
133 out[0] = v0;
134 out += 2;
135 }
136 out = (float*) ((uintptr_t) out + extra_bytes);
137 }
138 weights += nc * kc;
139 } while (--g != 0);
140 }