Debian Codegraph @

src/qd8-f32-qc8w-gemm/gen/qd8-f32-qc8w-gemm-1x4-minmax-wasm.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-gemm/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/gemm.h"
13 #include "xnnpack/math.h"
14
15
16 void xnn_qd8_f32_qc8w_gemm_minmax_ukernel_1x4__wasm(
17 size_t mr,
18 size_t nc,
19 size_t kc,
20 const int8_t* restrict a,
21 size_t a_stride,
22 const void* restrict w,
23 float* restrict c,
24 size_t cm_stride,
25 size_t cn_stride,
26 const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)],
27 const struct xnn_qd8_quantization_params quantization_params[restrict XNN_MIN_ELEMENTS(1)])
28 {
29 assert(mr != 0);
30 assert(mr <= 1);
31 assert(nc != 0);
32 assert(kc != 0);
33
34 const int8_t* a0 = a;
35 float* c0 = c;
36
37
38 do {
39 const int32_t vksum0 = ((const int32_t*) w)[0];
40 const int32_t vksum1 = ((const int32_t*) w)[1];
41 const int32_t vksum2 = ((const int32_t*) w)[2];
42 const int32_t vksum3 = ((const int32_t*) w)[3];
43 const int32_t vinput_zero_point0 = quantization_params[0].zero_point;
44 int32_t vacc0x0 = vksum0 * vinput_zero_point0;
45 int32_t vacc0x1 = vksum1 * vinput_zero_point0;
46 int32_t vacc0x2 = vksum2 * vinput_zero_point0;
47 int32_t vacc0x3 = vksum3 * vinput_zero_point0;
48 w = (const int32_t*) w + 4;
49
50 size_t k = kc;
51 do {
52 const int32_t va0 = (int32_t) *a0++;
53
54 const int32_t vb0 = (int32_t) ((const int8_t*) w)[0];
55 const int32_t vb1 = (int32_t) ((const int8_t*) w)[1];
56 const int32_t vb2 = (int32_t) ((const int8_t*) w)[2];
57 const int32_t vb3 = (int32_t) ((const int8_t*) w)[3];
58 w = (const int8_t*) w + 4;
59
60 vacc0x0 += va0 * vb0;
61 vacc0x1 += va0 * vb1;
62 vacc0x2 += va0 * vb2;
63 vacc0x3 += va0 * vb3;
64
65 k -= sizeof(int8_t);
66 } while (k != 0);
67
68 float vout0x0 = (float) vacc0x0;
69 float vout0x1 = (float) vacc0x1;
70 float vout0x2 = (float) vacc0x2;
71 float vout0x3 = (float) vacc0x3;
72
73 const float vinput_scale0 = quantization_params[0].inv_scale;
74 vout0x0 *= vinput_scale0;
75 vout0x1 *= vinput_scale0;
76 vout0x2 *= vinput_scale0;
77 vout0x3 *= vinput_scale0;
78
79 const float vfilter_output_scale0 = ((const float*) w)[0];
80 vout0x0 *= vfilter_output_scale0;
81 const float vfilter_output_scale1 = ((const float*) w)[1];
82 vout0x1 *= vfilter_output_scale1;
83 const float vfilter_output_scale2 = ((const float*) w)[2];
84 vout0x2 *= vfilter_output_scale2;
85 const float vfilter_output_scale3 = ((const float*) w)[3];
86 vout0x3 *= vfilter_output_scale3;
87
88 const float vbias0 = ((const float*) w)[4];
89 vout0x0 += vbias0;
90 const float vbias1 = ((const float*) w)[5];
91 vout0x1 += vbias1;
92 const float vbias2 = ((const float*) w)[6];
93 vout0x2 += vbias2;
94 const float vbias3 = ((const float*) w)[7];
95 vout0x3 += vbias3;
96
97 w = (const float*) w + 8;
98
99 const float voutput_min = params->scalar.min;
100 vout0x0 = __builtin_wasm_max_f32(vout0x0, voutput_min);
101 vout0x1 = __builtin_wasm_max_f32(vout0x1, voutput_min);
102 vout0x2 = __builtin_wasm_max_f32(vout0x2, voutput_min);
103 vout0x3 = __builtin_wasm_max_f32(vout0x3, voutput_min);
104
105 const float voutput_max = params->scalar.max;
106 vout0x0 = __builtin_wasm_min_f32(vout0x0, voutput_max);
107 vout0x1 = __builtin_wasm_min_f32(vout0x1, voutput_max);
108 vout0x2 = __builtin_wasm_min_f32(vout0x2, voutput_max);
109 vout0x3 = __builtin_wasm_min_f32(vout0x3, voutput_max);
110
111 if XNN_LIKELY(nc >= 4) {
112 c0[0] = vout0x0;
113 c0[1] = vout0x1;
114 c0[2] = vout0x2;
115 c0[3] = vout0x3;
116
117 a0 = (const int8_t*) ((uintptr_t) a0 - kc);
118
119 c0 = (float*) ((uintptr_t) c0 + cn_stride);
120
121 nc -= 4;
122 } else {
123 if (nc & 2) {
124 c0[0] = vout0x0;
125 c0[1] = vout0x1;
126 vout0x0 = vout0x2;
127 c0 += 2;
128 }
129 if (nc & 1) {
130 c0[0] = vout0x0;
131 }
132
133 nc = 0;
134 }
135 } while (nc != 0);
136 }