Debian Codegraph @

src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-1x4c2s4-minmax-fp32-wasmsimd-dot16x2-ld64.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-igemm/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/igemm.h"
16 #include "xnnpack/math.h"
17
18
19 void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_1x4c2s4__wasmsimd_dot16x2_ld64(
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 int8_t* c0 = c;
45
46 kc = round_up_po2(kc, 8 * sizeof(int8_t));
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
58 do {
59 v128_t vacc0x0123 = wasm_v128_load(w);
60 w = (const void*) ((const int32_t*) w + 4);
61
62 size_t p = ks;
63 do {
64 const int8_t* restrict a0 = a[0];
65 if XNN_UNPREDICTABLE(a0 != zero) {
66 a0 = (const int8_t*) ((uintptr_t) a0 + a_offset);
67 }
68 a += 1;
69
70 size_t k = kc;
71 do {
72 v128_t vxa0 = wasm_i16x8_load8x8(a0);
73 a0 += 8;
74
75 const v128_t vxb0 = wasm_i16x8_load8x8(w);
76
77 vacc0x0123 = wasm_i32x4_add(vacc0x0123, wasm_i32x4_dot_i16x8(vxa0, vxb0));
78 vxa0 = wasm_v32x4_shuffle(vxa0, vxa0, 1, 2, 3, 4);
79 const v128_t vxb1 = wasm_i16x8_load8x8((const int8_t*) w + 8);
80
81 vacc0x0123 = wasm_i32x4_add(vacc0x0123, wasm_i32x4_dot_i16x8(vxa0, vxb1));
82 vxa0 = wasm_v32x4_shuffle(vxa0, vxa0, 1, 2, 3, 4);
83 const v128_t vxb2 = wasm_i16x8_load8x8((const int8_t*) w + 16);
84
85 vacc0x0123 = wasm_i32x4_add(vacc0x0123, wasm_i32x4_dot_i16x8(vxa0, vxb2));
86 vxa0 = wasm_v32x4_shuffle(vxa0, vxa0, 1, 2, 3, 4);
87 const v128_t vxb3 = wasm_i16x8_load8x8((const int8_t*) w + 24);
88
89 vacc0x0123 = wasm_i32x4_add(vacc0x0123, wasm_i32x4_dot_i16x8(vxa0, vxb3));
90
91 w = (const int8_t*) w + 32;
92 k -= 8 * sizeof(int8_t);
93 } while (k != 0);
94 p -= 1 * sizeof(void*);
95 } while (p != 0);
96
97 vacc0x0123 = wasm_f32x4_convert_i32x4(vacc0x0123);
98
99 const v128_t vscale0123 = wasm_v128_load(w);
100 w = (const float*) w + 4;
101 vacc0x0123 = wasm_f32x4_mul(vacc0x0123, vscale0123);
102
103 vacc0x0123 = wasm_f32x4_add(vacc0x0123, vmagic_bias);
104
105 vacc0x0123 = wasm_i32x4_max(vacc0x0123, vmagic_min);
106
107 vacc0x0123 = wasm_i32x4_sub(vacc0x0123, vmagic_bias_less_output_zero_point);
108
109 v128_t vacc00x0123 = wasm_i16x8_narrow_i32x4(vacc0x0123, vacc0x0123);
110
111 v128_t vout = wasm_i8x16_narrow_i16x8(vacc00x0123, vacc00x0123);
112
113 vout = wasm_i8x16_min(vout, voutput_max);
114
115 if (nc >= 4) {
116 wasm_v128_store32_lane(c0, vout, 0);
117
118 c0 = (int8_t*) ((uintptr_t) c0 + cn_stride);
119
120 a = (const int8_t**restrict) ((uintptr_t) a - ks);
121
122 nc -= 4;
123 } else {
124 if (nc & 2) {
125 wasm_v128_store16_lane(c0, vout, 0);
126 c0 += 2;
127
128 vout = wasm_u32x4_shr(vout, 16);
129 }
130 if (nc & 1) {
131 wasm_v128_store8_lane(c0, vout, 0);
132 }
133
134 nc = 0;
135 }
136 } while (nc != 0);
137 }