Debian Codegraph @

src/qu8-igemm/gen/qu8-igemm-2x4-minmax-rndnu-scalar.c

raw symbols SCIP
1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-igemm/scalar.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2021 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 #include <assert.h>
11
12 #include "xnnpack/math.h"
13 #include "xnnpack/gemm.h"
14
15
16 void xnn_qu8_igemm_minmax_rndnu_ukernel_2x4__scalar(
17 size_t mr,
18 size_t nc,
19 size_t kc,
20 size_t ks,
21 const uint8_t** restrict a,
22 const void* restrict w,
23 uint8_t* restrict c,
24 size_t cm_stride,
25 size_t cn_stride,
26 size_t a_offset,
27 const uint8_t* zero,
28 const union xnn_qu8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)])
29 {
30 assert(mr != 0);
31 assert(mr <= 2);
32 assert(nc != 0);
33 assert(kc != 0);
34 assert(ks != 0);
35 assert(ks % (2 * sizeof(void*)) == 0);
36 assert(a != NULL);
37 assert(w != NULL);
38 assert(c != NULL);
39
40 uint8_t* c0 = c;
41 uint8_t* c1 = (uint8_t*) ((uintptr_t) c0 + cm_stride);
42 if XNN_UNPREDICTABLE(mr != 2) {
43 c1 = c0;
44 }
45
46 const int32_t vmultiplier = params->rndnu_scalar.multiplier;
47 const int64_t vrounding = params->rndnu_scalar.rounding;
48 const uint32_t vshift = params->rndnu_scalar.shift;
49 const int32_t voutput_min_less_zero_point = (int32_t) params->rndnu_scalar.output_min - (int32_t) params->rndnu_scalar.output_zero_point;
50 const int32_t voutput_max_less_zero_point = (int32_t) params->rndnu_scalar.output_max - (int32_t) params->rndnu_scalar.output_zero_point;
51 const int32_t voutput_zero_point = params->rndnu_scalar.output_zero_point;
52
53 const int32_t vb_zero_point = params->rndnu_scalar.kernel_zero_point;
54 do {
55 int32_t vacc0x0 = ((const int32_t*) w)[0];
56 int32_t vacc0x1 = ((const int32_t*) w)[1];
57 int32_t vacc0x2 = ((const int32_t*) w)[2];
58 int32_t vacc0x3 = ((const int32_t*) w)[3];
59 int32_t vacc1x0 = vacc0x0;
60 int32_t vacc1x1 = vacc0x1;
61 int32_t vacc1x2 = vacc0x2;
62 int32_t vacc1x3 = vacc0x3;
63 w = (const void*) ((const int32_t*) w + 4);
64
65 size_t p = ks;
66 do {
67 const uint8_t* restrict a0 = a[0];
68 assert(a0 != NULL);
69 if XNN_UNPREDICTABLE(a0 != zero) {
70 a0 = (const uint8_t*) ((uintptr_t) a0 + a_offset);
71 }
72 const uint8_t* restrict a1 = a[1];
73 assert(a1 != NULL);
74 if XNN_UNPREDICTABLE(a1 != zero) {
75 a1 = (const uint8_t*) ((uintptr_t) a1 + a_offset);
76 }
77 a += 2;
78
79 size_t k = kc;
80 do {
81 const int32_t va0 = (int32_t) (uint32_t) *a0++;
82 const int32_t va1 = (int32_t) (uint32_t) *a1++;
83
84 const int32_t vb0 = (int32_t) (uint32_t) ((const uint8_t*) w)[0] - vb_zero_point;
85 const int32_t vb1 = (int32_t) (uint32_t) ((const uint8_t*) w)[1] - vb_zero_point;
86 const int32_t vb2 = (int32_t) (uint32_t) ((const uint8_t*) w)[2] - vb_zero_point;
87 const int32_t vb3 = (int32_t) (uint32_t) ((const uint8_t*) w)[3] - vb_zero_point;
88 w = (const void*) ((const uint8_t*) w + 4);
89
90 vacc0x0 += va0 * vb0;
91 vacc0x1 += va0 * vb1;
92 vacc0x2 += va0 * vb2;
93 vacc0x3 += va0 * vb3;
94 vacc1x0 += va1 * vb0;
95 vacc1x1 += va1 * vb1;
96 vacc1x2 += va1 * vb2;
97 vacc1x3 += va1 * vb3;
98
99 k -= sizeof(uint8_t);
100 } while (k != 0);
101 p -= 2 * sizeof(void*);
102 } while (p != 0);
103
104 const int64_t vextacc0x0 = math_mulext_s32(vacc0x0, vmultiplier) + vrounding;
105 const int64_t vextacc0x1 = math_mulext_s32(vacc0x1, vmultiplier) + vrounding;
106 const int64_t vextacc0x2 = math_mulext_s32(vacc0x2, vmultiplier) + vrounding;
107 const int64_t vextacc0x3 = math_mulext_s32(vacc0x3, vmultiplier) + vrounding;
108 const int64_t vextacc1x0 = math_mulext_s32(vacc1x0, vmultiplier) + vrounding;
109 const int64_t vextacc1x1 = math_mulext_s32(vacc1x1, vmultiplier) + vrounding;
110 const int64_t vextacc1x2 = math_mulext_s32(vacc1x2, vmultiplier) + vrounding;
111 const int64_t vextacc1x3 = math_mulext_s32(vacc1x3, vmultiplier) + vrounding;
112
113 int32_t vout0x0 = (int32_t) math_asr_s64(vextacc0x0, vshift);
114 int32_t vout0x1 = (int32_t) math_asr_s64(vextacc0x1, vshift);
115 int32_t vout0x2 = (int32_t) math_asr_s64(vextacc0x2, vshift);
116 int32_t vout0x3 = (int32_t) math_asr_s64(vextacc0x3, vshift);
117 int32_t vout1x0 = (int32_t) math_asr_s64(vextacc1x0, vshift);
118 int32_t vout1x1 = (int32_t) math_asr_s64(vextacc1x1, vshift);
119 int32_t vout1x2 = (int32_t) math_asr_s64(vextacc1x2, vshift);
120 int32_t vout1x3 = (int32_t) math_asr_s64(vextacc1x3, vshift);
121
122 vout0x0 = math_max_s32(vout0x0, voutput_min_less_zero_point);
123 vout0x1 = math_max_s32(vout0x1, voutput_min_less_zero_point);
124 vout0x2 = math_max_s32(vout0x2, voutput_min_less_zero_point);
125 vout0x3 = math_max_s32(vout0x3, voutput_min_less_zero_point);
126 vout1x0 = math_max_s32(vout1x0, voutput_min_less_zero_point);
127 vout1x1 = math_max_s32(vout1x1, voutput_min_less_zero_point);
128 vout1x2 = math_max_s32(vout1x2, voutput_min_less_zero_point);
129 vout1x3 = math_max_s32(vout1x3, voutput_min_less_zero_point);
130
131 vout0x0 = math_min_s32(vout0x0, voutput_max_less_zero_point);
132 vout0x1 = math_min_s32(vout0x1, voutput_max_less_zero_point);
133 vout0x2 = math_min_s32(vout0x2, voutput_max_less_zero_point);
134 vout0x3 = math_min_s32(vout0x3, voutput_max_less_zero_point);
135 vout1x0 = math_min_s32(vout1x0, voutput_max_less_zero_point);
136 vout1x1 = math_min_s32(vout1x1, voutput_max_less_zero_point);
137 vout1x2 = math_min_s32(vout1x2, voutput_max_less_zero_point);
138 vout1x3 = math_min_s32(vout1x3, voutput_max_less_zero_point);
139
140 vout0x0 += voutput_zero_point;
141 vout0x1 += voutput_zero_point;
142 vout0x2 += voutput_zero_point;
143 vout0x3 += voutput_zero_point;
144 vout1x0 += voutput_zero_point;
145 vout1x1 += voutput_zero_point;
146 vout1x2 += voutput_zero_point;
147 vout1x3 += voutput_zero_point;
148
149 if XNN_LIKELY(nc >= 4) {
150 c1[0] = (uint8_t) vout1x0;
151 c1[1] = (uint8_t) vout1x1;
152 c1[2] = (uint8_t) vout1x2;
153 c1[3] = (uint8_t) vout1x3;
154 c0[0] = (uint8_t) vout0x0;
155 c0[1] = (uint8_t) vout0x1;
156 c0[2] = (uint8_t) vout0x2;
157 c0[3] = (uint8_t) vout0x3;
158
159 c1 = (uint8_t*) ((uintptr_t) c1 + cn_stride);
160 c0 = (uint8_t*) ((uintptr_t) c0 + cn_stride);
161
162 a = (const uint8_t**restrict) ((uintptr_t) a - ks);
163 nc -= 4;
164 } else {
165 if (nc & 2) {
166 c1[0] = (uint8_t) vout1x0;
167 c1[1] = (uint8_t) vout1x1;
168 vout1x0 = vout1x2;
169 c1 += 2;
170 c0[0] = (uint8_t) vout0x0;
171 c0[1] = (uint8_t) vout0x1;
172 vout0x0 = vout0x2;
173 c0 += 2;
174 }
175 if (nc & 1) {
176 c1[0] = (uint8_t) vout1x0;
177 c0[0] = (uint8_t) vout0x0;
178 }
179
180 nc = 0;
181 }
182 } while (nc != 0);
183 }