Debian Codegraph @

src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-1x8c16-minmax-fp32-wasmsdot.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-igemm/MRx4c16-wasmdot.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2023 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_qs8_qc8w_igemm_minmax_fp32_ukernel_1x8c16__wasmsdot(
19 size_t mr,
20 size_t nc,
21 size_t kc,
22 size_t ks,
23 const int8_t** restrict a,
24 const void* restrict w,
25 int8_t* restrict c,
26 size_t cm_stride,
27 size_t cn_stride,
28 size_t a_offset,
29 const int8_t* zero,
30 const union xnn_qs8_qc8w_conv_minmax_params 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(ks != 0);
37 assert(ks % (1 * sizeof(void*)) == 0);
38 assert(a_offset % sizeof(int8_t) == 0);
39 assert(a != NULL);
40 assert(w != NULL);
41 assert(c != NULL);
42
43 kc = round_up_po2(kc, 16 * sizeof(int8_t));
44 int8_t* c0 = c;
45
46 const v128_t vmagic_bias = wasm_f32x4_const_splat(12582912.0f);
47 const int32_t output_min_less_zero_point = (int32_t) params->fp32_scalar.output_min - (int32_t) params->fp32_scalar.output_zero_point;
48 const v128_t vmagic_min = wasm_i32x4_splat((int32_t) float_as_uint32(12582912.0f + output_min_less_zero_point));
49 const v128_t vmagic_bias_less_output_zero_point = wasm_i32x4_splat(INT32_C(0x4B400000) - (int32_t) params->fp32_scalar.output_zero_point);
50 const v128_t voutput_max = wasm_i8x16_splat(params->fp32_scalar.output_max);
51 XNN_FORCE_REALIZATION(vmagic_bias);
52 XNN_FORCE_REALIZATION(vmagic_min);
53 XNN_FORCE_REALIZATION(vmagic_bias_less_output_zero_point);
54 XNN_FORCE_REALIZATION(voutput_max);
55
56 do {
57 v128_t vacc0x0 = wasm_v128_load32_zero(w);
58 v128_t vacc0x1 = wasm_v128_load32_zero((const int32_t*) w + 1);
59 v128_t vacc0x2 = wasm_v128_load32_zero((const int32_t*) w + 2);
60 v128_t vacc0x3 = wasm_v128_load32_zero((const int32_t*) w + 3);
61 v128_t vacc0x4 = wasm_v128_load32_zero((const int32_t*) w + 4);
62 v128_t vacc0x5 = wasm_v128_load32_zero((const int32_t*) w + 5);
63 v128_t vacc0x6 = wasm_v128_load32_zero((const int32_t*) w + 6);
64 v128_t vacc0x7 = wasm_v128_load32_zero((const int32_t*) w + 7);
65 w = (const int32_t*) w + 8;
66
67 size_t p = ks;
68 do {
69 const int8_t* restrict a0 = a[0];
70 if XNN_UNPREDICTABLE(a0 != zero) {
71 a0 = (const int8_t*) ((uintptr_t) a0 + a_offset);
72 }
73 a += 1;
74
75 size_t k = kc;
76 do {
77 const v128_t va0 = wasm_v128_load(a0);
78 a0 += 16;
79
80 const v128_t vb0 = wasm_v128_load(w);
81 vacc0x0 = wasm_i32x4_relaxed_dot_i8x16_i7x16_add(vb0, va0, vacc0x0);
82 const v128_t vb1 = wasm_v128_load((const int8_t*) w + 16);
83 vacc0x1 = wasm_i32x4_relaxed_dot_i8x16_i7x16_add(vb1, va0, vacc0x1);
84 const v128_t vb2 = wasm_v128_load((const int8_t*) w + 32);
85 vacc0x2 = wasm_i32x4_relaxed_dot_i8x16_i7x16_add(vb2, va0, vacc0x2);
86 const v128_t vb3 = wasm_v128_load((const int8_t*) w + 48);
87 vacc0x3 = wasm_i32x4_relaxed_dot_i8x16_i7x16_add(vb3, va0, vacc0x3);
88 const v128_t vb4 = wasm_v128_load((const int8_t*) w + 64);
89 vacc0x4 = wasm_i32x4_relaxed_dot_i8x16_i7x16_add(vb4, va0, vacc0x4);
90 const v128_t vb5 = wasm_v128_load((const int8_t*) w + 80);
91 vacc0x5 = wasm_i32x4_relaxed_dot_i8x16_i7x16_add(vb5, va0, vacc0x5);
92 const v128_t vb6 = wasm_v128_load((const int8_t*) w + 96);
93 vacc0x6 = wasm_i32x4_relaxed_dot_i8x16_i7x16_add(vb6, va0, vacc0x6);
94 const v128_t vb7 = wasm_v128_load((const int8_t*) w + 112);
95 vacc0x7 = wasm_i32x4_relaxed_dot_i8x16_i7x16_add(vb7, va0, vacc0x7);
96
97 w = (const int8_t*) w + 128;
98 k -= 16 * sizeof(int8_t);
99 } while (k != 0);
100 p -= 1 * sizeof(void*);
101 } while (p != 0);
102
103 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));
104 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));
105 const v128_t vacc0x46 = wasm_i32x4_add(wasm_v32x4_shuffle(vacc0x4, vacc0x6, 0, 4, 1, 5), wasm_v32x4_shuffle(vacc0x4, vacc0x6, 2, 6, 3, 7));
106 const v128_t vacc0x57 = wasm_i32x4_add(wasm_v32x4_shuffle(vacc0x5, vacc0x7, 0, 4, 1, 5), wasm_v32x4_shuffle(vacc0x5, vacc0x7, 2, 6, 3, 7));
107
108 v128_t vacc0x0123 = wasm_i32x4_add(wasm_v32x4_shuffle(vacc0x02, vacc0x13, 0, 4, 1, 5), wasm_v32x4_shuffle(vacc0x02, vacc0x13, 2, 6, 3, 7));
109 v128_t vacc0x4567 = wasm_i32x4_add(wasm_v32x4_shuffle(vacc0x46, vacc0x57, 0, 4, 1, 5), wasm_v32x4_shuffle(vacc0x46, vacc0x57, 2, 6, 3, 7));
110
111 vacc0x0123 = wasm_f32x4_convert_i32x4(vacc0x0123);
112 vacc0x4567 = wasm_f32x4_convert_i32x4(vacc0x4567);
113
114 const v128_t vscale0123 = wasm_v128_load(w);
115 w = (const float*) w + 4;
116 const v128_t vscale4567 = wasm_v128_load(w);
117 w = (const float*) w + 4;
118 vacc0x0123 = wasm_f32x4_mul(vacc0x0123, vscale0123);
119 vacc0x4567 = wasm_f32x4_mul(vacc0x4567, vscale4567);
120
121 vacc0x0123 = wasm_f32x4_add(vacc0x0123, vmagic_bias);
122 vacc0x4567 = wasm_f32x4_add(vacc0x4567, vmagic_bias);
123
124 vacc0x0123 = wasm_i32x4_max(vacc0x0123, vmagic_min);
125 vacc0x4567 = wasm_i32x4_max(vacc0x4567, vmagic_min);
126
127 vacc0x0123 = wasm_i32x4_sub(vacc0x0123, vmagic_bias_less_output_zero_point);
128 vacc0x4567 = wasm_i32x4_sub(vacc0x4567, vmagic_bias_less_output_zero_point);
129
130 v128_t vacc0x01234567 = wasm_i16x8_narrow_i32x4(vacc0x0123, vacc0x4567);
131
132 v128_t vout0x01234567_0x01234567 = wasm_i8x16_narrow_i16x8(vacc0x01234567, vacc0x01234567);
133
134 vout0x01234567_0x01234567 = wasm_i8x16_min(vout0x01234567_0x01234567, voutput_max);
135
136 if (nc >= 8) {
137 wasm_v128_store64_lane(c0, vout0x01234567_0x01234567, 0);
138
139 c0 = (int8_t*) ((uintptr_t) c0 + cn_stride);
140
141 a = (const int8_t**restrict) ((uintptr_t) a - ks);
142
143 nc -= 8;
144 } else {
145 if (nc & 4) {
146 wasm_v128_store32_lane(c0, vout0x01234567_0x01234567, 0);
147 c0 += 4;
148
149 vout0x01234567_0x01234567 = wasm_u64x2_shr(vout0x01234567_0x01234567, 32);
150 }
151 if (nc & 2) {
152 wasm_v128_store16_lane(c0, vout0x01234567_0x01234567, 0);
153 c0 += 2;
154
155 vout0x01234567_0x01234567 = wasm_u32x4_shr(vout0x01234567_0x01234567, 16);
156 }
157 if (nc & 1) {
158 wasm_v128_store8_lane(c0, vout0x01234567_0x01234567, 0);
159 }
160
161 nc = 0;
162 }
163 } while (nc != 0);
164 }