Debian Codegraph @

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