Debian Codegraph @

src/qd8-f32-qc8w-gemm/gen/qd8-f32-qc8w-gemm-1x4c2-minmax-wasmsimd-dot16x2-ld128.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-gemm/MRx4c2-wasmsimd-dot16x2.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 <wasm_simd128.h>
13
14 #include "xnnpack/gemm.h"
15 #include "xnnpack/math.h"
16
17
18 void xnn_qd8_f32_qc8w_gemm_minmax_ukernel_1x4c2__wasmsimd_dot16x2_ld128(
19 size_t mr,
20 size_t nc,
21 size_t kc,
22 const int8_t* restrict a,
23 size_t a_stride,
24 const void* restrict w,
25 float* restrict c,
26 size_t cm_stride,
27 size_t cn_stride,
28 const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)],
29 const struct xnn_qd8_quantization_params quantization_params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
30 {
31 assert(mr != 0);
32 assert(mr <= 1);
33 assert(nc != 0);
34 assert(kc != 0);
35 assert(kc % sizeof(int8_t) == 0);
36 assert(a != NULL);
37 assert(w != NULL);
38 assert(c != NULL);
39
40 kc = round_up_po2(kc, 2 * sizeof(int8_t));
41 const int8_t* a0 = a;
42 float* c0 = c;
43
44 const v128_t vmin = wasm_v128_load32_splat(&params->scalar.min);
45 const v128_t vmax = wasm_v128_load32_splat(&params->scalar.max);
46 XNN_FORCE_REALIZATION(vmin);
47 XNN_FORCE_REALIZATION(vmax);
48
49
50 do {
51 const v128_t vksum0123 = wasm_v128_load(w);
52 const v128_t vinput_zero_point0 = wasm_v128_load32_splat(&quantization_params[0].zero_point);
53 v128_t vacc0x0123 = wasm_i32x4_mul(vksum0123, vinput_zero_point0);
54 w = (const int32_t*) w + 4;
55
56 size_t k = kc;
57 while (k >= 8 * sizeof(int8_t)) {
58 const v128_t vxa0 = wasm_i16x8_load8x8((const v128_t*) a0);
59 a0 += 8;
60
61 const v128_t vb01 = wasm_v128_load(w);
62 const v128_t vxb0 = wasm_i16x8_extend_low_i8x16(vb01);
63 const v128_t vxb1 = wasm_i16x8_extend_high_i8x16(vb01);
64
65 vacc0x0123 = wasm_i32x4_add(vacc0x0123,
66 wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa0, vxa0, 0, 0, 0, 0), vxb0));
67
68 vacc0x0123 = wasm_i32x4_add(vacc0x0123,
69 wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa0, vxa0, 1, 1, 1, 1), vxb1));
70 const v128_t vb23 = wasm_v128_load((const int8_t*) w + 16);
71 const v128_t vxb2 = wasm_i16x8_extend_low_i8x16(vb23);
72 const v128_t vxb3 = wasm_i16x8_extend_high_i8x16(vb23);
73
74 vacc0x0123 = wasm_i32x4_add(vacc0x0123,
75 wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa0, vxa0, 2, 2, 2, 2), vxb2));
76
77 vacc0x0123 = wasm_i32x4_add(vacc0x0123,
78 wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa0, vxa0, 3, 3, 3, 3), vxb3));
79
80 w = (const int8_t*) w + 32;
81 k -= 8 * sizeof(int8_t);
82 }
83 if (k != 0) {
84 const v128_t vxa0 = wasm_i16x8_load8x8(a0);
85 a0 = (const int8_t*) ((uintptr_t) a0 + k);
86
87 const v128_t vxb0 = wasm_i16x8_load8x8(w);
88 w = (const int8_t*) w + 8;
89
90 vacc0x0123 = wasm_i32x4_add(vacc0x0123,
91 wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa0, vxa0, 0, 0, 0, 0), vxb0));
92
93 if (k > 2 * sizeof(int8_t)) {
94 const v128_t vxb1 = wasm_i16x8_load8x8(w);
95 w = (const int8_t*) w + 8;
96
97 vacc0x0123 = wasm_i32x4_add(vacc0x0123,
98 wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa0, vxa0, 1, 1, 1, 1), vxb1));
99
100 if (k > 4 * sizeof(int8_t)) {
101 const v128_t vxb2 = wasm_i16x8_load8x8(w);
102 w = (const int8_t*) w + 8;
103
104 vacc0x0123 = wasm_i32x4_add(vacc0x0123,
105 wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa0, vxa0, 2, 2, 2, 2), vxb2));
106 }
107 }
108 }
109
110 vacc0x0123 = wasm_f32x4_convert_i32x4(vacc0x0123);
111
112 const v128_t vinput_scale0 = wasm_v128_load32_splat(&quantization_params[0].inv_scale);
113
114 vacc0x0123 = wasm_f32x4_mul(vacc0x0123, vinput_scale0);
115
116 const v128_t vfilter_output_scale0123 = wasm_v128_load(w);
117 vacc0x0123 = wasm_f32x4_mul(vacc0x0123, vfilter_output_scale0123);
118 w = (const float*) w + 4;
119
120 const v128_t vbias0123 = wasm_v128_load(w);
121 vacc0x0123 = wasm_f32x4_add(vacc0x0123, vbias0123);
122 w = (const float*) w + 4;
123
124 vacc0x0123 = wasm_f32x4_pmax(vacc0x0123, vmin);
125
126 vacc0x0123 = wasm_f32x4_pmin(vacc0x0123, vmax);
127
128 if XNN_LIKELY(nc >= 4) {
129 wasm_v128_store(c0, vacc0x0123);
130
131 a0 = (const int8_t*) ((uintptr_t) a0 - kc);
132
133 c0 = (float*) ((uintptr_t) c0 + cn_stride);
134
135 nc -= 4;
136 } else {
137 if (nc & 2) {
138 wasm_v128_store64_lane(c0, vacc0x0123, 0);
139 vacc0x0123 = wasm_v64x2_shuffle(vacc0x0123, vacc0x0123, 1, 1);
140 c0 += 2;
141 }
142 if (nc & 1) {
143 wasm_v128_store32_lane(c0, vacc0x0123, 0);
144 }
145 nc = 0;
146 }
147 } while (nc != 0);
148 }