Debian Codegraph @

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