Debian Codegraph @

src/qu8-igemm/gen/qu8-igemm-3x2-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_3x2__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 <= 3);
33 assert(nc != 0);
34 assert(kc != 0);
35 assert(ks != 0);
36 assert(ks % (3 * 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
51 const int32_t vmultiplier = params->rndnu_scalar.multiplier;
52 const int64_t vrounding = params->rndnu_scalar.rounding;
53 const uint32_t vshift = params->rndnu_scalar.shift;
54 const int32_t voutput_min_less_zero_point = (int32_t) params->rndnu_scalar.output_min - (int32_t) params->rndnu_scalar.output_zero_point;
55 const int32_t voutput_max_less_zero_point = (int32_t) params->rndnu_scalar.output_max - (int32_t) params->rndnu_scalar.output_zero_point;
56 const int32_t voutput_zero_point = params->rndnu_scalar.output_zero_point;
57
58 const int32_t vb_zero_point = params->rndnu_scalar.kernel_zero_point;
59 do {
60 int32_t vacc0x0 = unaligned_indexed_load_s32(w, 0);
61 int32_t vacc0x1 = unaligned_indexed_load_s32(w, 1);
62 int32_t vacc1x0 = vacc0x0;
63 int32_t vacc1x1 = vacc0x1;
64 int32_t vacc2x0 = vacc0x0;
65 int32_t vacc2x1 = vacc0x1;
66 w = (const void*) ((const int32_t*) w + 2);
67
68 size_t p = ks;
69 do {
70 const uint8_t* restrict a0 = a[0];
71 assert(a0 != NULL);
72 if XNN_UNPREDICTABLE(a0 != zero) {
73 a0 = (const uint8_t*) ((uintptr_t) a0 + a_offset);
74 }
75 const uint8_t* restrict a1 = a[1];
76 assert(a1 != NULL);
77 if XNN_UNPREDICTABLE(a1 != zero) {
78 a1 = (const uint8_t*) ((uintptr_t) a1 + a_offset);
79 }
80 const uint8_t* restrict a2 = a[2];
81 assert(a2 != NULL);
82 if XNN_UNPREDICTABLE(a2 != zero) {
83 a2 = (const uint8_t*) ((uintptr_t) a2 + a_offset);
84 }
85 a += 3;
86
87 size_t k = kc;
88 do {
89 const int32_t va0 = (int32_t) (uint32_t) *a0++;
90 const int32_t va1 = (int32_t) (uint32_t) *a1++;
91 const int32_t va2 = (int32_t) (uint32_t) *a2++;
92
93 const int32_t vb0 = (int32_t) (uint32_t) ((const uint8_t*) w)[0] - vb_zero_point;
94 const int32_t vb1 = (int32_t) (uint32_t) ((const uint8_t*) w)[1] - vb_zero_point;
95 w = (const void*) ((const uint8_t*) w + 2);
96
97 vacc0x0 += va0 * vb0;
98 vacc0x1 += va0 * vb1;
99 vacc1x0 += va1 * vb0;
100 vacc1x1 += va1 * vb1;
101 vacc2x0 += va2 * vb0;
102 vacc2x1 += va2 * vb1;
103
104 k -= sizeof(uint8_t);
105 } while (k != 0);
106 p -= 3 * sizeof(void*);
107 } while (p != 0);
108
109 const int64_t vextacc0x0 = math_mulext_s32(vacc0x0, vmultiplier) + vrounding;
110 const int64_t vextacc0x1 = math_mulext_s32(vacc0x1, vmultiplier) + vrounding;
111 const int64_t vextacc1x0 = math_mulext_s32(vacc1x0, vmultiplier) + vrounding;
112 const int64_t vextacc1x1 = math_mulext_s32(vacc1x1, vmultiplier) + vrounding;
113 const int64_t vextacc2x0 = math_mulext_s32(vacc2x0, vmultiplier) + vrounding;
114 const int64_t vextacc2x1 = math_mulext_s32(vacc2x1, vmultiplier) + vrounding;
115
116 int32_t vout0x0 = (int32_t) math_asr_s64(vextacc0x0, vshift);
117 int32_t vout0x1 = (int32_t) math_asr_s64(vextacc0x1, vshift);
118 int32_t vout1x0 = (int32_t) math_asr_s64(vextacc1x0, vshift);
119 int32_t vout1x1 = (int32_t) math_asr_s64(vextacc1x1, vshift);
120 int32_t vout2x0 = (int32_t) math_asr_s64(vextacc2x0, vshift);
121 int32_t vout2x1 = (int32_t) math_asr_s64(vextacc2x1, vshift);
122
123 vout0x0 = math_max_s32(vout0x0, voutput_min_less_zero_point);
124 vout0x1 = math_max_s32(vout0x1, voutput_min_less_zero_point);
125 vout1x0 = math_max_s32(vout1x0, voutput_min_less_zero_point);
126 vout1x1 = math_max_s32(vout1x1, voutput_min_less_zero_point);
127 vout2x0 = math_max_s32(vout2x0, voutput_min_less_zero_point);
128 vout2x1 = math_max_s32(vout2x1, voutput_min_less_zero_point);
129
130 vout0x0 = math_min_s32(vout0x0, voutput_max_less_zero_point);
131 vout0x1 = math_min_s32(vout0x1, voutput_max_less_zero_point);
132 vout1x0 = math_min_s32(vout1x0, voutput_max_less_zero_point);
133 vout1x1 = math_min_s32(vout1x1, voutput_max_less_zero_point);
134 vout2x0 = math_min_s32(vout2x0, voutput_max_less_zero_point);
135 vout2x1 = math_min_s32(vout2x1, voutput_max_less_zero_point);
136
137 vout0x0 += voutput_zero_point;
138 vout0x1 += voutput_zero_point;
139 vout1x0 += voutput_zero_point;
140 vout1x1 += voutput_zero_point;
141 vout2x0 += voutput_zero_point;
142 vout2x1 += voutput_zero_point;
143
144 if XNN_LIKELY(nc >= 2) {
145 c2[0] = (uint8_t) vout2x0;
146 c2[1] = (uint8_t) vout2x1;
147 c1[0] = (uint8_t) vout1x0;
148 c1[1] = (uint8_t) vout1x1;
149 c0[0] = (uint8_t) vout0x0;
150 c0[1] = (uint8_t) vout0x1;
151
152 c2 = (uint8_t*) ((uintptr_t) c2 + cn_stride);
153 c1 = (uint8_t*) ((uintptr_t) c1 + cn_stride);
154 c0 = (uint8_t*) ((uintptr_t) c0 + cn_stride);
155
156 a = (const uint8_t**restrict) ((uintptr_t) a - ks);
157 nc -= 2;
158 } else {
159 if (nc & 1) {
160 c2[0] = (uint8_t) vout2x0;
161 c1[0] = (uint8_t) vout1x0;
162 c0[0] = (uint8_t) vout0x0;
163 }
164
165 nc = 0;
166 }
167 } while (nc != 0);
168 }