Debian Codegraph @

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

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-gemm/MRx4c2s4-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/common.h"
15 #include "xnnpack/gemm.h"
16 #include "xnnpack/math.h"
17
18
19 void xnn_qd8_f32_qc8w_gemm_minmax_ukernel_1x4c2s4__wasmsimd_dot16x2_ld128(
20 size_t mr,
21 size_t nc,
22 size_t kc,
23 const int8_t* restrict a,
24 size_t a_stride,
25 const void* restrict w,
26 float* restrict c,
27 size_t cm_stride,
28 size_t cn_stride,
29 const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)],
30 const struct xnn_qd8_quantization_params quantization_params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
31 {
32 assert(mr != 0);
33 assert(mr <= 1);
34 assert(nc != 0);
35 assert(kc != 0);
36 assert(kc % sizeof(int8_t) == 0);
37 assert(a != NULL);
38 assert(w != NULL);
39 assert(c != NULL);
40
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 kc = round_up_po2(kc, 8 * sizeof(int8_t));
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 do {
58 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, wasm_i32x4_dot_i16x8(vxa0, vxb0));
66 vxa0 = wasm_v32x4_shuffle(vxa0, vxa0, 1, 2, 3, 4);
67
68 vacc0x0123 = wasm_i32x4_add(vacc0x0123, wasm_i32x4_dot_i16x8(vxa0, vxb1));
69 vxa0 = wasm_v32x4_shuffle(vxa0, vxa0, 1, 2, 3, 4);
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, wasm_i32x4_dot_i16x8(vxa0, vxb2));
75 vxa0 = wasm_v32x4_shuffle(vxa0, vxa0, 1, 2, 3, 4);
76
77 vacc0x0123 = wasm_i32x4_add(vacc0x0123, wasm_i32x4_dot_i16x8(vxa0, vxb3));
78
79 w = (const int8_t*) w + 32;
80 k -= 8 * sizeof(int8_t);
81 } while (k != 0);
82
83 vacc0x0123 = wasm_f32x4_convert_i32x4(vacc0x0123);
84
85 const v128_t vinput_scale0 = wasm_v128_load32_splat(&quantization_params[0].inv_scale);
86
87 vacc0x0123 = wasm_f32x4_mul(vacc0x0123, vinput_scale0);
88
89 const v128_t vfilter_output_scale0123 = wasm_v128_load(w);
90 vacc0x0123 = wasm_f32x4_mul(vacc0x0123, vfilter_output_scale0123);
91 w = (const float*) w + 4;
92
93 const v128_t vbias0123 = wasm_v128_load(w);
94 vacc0x0123 = wasm_f32x4_add(vacc0x0123, vbias0123);
95 w = (const float*) w + 4;
96
97 vacc0x0123 = wasm_f32x4_pmax(vacc0x0123, vmin);
98
99 vacc0x0123 = wasm_f32x4_pmin(vacc0x0123, vmax);
100
101 if XNN_LIKELY(nc >= 4) {
102 wasm_v128_store(c0, vacc0x0123);
103
104 a0 = (const int8_t*) ((uintptr_t) a0 - kc);
105
106 c0 = (float*) ((uintptr_t) c0 + cn_stride);
107
108 nc -= 4;
109 } else {
110 if (nc & 2) {
111 wasm_v128_store64_lane(c0, vacc0x0123, 0);
112 vacc0x0123 = wasm_v64x2_shuffle(vacc0x0123, vacc0x0123, 1, 1);
113 c0 += 2;
114 }
115 if (nc & 1) {
116 wasm_v128_store32_lane(c0, vacc0x0123, 0);
117 }
118 nc = 0;
119 }
120 } while (nc != 0);
121 }