Debian Codegraph @

src/qu8-igemm/gen/qu8-igemm-4x2-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 #include "xnnpack/unaligned.h"
15
16
17 void xnn_qu8_igemm_minmax_rndnu_ukernel_4x2__scalar(
18 size_t mr,
19 size_t nc,
20 size_t kc,
21 size_t ks,
22 const uint8_t** restrict a,
23 const void* restrict w,
24 uint8_t* restrict c,
25 size_t cm_stride,
26 size_t cn_stride,
27 size_t a_offset,
28 const uint8_t* zero,
29 const union xnn_qu8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)])
30 {
31 assert(mr != 0);
32 assert(mr <= 4);
33 assert(nc != 0);
34 assert(kc != 0);
35 assert(ks != 0);
36 assert(ks % (4 * sizeof(void*)) == 0);
37 assert(a != NULL);
38 assert(w != NULL);
39 assert(c != NULL);
40
41 uint8_t* c0 = c;
42 uint8_t* c1 = (uint8_t*) ((uintptr_t) c0 + cm_stride);
43 if XNN_UNPREDICTABLE(mr < 2) {
44 c1 = c0;
45 }
46 uint8_t* c2 = (uint8_t*) ((uintptr_t) c1 + cm_stride);
47 if XNN_UNPREDICTABLE(mr <= 2) {
48 c2 = c1;
49 }
50 uint8_t* c3 = (uint8_t*) ((uintptr_t) c2 + cm_stride);
51 if XNN_UNPREDICTABLE(mr != 4) {
52 c3 = c2;
53 }
54
55 const int32_t vmultiplier = params->rndnu_scalar.multiplier;
56 const int64_t vrounding = params->rndnu_scalar.rounding;
57 const uint32_t vshift = params->rndnu_scalar.shift;
58 const int32_t voutput_min_less_zero_point = (int32_t) params->rndnu_scalar.output_min - (int32_t) params->rndnu_scalar.output_zero_point;
59 const int32_t voutput_max_less_zero_point = (int32_t) params->rndnu_scalar.output_max - (int32_t) params->rndnu_scalar.output_zero_point;
60 const int32_t voutput_zero_point = params->rndnu_scalar.output_zero_point;
61
62 const int32_t vb_zero_point = params->rndnu_scalar.kernel_zero_point;
63 do {
64 int32_t vacc0x0 = unaligned_indexed_load_s32(w, 0);
65 int32_t vacc0x1 = unaligned_indexed_load_s32(w, 1);
66 int32_t vacc1x0 = vacc0x0;
67 int32_t vacc1x1 = vacc0x1;
68 int32_t vacc2x0 = vacc0x0;
69 int32_t vacc2x1 = vacc0x1;
70 int32_t vacc3x0 = vacc0x0;
71 int32_t vacc3x1 = vacc0x1;
72 w = (const void*) ((const int32_t*) w + 2);
73
74 size_t p = ks;
75 do {
76 const uint8_t* restrict a0 = a[0];
77 assert(a0 != NULL);
78 if XNN_UNPREDICTABLE(a0 != zero) {
79 a0 = (const uint8_t*) ((uintptr_t) a0 + a_offset);
80 }
81 const uint8_t* restrict a1 = a[1];
82 assert(a1 != NULL);
83 if XNN_UNPREDICTABLE(a1 != zero) {
84 a1 = (const uint8_t*) ((uintptr_t) a1 + a_offset);
85 }
86 const uint8_t* restrict a2 = a[2];
87 assert(a2 != NULL);
88 if XNN_UNPREDICTABLE(a2 != zero) {
89 a2 = (const uint8_t*) ((uintptr_t) a2 + a_offset);
90 }
91 const uint8_t* restrict a3 = a[3];
92 assert(a3 != NULL);
93 if XNN_UNPREDICTABLE(a3 != zero) {
94 a3 = (const uint8_t*) ((uintptr_t) a3 + a_offset);
95 }
96 a += 4;
97
98 size_t k = kc;
99 do {
100 const int32_t va0 = (int32_t) (uint32_t) *a0++;
101 const int32_t va1 = (int32_t) (uint32_t) *a1++;
102 const int32_t va2 = (int32_t) (uint32_t) *a2++;
103 const int32_t va3 = (int32_t) (uint32_t) *a3++;
104
105 const int32_t vb0 = (int32_t) (uint32_t) ((const uint8_t*) w)[0] - vb_zero_point;
106 const int32_t vb1 = (int32_t) (uint32_t) ((const uint8_t*) w)[1] - vb_zero_point;
107 w = (const void*) ((const uint8_t*) w + 2);
108
109 vacc0x0 += va0 * vb0;
110 vacc0x1 += va0 * vb1;
111 vacc1x0 += va1 * vb0;
112 vacc1x1 += va1 * vb1;
113 vacc2x0 += va2 * vb0;
114 vacc2x1 += va2 * vb1;
115 vacc3x0 += va3 * vb0;
116 vacc3x1 += va3 * vb1;
117
118 k -= sizeof(uint8_t);
119 } while (k != 0);
120 p -= 4 * sizeof(void*);
121 } while (p != 0);
122
123 const int64_t vextacc0x0 = math_mulext_s32(vacc0x0, vmultiplier) + vrounding;
124 const int64_t vextacc0x1 = math_mulext_s32(vacc0x1, vmultiplier) + vrounding;
125 const int64_t vextacc1x0 = math_mulext_s32(vacc1x0, vmultiplier) + vrounding;
126 const int64_t vextacc1x1 = math_mulext_s32(vacc1x1, vmultiplier) + vrounding;
127 const int64_t vextacc2x0 = math_mulext_s32(vacc2x0, vmultiplier) + vrounding;
128 const int64_t vextacc2x1 = math_mulext_s32(vacc2x1, vmultiplier) + vrounding;
129 const int64_t vextacc3x0 = math_mulext_s32(vacc3x0, vmultiplier) + vrounding;
130 const int64_t vextacc3x1 = math_mulext_s32(vacc3x1, vmultiplier) + vrounding;
131
132 int32_t vout0x0 = (int32_t) math_asr_s64(vextacc0x0, vshift);
133 int32_t vout0x1 = (int32_t) math_asr_s64(vextacc0x1, vshift);
134 int32_t vout1x0 = (int32_t) math_asr_s64(vextacc1x0, vshift);
135 int32_t vout1x1 = (int32_t) math_asr_s64(vextacc1x1, vshift);
136 int32_t vout2x0 = (int32_t) math_asr_s64(vextacc2x0, vshift);
137 int32_t vout2x1 = (int32_t) math_asr_s64(vextacc2x1, vshift);
138 int32_t vout3x0 = (int32_t) math_asr_s64(vextacc3x0, vshift);
139 int32_t vout3x1 = (int32_t) math_asr_s64(vextacc3x1, vshift);
140
141 vout0x0 = math_max_s32(vout0x0, voutput_min_less_zero_point);
142 vout0x1 = math_max_s32(vout0x1, voutput_min_less_zero_point);
143 vout1x0 = math_max_s32(vout1x0, voutput_min_less_zero_point);
144 vout1x1 = math_max_s32(vout1x1, voutput_min_less_zero_point);
145 vout2x0 = math_max_s32(vout2x0, voutput_min_less_zero_point);
146 vout2x1 = math_max_s32(vout2x1, voutput_min_less_zero_point);
147 vout3x0 = math_max_s32(vout3x0, voutput_min_less_zero_point);
148 vout3x1 = math_max_s32(vout3x1, voutput_min_less_zero_point);
149
150 vout0x0 = math_min_s32(vout0x0, voutput_max_less_zero_point);
151 vout0x1 = math_min_s32(vout0x1, voutput_max_less_zero_point);
152 vout1x0 = math_min_s32(vout1x0, voutput_max_less_zero_point);
153 vout1x1 = math_min_s32(vout1x1, voutput_max_less_zero_point);
154 vout2x0 = math_min_s32(vout2x0, voutput_max_less_zero_point);
155 vout2x1 = math_min_s32(vout2x1, voutput_max_less_zero_point);
156 vout3x0 = math_min_s32(vout3x0, voutput_max_less_zero_point);
157 vout3x1 = math_min_s32(vout3x1, voutput_max_less_zero_point);
158
159 vout0x0 += voutput_zero_point;
160 vout0x1 += voutput_zero_point;
161 vout1x0 += voutput_zero_point;
162 vout1x1 += voutput_zero_point;
163 vout2x0 += voutput_zero_point;
164 vout2x1 += voutput_zero_point;
165 vout3x0 += voutput_zero_point;
166 vout3x1 += voutput_zero_point;
167
168 if XNN_LIKELY(nc >= 2) {
169 c3[0] = (uint8_t) vout3x0;
170 c3[1] = (uint8_t) vout3x1;
171 c2[0] = (uint8_t) vout2x0;
172 c2[1] = (uint8_t) vout2x1;
173 c1[0] = (uint8_t) vout1x0;
174 c1[1] = (uint8_t) vout1x1;
175 c0[0] = (uint8_t) vout0x0;
176 c0[1] = (uint8_t) vout0x1;
177
178 c3 = (uint8_t*) ((uintptr_t) c3 + cn_stride);
179 c2 = (uint8_t*) ((uintptr_t) c2 + cn_stride);
180 c1 = (uint8_t*) ((uintptr_t) c1 + cn_stride);
181 c0 = (uint8_t*) ((uintptr_t) c0 + cn_stride);
182
183 a = (const uint8_t**restrict) ((uintptr_t) a - ks);
184 nc -= 2;
185 } else {
186 if (nc & 1) {
187 c3[0] = (uint8_t) vout3x0;
188 c2[0] = (uint8_t) vout2x0;
189 c1[0] = (uint8_t) vout1x0;
190 c0[0] = (uint8_t) vout0x0;
191 }
192
193 nc = 0;
194 }
195 } while (nc != 0);
196 }