Debian Codegraph @

src/qd8-f32-qc8w-gemm/gen/qd8-f32-qc8w-gemm-1x4c2-minmax-wasmsimd-dot16x2-ld64.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_ld64(
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 vxb0 = wasm_i16x8_load8x8(w);
62
63 vacc0x0123 = wasm_i32x4_add(vacc0x0123,
64 wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa0, vxa0, 0, 0, 0, 0), vxb0));
65 const v128_t vxb1 = wasm_i16x8_load8x8((const int8_t*) w + 8);
66
67 vacc0x0123 = wasm_i32x4_add(vacc0x0123,
68 wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa0, vxa0, 1, 1, 1, 1), vxb1));
69 const v128_t vxb2 = wasm_i16x8_load8x8((const int8_t*) w + 16);
70
71 vacc0x0123 = wasm_i32x4_add(vacc0x0123,
72 wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa0, vxa0, 2, 2, 2, 2), vxb2));
73 const v128_t vxb3 = wasm_i16x8_load8x8((const int8_t*) w + 24);
74
75 vacc0x0123 = wasm_i32x4_add(vacc0x0123,
76 wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa0, vxa0, 3, 3, 3, 3), vxb3));
77
78 w = (const int8_t*) w + 32;
79 k -= 8 * sizeof(int8_t);
80 }
81 if (k != 0) {
82 const v128_t vxa0 = wasm_i16x8_load8x8(a0);
83 a0 = (const int8_t*) ((uintptr_t) a0 + k);
84
85 const v128_t vxb0 = wasm_i16x8_load8x8(w);
86 w = (const int8_t*) w + 8;
87
88 vacc0x0123 = wasm_i32x4_add(vacc0x0123,
89 wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa0, vxa0, 0, 0, 0, 0), vxb0));
90
91 if (k > 2 * sizeof(int8_t)) {
92 const v128_t vxb1 = wasm_i16x8_load8x8(w);
93 w = (const int8_t*) w + 8;
94
95 vacc0x0123 = wasm_i32x4_add(vacc0x0123,
96 wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa0, vxa0, 1, 1, 1, 1), vxb1));
97
98 if (k > 4 * sizeof(int8_t)) {
99 const v128_t vxb2 = wasm_i16x8_load8x8(w);
100 w = (const int8_t*) w + 8;
101
102 vacc0x0123 = wasm_i32x4_add(vacc0x0123,
103 wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa0, vxa0, 2, 2, 2, 2), vxb2));
104 }
105 }
106 }
107
108 vacc0x0123 = wasm_f32x4_convert_i32x4(vacc0x0123);
109
110 const v128_t vinput_scale0 = wasm_v128_load32_splat(&quantization_params[0].inv_scale);
111
112 vacc0x0123 = wasm_f32x4_mul(vacc0x0123, vinput_scale0);
113
114 const v128_t vfilter_output_scale0123 = wasm_v128_load(w);
115 vacc0x0123 = wasm_f32x4_mul(vacc0x0123, vfilter_output_scale0123);
116 w = (const float*) w + 4;
117
118 const v128_t vbias0123 = wasm_v128_load(w);
119 vacc0x0123 = wasm_f32x4_add(vacc0x0123, vbias0123);
120 w = (const float*) w + 4;
121
122 vacc0x0123 = wasm_f32x4_pmax(vacc0x0123, vmin);
123
124 vacc0x0123 = wasm_f32x4_pmin(vacc0x0123, vmax);
125
126 if XNN_LIKELY(nc >= 4) {
127 wasm_v128_store(c0, vacc0x0123);
128
129 a0 = (const int8_t*) ((uintptr_t) a0 - kc);
130
131 c0 = (float*) ((uintptr_t) c0 + cn_stride);
132
133 nc -= 4;
134 } else {
135 if (nc & 2) {
136 wasm_v128_store64_lane(c0, vacc0x0123, 0);
137 vacc0x0123 = wasm_v64x2_shuffle(vacc0x0123, vacc0x0123, 1, 1);
138 c0 += 2;
139 }
140 if (nc & 1) {
141 wasm_v128_store32_lane(c0, vacc0x0123, 0);
142 }
143 nc = 0;
144 }
145 } while (nc != 0);
146 }