Debian Codegraph @

src/qd8-f32-qc8w-igemm/gen/qd8-f32-qc8w-igemm-1x2-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_1x2__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 <= 1);
35 assert(nc != 0);
36 assert(kc != 0);
37 assert(ks != 0);
38 assert(ks % (1 * sizeof(void*)) == 0);
39 assert(a != NULL);
40 assert(w != NULL);
41 assert(c != NULL);
42
43 float* c0 = c;
44
45
46 do {
47 const int32_t vksum0 = unaligned_indexed_load_s32(w, 0);
48 const int32_t vksum1 = unaligned_indexed_load_s32(w, 1);
49 const int32_t vinput_zero_point = quantization_params->zero_point;
50 int32_t vacc0x0 = vksum0 * vinput_zero_point;
51 int32_t vacc0x1 = vksum1 * vinput_zero_point;
52 w = (const void*) ((const int32_t*) w + 2);
53
54 size_t p = ks;
55 do {
56 const int8_t* restrict a0 = a[0];
57 assert(a0 != NULL);
58 if XNN_UNPREDICTABLE(a0 != zero) {
59 a0 = (const int8_t*) ((uintptr_t) a0 + a_offset);
60 } else {
61 a0 = zero_data;
62 }
63 a += 1;
64
65 size_t k = kc;
66 do {
67 const int32_t va0 = (int32_t) *a0++;
68
69 const int32_t vb0 = (int32_t) ((const int8_t*) w)[0];
70 const int32_t vb1 = (int32_t) ((const int8_t*) w)[1];
71 w = (const void*) ((const int8_t*) w + 2);
72
73 vacc0x0 += va0 * vb0;
74 vacc0x1 += va0 * vb1;
75
76 k -= sizeof(int8_t);
77 } while (k != 0);
78 p -= 1 * sizeof(void*);
79 } while (p != 0);
80
81 float vout0x0 = (float) vacc0x0;
82 float vout0x1 = (float) vacc0x1;
83
84 const float vinput_scale = quantization_params->inv_scale;
85 vout0x0 *= vinput_scale;
86 vout0x1 *= vinput_scale;
87
88 const float vfilter_output_scale0 = unaligned_indexed_load_f32(w, 0);
89 vout0x0 *= vfilter_output_scale0;
90 const float vfilter_output_scale1 = unaligned_indexed_load_f32(w, 1);
91 vout0x1 *= vfilter_output_scale1;
92
93 const float vbias0 = unaligned_indexed_load_f32(w, 2);
94 vout0x0 += vbias0;
95 const float vbias1 = unaligned_indexed_load_f32(w, 3);
96 vout0x1 += vbias1;
97
98 w = (const float*) w + 4;
99
100 const float voutput_min = params->scalar.min;
101 vout0x0 = math_max_f32(vout0x0, voutput_min);
102 vout0x1 = math_max_f32(vout0x1, voutput_min);
103
104 const float voutput_max = params->scalar.max;
105 vout0x0 = math_min_f32(vout0x0, voutput_max);
106 vout0x1 = math_min_f32(vout0x1, voutput_max);
107
108 if XNN_LIKELY(nc >= 2) {
109 c0[0] = vout0x0;
110 c0[1] = vout0x1;
111
112 c0 = (float*) ((uintptr_t) c0 + cn_stride);
113
114 a = (const int8_t**restrict) ((uintptr_t) a - ks);
115 nc -= 2;
116 } else {
117 if (nc & 1) {
118 c0[0] = vout0x0;
119 }
120
121 nc = 0;
122 }
123 } while (nc != 0);
124 }