Debian Codegraph @

src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-1x4c8-minmax-fp32-wasmsimd-dot16x2-ld128.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-igemm/MRx4c8-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_qs8_qc8w_igemm_minmax_fp32_ukernel_1x4c8__wasmsimd_dot16x2_ld128(
20 size_t mr,
21 size_t nc,
22 size_t kc,
23 size_t ks,
24 const int8_t** restrict a,
25 const void* restrict w,
26 int8_t* restrict c,
27 size_t cm_stride,
28 size_t cn_stride,
29 size_t a_offset,
30 const int8_t* zero,
31 const union xnn_qs8_qc8w_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
32 {
33 assert(mr != 0);
34 assert(mr <= 1);
35 assert(nc != 0);
36 assert(kc != 0);
37 assert(ks != 0);
38 assert(ks % (1 * sizeof(void*)) == 0);
39 assert(a_offset % sizeof(int8_t) == 0);
40 assert(a != NULL);
41 assert(w != NULL);
42 assert(c != NULL);
43
44 kc = round_up_po2(kc, 8 * sizeof(int8_t));
45 int8_t* c0 = c;
46
47
48 const v128_t vmagic_bias = wasm_f32x4_const_splat(12582912.0f);
49 const int32_t output_min_less_zero_point = (int32_t) params->fp32_scalar.output_min - (int32_t) params->fp32_scalar.output_zero_point;
50 const v128_t vmagic_min = wasm_i32x4_splat((int32_t) float_as_uint32(12582912.0f + output_min_less_zero_point));
51 const v128_t vmagic_bias_less_output_zero_point = wasm_i32x4_splat(INT32_C(0x4B400000) - (int32_t) params->fp32_scalar.output_zero_point);
52 const v128_t voutput_max = wasm_i8x16_splat(params->fp32_scalar.output_max);
53 XNN_FORCE_REALIZATION(vmagic_bias);
54 XNN_FORCE_REALIZATION(vmagic_min);
55 XNN_FORCE_REALIZATION(vmagic_bias_less_output_zero_point);
56 XNN_FORCE_REALIZATION(voutput_max);
57 do {
58 v128_t vacc0x0 = wasm_v128_load32_zero(w);
59 v128_t vacc0x1 = wasm_v128_load32_zero((const int32_t*) w + 1);
60 v128_t vacc0x2 = wasm_v128_load32_zero((const int32_t*) w + 2);
61 v128_t vacc0x3 = wasm_v128_load32_zero((const int32_t*) w + 3);
62 w = (const void*) ((const int32_t*) w + 4);
63
64 size_t p = ks;
65 do {
66 const int8_t* restrict a0 = a[0];
67 if XNN_UNPREDICTABLE(a0 != zero) {
68 a0 = (const int8_t*) ((uintptr_t) a0 + a_offset);
69 }
70 a += 1;
71
72 size_t k = kc;
73 do {
74 const v128_t vxa0 = wasm_i16x8_load8x8(a0);
75 a0 += 8;
76
77 const v128_t vb01 = wasm_v128_load(w);
78 const v128_t vxb0 = wasm_i16x8_extend_low_i8x16(vb01);
79 const v128_t vxb1 = wasm_i16x8_extend_high_i8x16(vb01);
80
81 vacc0x0 = wasm_i32x4_add(vacc0x0, wasm_i32x4_dot_i16x8(vxa0, vxb0));
82 vacc0x1 = wasm_i32x4_add(vacc0x1, wasm_i32x4_dot_i16x8(vxa0, vxb1));
83 const v128_t vb23 = wasm_v128_load((const int8_t*) w + 16);
84 const v128_t vxb2 = wasm_i16x8_extend_low_i8x16(vb23);
85 const v128_t vxb3 = wasm_i16x8_extend_high_i8x16(vb23);
86
87 vacc0x2 = wasm_i32x4_add(vacc0x2, wasm_i32x4_dot_i16x8(vxa0, vxb2));
88 vacc0x3 = wasm_i32x4_add(vacc0x3, wasm_i32x4_dot_i16x8(vxa0, vxb3));
89
90 w = (const void*) ((const int8_t*) w + 32);
91 k -= 8 * sizeof(int8_t);
92 } while (k != 0);
93 p -= 1 * sizeof(void*);
94 } while (p != 0);
95
96 const v128_t vacc0x02 = wasm_i32x4_add(wasm_v32x4_shuffle(vacc0x0, vacc0x2, 0, 4, 1, 5), wasm_v32x4_shuffle(vacc0x0, vacc0x2, 2, 6, 3, 7));
97 const v128_t vacc0x13 = wasm_i32x4_add(wasm_v32x4_shuffle(vacc0x1, vacc0x3, 0, 4, 1, 5), wasm_v32x4_shuffle(vacc0x1, vacc0x3, 2, 6, 3, 7));
98
99 v128_t vacc0x0123 = wasm_i32x4_add(wasm_v32x4_shuffle(vacc0x02, vacc0x13, 0, 4, 1, 5), wasm_v32x4_shuffle(vacc0x02, vacc0x13, 2, 6, 3, 7));
100
101 vacc0x0123 = wasm_f32x4_convert_i32x4(vacc0x0123);
102
103
104 const v128_t vscale0123 = wasm_v128_load(w);
105 w = (const float*) w + 4;
106 vacc0x0123 = wasm_f32x4_mul(vacc0x0123, vscale0123);
107
108 vacc0x0123 = wasm_f32x4_add(vacc0x0123, vmagic_bias);
109
110 vacc0x0123 = wasm_i32x4_max(vacc0x0123, vmagic_min);
111
112 vacc0x0123 = wasm_i32x4_sub(vacc0x0123, vmagic_bias_less_output_zero_point);
113
114 v128_t vacc00x0123 = wasm_i16x8_narrow_i32x4(vacc0x0123, vacc0x0123);
115
116 v128_t vout = wasm_i8x16_narrow_i16x8(vacc00x0123, vacc00x0123);
117
118 vout = wasm_i8x16_min(vout, voutput_max);
119
120 if (nc >= 4) {
121 wasm_v128_store32_lane(c0, vout, 0);
122
123 c0 = (int8_t*) ((uintptr_t) c0 + cn_stride);
124
125 a = (const int8_t**restrict) ((uintptr_t) a - ks);
126
127 nc -= 4;
128 } else {
129 if (nc & 2) {
130 wasm_v128_store16_lane(c0, vout, 0);
131 c0 += 2;
132
133 vout = wasm_u32x4_shr(vout, 16);
134 }
135 if (nc & 1) {
136 wasm_v128_store8_lane(c0, vout, 0);
137 }
138
139 nc = 0;
140 }
141 } while (nc != 0);
142 }