Debian Codegraph @

src/qu8-igemm/gen/qu8-igemm-1x4c8-minmax-fp32-wasmsimd-dot16x2-ld64.c

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