Debian Codegraph @

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