Debian Codegraph @

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

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-igemm/c8-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_1x8c8__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, 8 * 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 vacc0x01 = wasm_u64x2_load32x2(w); w = (const int32_t*) w + 2;
58 v128_t vacc0x23 = wasm_u64x2_load32x2(w); w = (const int32_t*) w + 2;
59 v128_t vacc0x45 = wasm_u64x2_load32x2(w); w = (const int32_t*) w + 2;
60 v128_t vacc0x67 = wasm_u64x2_load32x2(w); w = (const int32_t*) w + 2;
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 while (k != 0) {
72 const v128_t va0x01 = wasm_v128_load64_splat(a0);
73 a0 += 8;
74
75 const v128_t vb01x01 = wasm_v128_load(w); w = (const int8_t*) w + 16;
76 const v128_t vb23x01 = wasm_v128_load(w); w = (const int8_t*) w + 16;
77 const v128_t vb45x01 = wasm_v128_load(w); w = (const int8_t*) w + 16;
78 const v128_t vb67x01 = wasm_v128_load(w); w = (const int8_t*) w + 16;
79
80 vacc0x01 = wasm_i32x4_relaxed_dot_i8x16_i7x16_add(vb01x01, va0x01, vacc0x01);
81 vacc0x23 = wasm_i32x4_relaxed_dot_i8x16_i7x16_add(vb23x01, va0x01, vacc0x23);
82 vacc0x45 = wasm_i32x4_relaxed_dot_i8x16_i7x16_add(vb45x01, va0x01, vacc0x45);
83 vacc0x67 = wasm_i32x4_relaxed_dot_i8x16_i7x16_add(vb67x01, va0x01, vacc0x67);
84
85 k -= 8 * sizeof(int8_t);
86 }
87
88 p -= 1 * sizeof(void*);
89 } while (p != 0);
90
91 v128_t vacc0x0123 = wasm_i32x4_add(wasm_v32x4_shuffle(vacc0x01, vacc0x23, 0, 2, 4, 6), wasm_v32x4_shuffle(vacc0x01, vacc0x23, 1, 3, 5, 7));
92 v128_t vacc0x4567 = wasm_i32x4_add(wasm_v32x4_shuffle(vacc0x45, vacc0x67, 0, 2, 4, 6), wasm_v32x4_shuffle(vacc0x45, vacc0x67, 1, 3, 5, 7));
93
94 vacc0x0123 = wasm_f32x4_convert_i32x4(vacc0x0123);
95 vacc0x4567 = wasm_f32x4_convert_i32x4(vacc0x4567);
96
97 const v128_t vscale0123 = wasm_v128_load(w);
98 w = (const float*) w + 4;
99 const v128_t vscale4567 = wasm_v128_load(w);
100 w = (const float*) w + 4;
101 vacc0x0123 = wasm_f32x4_mul(vacc0x0123, vscale0123);
102 vacc0x4567 = wasm_f32x4_mul(vacc0x4567, vscale4567);
103
104 vacc0x0123 = wasm_f32x4_add(vacc0x0123, vmagic_bias);
105 vacc0x4567 = wasm_f32x4_add(vacc0x4567, vmagic_bias);
106
107 vacc0x0123 = wasm_i32x4_max(vacc0x0123, vmagic_min);
108 vacc0x4567 = wasm_i32x4_max(vacc0x4567, vmagic_min);
109
110 vacc0x0123 = wasm_i32x4_sub(vacc0x0123, vmagic_bias_less_output_zero_point);
111 vacc0x4567 = wasm_i32x4_sub(vacc0x4567, vmagic_bias_less_output_zero_point);
112
113 v128_t vacc0x01234567 = wasm_i16x8_narrow_i32x4(vacc0x0123, vacc0x4567);
114
115 v128_t vout0x01234567_0x01234567 = wasm_i8x16_narrow_i16x8(vacc0x01234567, vacc0x01234567);
116
117 vout0x01234567_0x01234567 = wasm_i8x16_min(vout0x01234567_0x01234567, voutput_max);
118
119 if (nc >= 8) {
120 wasm_v128_store64_lane(c0, vout0x01234567_0x01234567, 0);
121
122 c0 = (int8_t*) ((uintptr_t) c0 + cn_stride);
123
124 a = (const int8_t**restrict) ((uintptr_t) a - ks);
125
126 nc -= 8;
127 } else {
128 if (nc & 4) {
129 wasm_v128_store32_lane(c0, vout0x01234567_0x01234567, 0);
130 c0 += 4;
131
132 vout0x01234567_0x01234567 = wasm_u64x2_shr(vout0x01234567_0x01234567, 32);
133 }
134 if (nc & 2) {
135 wasm_v128_store16_lane(c0, vout0x01234567_0x01234567, 0);
136 c0 += 2;
137
138 vout0x01234567_0x01234567 = wasm_u32x4_shr(vout0x01234567_0x01234567, 16);
139 }
140 if (nc & 1) {
141 wasm_v128_store8_lane(c0, vout0x01234567_0x01234567, 0);
142 }
143
144 nc = 0;
145 }
146 } while (nc != 0);
147 }