Debian Codegraph @

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