Debian Codegraph @

src/qd8-f32-qc8w-gemm/gen/qd8-f32-qc8w-gemm-1x2-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_1x2__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 <= 1);
32 assert(nc != 0);
33 assert(kc != 0);
34
35 const int8_t* a0 = a;
36 float* c0 = c;
37
38
39 do {
40 const int32_t vksum0 = unaligned_indexed_load_s32(w, 0);
41 const int32_t vksum1 = unaligned_indexed_load_s32(w, 1);
42 const int32_t vinput_zero_point0 = quantization_params[0].zero_point;
43 int32_t vacc0x0 = vksum0 * vinput_zero_point0;
44 int32_t vacc0x1 = vksum1 * vinput_zero_point0;
45 w = (const int32_t*) w + 2;
46
47 size_t k = kc;
48 do {
49 const int32_t va0 = (int32_t) *a0++;
50
51 const int32_t vb0 = (int32_t) ((const int8_t*) w)[0];
52 const int32_t vb1 = (int32_t) ((const int8_t*) w)[1];
53 w = (const int8_t*) w + 2;
54
55 vacc0x0 += va0 * vb0;
56 vacc0x1 += va0 * vb1;
57
58 k -= sizeof(int8_t);
59 } while (k != 0);
60
61 float vout0x0 = (float) vacc0x0;
62 float vout0x1 = (float) vacc0x1;
63
64 const float vinput_scale0 = quantization_params[0].inv_scale;
65 vout0x0 *= vinput_scale0;
66 vout0x1 *= vinput_scale0;
67
68 const float vfilter_output_scale0 = unaligned_indexed_load_f32(w, 0);
69 vout0x0 *= vfilter_output_scale0;
70 const float vfilter_output_scale1 = unaligned_indexed_load_f32(w, 1);
71 vout0x1 *= vfilter_output_scale1;
72
73 const float vbias0 = unaligned_indexed_load_f32(w, 2);
74 vout0x0 += vbias0;
75 const float vbias1 = unaligned_indexed_load_f32(w, 3);
76 vout0x1 += vbias1;
77
78 w = (const float*) w + 4;
79
80 const float voutput_min = params->scalar.min;
81 vout0x0 = __builtin_wasm_max_f32(vout0x0, voutput_min);
82 vout0x1 = __builtin_wasm_max_f32(vout0x1, voutput_min);
83
84 const float voutput_max = params->scalar.max;
85 vout0x0 = __builtin_wasm_min_f32(vout0x0, voutput_max);
86 vout0x1 = __builtin_wasm_min_f32(vout0x1, voutput_max);
87
88 if XNN_LIKELY(nc >= 2) {
89 c0[0] = vout0x0;
90 c0[1] = vout0x1;
91
92 a0 = (const int8_t*) ((uintptr_t) a0 - kc);
93
94 c0 = (float*) ((uintptr_t) c0 + cn_stride);
95
96 nc -= 2;
97 } else {
98 if (nc & 1) {
99 c0[0] = vout0x0;
100 }
101
102 nc = 0;
103 }
104 } while (nc != 0);
105 }