Debian Codegraph @

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