Debian Codegraph @

src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-1x4-minmax-fp32-scalar-imagic.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_qs8_qc8w_igemm_minmax_fp32_ukernel_1x4__scalar_imagic(
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 int8_t* restrict c,
24 size_t cm_stride,
25 size_t cn_stride,
26 size_t a_offset,
27 const int8_t* zero,
28 const union xnn_qs8_qc8w_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 int8_t* c0 = c;
41
42 const int32_t output_min_less_zero_point = (int32_t) params->fp32_scalar.output_min - (int32_t) params->fp32_scalar.output_zero_point;
43 const int32_t output_max_less_zero_point = (int32_t) params->fp32_scalar.output_max - (int32_t) params->fp32_scalar.output_zero_point;
44 const float vmagic_bias = 12582912.0f;
45 const int32_t vmagic_min = (int32_t) float_as_uint32(12582912.0f + output_min_less_zero_point);
46 const int32_t vmagic_max = (int32_t) float_as_uint32(12582912.0f + output_max_less_zero_point);
47 const int32_t vmagic_bias_less_zero_point = INT32_C(0x4B400000) - (int32_t) params->fp32_scalar.output_zero_point;
48
49 do {
50 int32_t vacc0x0 = ((const int32_t*) w)[0];
51 int32_t vacc0x1 = ((const int32_t*) w)[1];
52 int32_t vacc0x2 = ((const int32_t*) w)[2];
53 int32_t vacc0x3 = ((const int32_t*) w)[3];
54 w = (const void*) ((const int32_t*) w + 4);
55
56 size_t p = ks;
57 do {
58 const int8_t* restrict a0 = a[0];
59 assert(a0 != NULL);
60 if XNN_UNPREDICTABLE(a0 != zero) {
61 a0 = (const int8_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) *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 const int32_t vb2 = (int32_t) ((const int8_t*) w)[2];
72 const int32_t vb3 = (int32_t) ((const int8_t*) w)[3];
73 w = (const void*) ((const int8_t*) w + 4);
74
75 vacc0x0 += va0 * vb0;
76 vacc0x1 += va0 * vb1;
77 vacc0x2 += va0 * vb2;
78 vacc0x3 += va0 * vb3;
79
80 k -= sizeof(int8_t);
81 } while (k != 0);
82 p -= 1 * sizeof(void*);
83 } while (p != 0);
84
85 float vfpacc0x0 = (float) vacc0x0;
86 float vfpacc0x1 = (float) vacc0x1;
87 float vfpacc0x2 = (float) vacc0x2;
88 float vfpacc0x3 = (float) vacc0x3;
89
90 const float vscale0 = ((const float*) w)[0];
91 vfpacc0x0 *= vscale0;
92 const float vscale1 = ((const float*) w)[1];
93 vfpacc0x1 *= vscale1;
94 const float vscale2 = ((const float*) w)[2];
95 vfpacc0x2 *= vscale2;
96 const float vscale3 = ((const float*) w)[3];
97 vfpacc0x3 *= vscale3;
98 w = (const void*) ((const float*) w + 4);
99
100 vfpacc0x0 += vmagic_bias;
101 vfpacc0x1 += vmagic_bias;
102 vfpacc0x2 += vmagic_bias;
103 vfpacc0x3 += vmagic_bias;
104
105 int32_t vout0x0 = (int32_t) float_as_uint32(vfpacc0x0);
106 int32_t vout0x1 = (int32_t) float_as_uint32(vfpacc0x1);
107 int32_t vout0x2 = (int32_t) float_as_uint32(vfpacc0x2);
108 int32_t vout0x3 = (int32_t) float_as_uint32(vfpacc0x3);
109
110 vout0x0 = math_max_s32(vout0x0, vmagic_min);
111 vout0x1 = math_max_s32(vout0x1, vmagic_min);
112 vout0x2 = math_max_s32(vout0x2, vmagic_min);
113 vout0x3 = math_max_s32(vout0x3, vmagic_min);
114
115 vout0x0 = math_min_s32(vout0x0, vmagic_max);
116 vout0x1 = math_min_s32(vout0x1, vmagic_max);
117 vout0x2 = math_min_s32(vout0x2, vmagic_max);
118 vout0x3 = math_min_s32(vout0x3, vmagic_max);
119
120 vout0x0 -= vmagic_bias_less_zero_point;
121 vout0x1 -= vmagic_bias_less_zero_point;
122 vout0x2 -= vmagic_bias_less_zero_point;
123 vout0x3 -= vmagic_bias_less_zero_point;
124
125 if XNN_LIKELY(nc >= 4) {
126 c0[0] = (int8_t) vout0x0;
127 c0[1] = (int8_t) vout0x1;
128 c0[2] = (int8_t) vout0x2;
129 c0[3] = (int8_t) vout0x3;
130
131 c0 = (int8_t*) ((uintptr_t) c0 + cn_stride);
132
133 a = (const int8_t**restrict) ((uintptr_t) a - ks);
134 nc -= 4;
135 } else {
136 if (nc & 2) {
137 c0[0] = (int8_t) vout0x0;
138 c0[1] = (int8_t) vout0x1;
139 vout0x0 = vout0x2;
140 c0 += 2;
141 }
142 if (nc & 1) {
143 c0[0] = (int8_t) vout0x0;
144 }
145
146 nc = 0;
147 }
148 } while (nc != 0);
149 }