Debian Codegraph @

src/qd8-f32-qc8w-igemm/gen/qd8-f32-qc8w-igemm-2x2-minmax-scalar.c

raw
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_qd8_f32_qc8w_igemm_minmax_ukernel_2x2__scalar(
18 size_t mr,
19 size_t nc,
20 size_t kc,
21 size_t ks,
22 const int8_t** restrict a,
23 const void* restrict w,
24 float* restrict c,
25 size_t cm_stride,
26 size_t cn_stride,
27 size_t a_offset,
28 const int8_t* zero,
29 const int8_t* zero_data,
30 const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)],
31 const struct xnn_qd8_quantization_params quantization_params[restrict XNN_MIN_ELEMENTS(1)])
32 {
33 assert(mr != 0);
34 assert(mr <= 2);
35 assert(nc != 0);
36 assert(kc != 0);
37 assert(ks != 0);
38 assert(ks % (2 * sizeof(void*)) == 0);
39 assert(a != NULL);
40 assert(w != NULL);
41 assert(c != NULL);
42
43 float* c0 = c;
44 float* c1 = (float*) ((uintptr_t) c0 + cm_stride);
45 if XNN_UNPREDICTABLE(mr != 2) {
46 c1 = c0;
47 }
48
49
50 do {
51 const int32_t vksum0 = unaligned_indexed_load_s32(w, 0);
52 const int32_t vksum1 = unaligned_indexed_load_s32(w, 1);
53 const int32_t vinput_zero_point = quantization_params->zero_point;
54 int32_t vacc0x0 = vksum0 * vinput_zero_point;
55 int32_t vacc0x1 = vksum1 * vinput_zero_point;
56 int32_t vacc1x0 = vksum0 * vinput_zero_point;
57 int32_t vacc1x1 = vksum1 * vinput_zero_point;
58 w = (const void*) ((const int32_t*) w + 2);
59
60 size_t p = ks;
61 do {
62 const int8_t* restrict a0 = a[0];
63 assert(a0 != NULL);
64 if XNN_UNPREDICTABLE(a0 != zero) {
65 a0 = (const int8_t*) ((uintptr_t) a0 + a_offset);
66 } else {
67 a0 = zero_data;
68 }
69 const int8_t* restrict a1 = a[1];
70 assert(a1 != NULL);
71 if XNN_UNPREDICTABLE(a1 != zero) {
72 a1 = (const int8_t*) ((uintptr_t) a1 + a_offset);
73 } else {
74 a1 = zero_data;
75 }
76 a += 2;
77
78 size_t k = kc;
79 do {
80 const int32_t va0 = (int32_t) *a0++;
81 const int32_t va1 = (int32_t) *a1++;
82
83 const int32_t vb0 = (int32_t) ((const int8_t*) w)[0];
84 const int32_t vb1 = (int32_t) ((const int8_t*) w)[1];
85 w = (const void*) ((const int8_t*) w + 2);
86
87 vacc0x0 += va0 * vb0;
88 vacc0x1 += va0 * vb1;
89 vacc1x0 += va1 * vb0;
90 vacc1x1 += va1 * vb1;
91
92 k -= sizeof(int8_t);
93 } while (k != 0);
94 p -= 2 * sizeof(void*);
95 } while (p != 0);
96
97 float vout0x0 = (float) vacc0x0;
98 float vout0x1 = (float) vacc0x1;
99 float vout1x0 = (float) vacc1x0;
100 float vout1x1 = (float) vacc1x1;
101
102 const float vinput_scale = quantization_params->inv_scale;
103 vout0x0 *= vinput_scale;
104 vout0x1 *= vinput_scale;
105 vout1x0 *= vinput_scale;
106 vout1x1 *= vinput_scale;
107
108 const float vfilter_output_scale0 = unaligned_indexed_load_f32(w, 0);
109 vout0x0 *= vfilter_output_scale0;
110 vout1x0 *= vfilter_output_scale0;
111 const float vfilter_output_scale1 = unaligned_indexed_load_f32(w, 1);
112 vout0x1 *= vfilter_output_scale1;
113 vout1x1 *= vfilter_output_scale1;
114
115 const float vbias0 = unaligned_indexed_load_f32(w, 2);
116 vout0x0 += vbias0;
117 vout1x0 += vbias0;
118 const float vbias1 = unaligned_indexed_load_f32(w, 3);
119 vout0x1 += vbias1;
120 vout1x1 += vbias1;
121
122 w = (const float*) w + 4;
123
124 const float voutput_min = params->scalar.min;
125 vout0x0 = math_max_f32(vout0x0, voutput_min);
126 vout1x0 = math_max_f32(vout1x0, voutput_min);
127 vout0x1 = math_max_f32(vout0x1, voutput_min);
128 vout1x1 = math_max_f32(vout1x1, voutput_min);
129
130 const float voutput_max = params->scalar.max;
131 vout0x0 = math_min_f32(vout0x0, voutput_max);
132 vout1x0 = math_min_f32(vout1x0, voutput_max);
133 vout0x1 = math_min_f32(vout0x1, voutput_max);
134 vout1x1 = math_min_f32(vout1x1, voutput_max);
135
136 if XNN_LIKELY(nc >= 2) {
137 c1[0] = vout1x0;
138 c1[1] = vout1x1;
139 c0[0] = vout0x0;
140 c0[1] = vout0x1;
141
142 c0 = (float*) ((uintptr_t) c0 + cn_stride);
143 c1 = (float*) ((uintptr_t) c1 + cn_stride);
144
145 a = (const int8_t**restrict) ((uintptr_t) a - ks);
146 nc -= 2;
147 } else {
148 if (nc & 1) {
149 c1[0] = vout1x0;
150 c0[0] = vout0x0;
151 }
152
153 nc = 0;
154 }
155 } while (nc != 0);
156 }