1 // Auto-generated file. Do not edit!
2 // Template: src/f32-gemm/wasmsimd-splat.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2020 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
16
xnn_f32_gemm_minmax_ukernel_3x8__wasmrelaxedsimd_fma_splat(size_t mr,size_t nc,size_t kc,const float * restrict a,size_t a_stride,const float * restrict w,float * restrict c,size_t cm_stride,size_t cn_stride,const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])17 void xnn_f32_gemm_minmax_ukernel_3x8__wasmrelaxedsimd_fma_splat(
18 size_t mr,
19 size_t nc,
20 size_t kc,
21 const float*restrict a,
22 size_t a_stride,
23 const float*restrict w,
24 float*restrict c,
25 size_t cm_stride,
26 size_t cn_stride,
27 const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)])
28 {
29 assert(mr != 0);
30 assert(mr <= 3);
31 assert(nc != 0);
32 assert(kc != 0);
33 assert(kc % sizeof(float) == 0);
34 assert(a != NULL);
35 assert(w != NULL);
36 assert(c != NULL);
37
38 const float* a0 = a;
39 float* c0 = c;
40 const float* a1 = (const float*) ((uintptr_t) a0 + a_stride);
41 float* c1 = (float*) ((uintptr_t) c0 + cm_stride);
42 if XNN_UNPREDICTABLE(mr < 2) {
43 a1 = a0;
44 c1 = c0;
45 }
46 const float* a2 = (const float*) ((uintptr_t) a1 + a_stride);
47 float* c2 = (float*) ((uintptr_t) c1 + cm_stride);
48 if XNN_UNPREDICTABLE(mr <= 2) {
49 a2 = a1;
50 c2 = c1;
51 }
52
53 const v128_t vmin = wasm_v128_load64_splat(params->wasmsimd.min);
54 const v128_t vmax = wasm_v128_load64_splat(params->wasmsimd.max);
55 do {
56 v128_t vacc0x0123 = wasm_v128_load(w + 0);
57 v128_t vacc0x4567 = wasm_v128_load(w + 4);
58 v128_t vacc1x0123 = vacc0x0123;
59 v128_t vacc1x4567 = vacc0x4567;
60 v128_t vacc2x0123 = vacc0x0123;
61 v128_t vacc2x4567 = vacc0x4567;
62 w += 8;
63
64 size_t k = kc;
65 while (k >= 4 * sizeof(float)) {
66 const v128_t va0 = wasm_v128_load(a0);
67 a0 += 4;
68 const v128_t va1 = wasm_v128_load(a1);
69 a1 += 4;
70 const v128_t va2 = wasm_v128_load(a2);
71 a2 += 4;
72
73 const v128_t va0c0 = wasm_v32x4_shuffle(va0, va0, 0, 0, 0, 0);
74 const v128_t va1c0 = wasm_v32x4_shuffle(va1, va1, 0, 0, 0, 0);
75 const v128_t va2c0 = wasm_v32x4_shuffle(va2, va2, 0, 0, 0, 0);
76
77 const v128_t vb0123c0 = wasm_v128_load(w + 0);
78 const v128_t vb4567c0 = wasm_v128_load(w + 4);
79
80 vacc0x0123 = wasm_f32x4_add(vacc0x0123, wasm_f32x4_mul(va0c0, vb0123c0));
81 vacc1x0123 = wasm_f32x4_add(vacc1x0123, wasm_f32x4_mul(va1c0, vb0123c0));
82 vacc2x0123 = wasm_f32x4_add(vacc2x0123, wasm_f32x4_mul(va2c0, vb0123c0));
83 vacc0x4567 = wasm_f32x4_add(vacc0x4567, wasm_f32x4_mul(va0c0, vb4567c0));
84 vacc1x4567 = wasm_f32x4_add(vacc1x4567, wasm_f32x4_mul(va1c0, vb4567c0));
85 vacc2x4567 = wasm_f32x4_add(vacc2x4567, wasm_f32x4_mul(va2c0, vb4567c0));
86 const v128_t va0c1 = wasm_v32x4_shuffle(va0, va0, 1, 1, 1, 1);
87 const v128_t va1c1 = wasm_v32x4_shuffle(va1, va1, 1, 1, 1, 1);
88 const v128_t va2c1 = wasm_v32x4_shuffle(va2, va2, 1, 1, 1, 1);
89
90 const v128_t vb0123c1 = wasm_v128_load(w + 8);
91 const v128_t vb4567c1 = wasm_v128_load(w + 12);
92
93 vacc0x0123 = wasm_f32x4_add(vacc0x0123, wasm_f32x4_mul(va0c1, vb0123c1));
94 vacc1x0123 = wasm_f32x4_add(vacc1x0123, wasm_f32x4_mul(va1c1, vb0123c1));
95 vacc2x0123 = wasm_f32x4_add(vacc2x0123, wasm_f32x4_mul(va2c1, vb0123c1));
96 vacc0x4567 = wasm_f32x4_add(vacc0x4567, wasm_f32x4_mul(va0c1, vb4567c1));
97 vacc1x4567 = wasm_f32x4_add(vacc1x4567, wasm_f32x4_mul(va1c1, vb4567c1));
98 vacc2x4567 = wasm_f32x4_add(vacc2x4567, wasm_f32x4_mul(va2c1, vb4567c1));
99 const v128_t va0c2 = wasm_v32x4_shuffle(va0, va0, 2, 2, 2, 2);
100 const v128_t va1c2 = wasm_v32x4_shuffle(va1, va1, 2, 2, 2, 2);
101 const v128_t va2c2 = wasm_v32x4_shuffle(va2, va2, 2, 2, 2, 2);
102
103 const v128_t vb0123c2 = wasm_v128_load(w + 16);
104 const v128_t vb4567c2 = wasm_v128_load(w + 20);
105
106 vacc0x0123 = wasm_f32x4_add(vacc0x0123, wasm_f32x4_mul(va0c2, vb0123c2));
107 vacc1x0123 = wasm_f32x4_add(vacc1x0123, wasm_f32x4_mul(va1c2, vb0123c2));
108 vacc2x0123 = wasm_f32x4_add(vacc2x0123, wasm_f32x4_mul(va2c2, vb0123c2));
109 vacc0x4567 = wasm_f32x4_add(vacc0x4567, wasm_f32x4_mul(va0c2, vb4567c2));
110 vacc1x4567 = wasm_f32x4_add(vacc1x4567, wasm_f32x4_mul(va1c2, vb4567c2));
111 vacc2x4567 = wasm_f32x4_add(vacc2x4567, wasm_f32x4_mul(va2c2, vb4567c2));
112 const v128_t va0c3 = wasm_v32x4_shuffle(va0, va0, 3, 3, 3, 3);
113 const v128_t va1c3 = wasm_v32x4_shuffle(va1, va1, 3, 3, 3, 3);
114 const v128_t va2c3 = wasm_v32x4_shuffle(va2, va2, 3, 3, 3, 3);
115
116 const v128_t vb0123c3 = wasm_v128_load(w + 24);
117 const v128_t vb4567c3 = wasm_v128_load(w + 28);
118
119 vacc0x0123 = wasm_f32x4_add(vacc0x0123, wasm_f32x4_mul(va0c3, vb0123c3));
120 vacc1x0123 = wasm_f32x4_add(vacc1x0123, wasm_f32x4_mul(va1c3, vb0123c3));
121 vacc2x0123 = wasm_f32x4_add(vacc2x0123, wasm_f32x4_mul(va2c3, vb0123c3));
122 vacc0x4567 = wasm_f32x4_add(vacc0x4567, wasm_f32x4_mul(va0c3, vb4567c3));
123 vacc1x4567 = wasm_f32x4_add(vacc1x4567, wasm_f32x4_mul(va1c3, vb4567c3));
124 vacc2x4567 = wasm_f32x4_add(vacc2x4567, wasm_f32x4_mul(va2c3, vb4567c3));
125
126 w += 32;
127 k -= 4 * sizeof(float);
128 }
129 if XNN_UNLIKELY(k != 0) {
130 do {
131 const v128_t va0 = wasm_v128_load32_splat(a0);
132 a0 += 1;
133 const v128_t va1 = wasm_v128_load32_splat(a1);
134 a1 += 1;
135 const v128_t va2 = wasm_v128_load32_splat(a2);
136 a2 += 1;
137
138 const v128_t vb0123 = wasm_v128_load(w);
139 const v128_t vb4567 = wasm_v128_load(w + 4);
140 w += 8;
141
142 vacc0x0123 = __builtin_wasm_fma_f32x4(vacc0x0123, va0, vb0123);
143 vacc1x0123 = __builtin_wasm_fma_f32x4(vacc1x0123, va1, vb0123);
144 vacc2x0123 = __builtin_wasm_fma_f32x4(vacc2x0123, va2, vb0123);
145 vacc0x4567 = __builtin_wasm_fma_f32x4(vacc0x4567, va0, vb4567);
146 vacc1x4567 = __builtin_wasm_fma_f32x4(vacc1x4567, va1, vb4567);
147 vacc2x4567 = __builtin_wasm_fma_f32x4(vacc2x4567, va2, vb4567);
148
149 k -= sizeof(float);
150 } while (k != 0);
151 }
152
153 vacc0x0123 = __builtin_wasm_relaxed_max_f32x4(vmin, vacc0x0123);
154 vacc1x0123 = __builtin_wasm_relaxed_max_f32x4(vmin, vacc1x0123);
155 vacc2x0123 = __builtin_wasm_relaxed_max_f32x4(vmin, vacc2x0123);
156 vacc0x4567 = __builtin_wasm_relaxed_max_f32x4(vmin, vacc0x4567);
157 vacc1x4567 = __builtin_wasm_relaxed_max_f32x4(vmin, vacc1x4567);
158 vacc2x4567 = __builtin_wasm_relaxed_max_f32x4(vmin, vacc2x4567);
159
160 vacc0x0123 = __builtin_wasm_relaxed_min_f32x4(vmax, vacc0x0123);
161 vacc1x0123 = __builtin_wasm_relaxed_min_f32x4(vmax, vacc1x0123);
162 vacc2x0123 = __builtin_wasm_relaxed_min_f32x4(vmax, vacc2x0123);
163 vacc0x4567 = __builtin_wasm_relaxed_min_f32x4(vmax, vacc0x4567);
164 vacc1x4567 = __builtin_wasm_relaxed_min_f32x4(vmax, vacc1x4567);
165 vacc2x4567 = __builtin_wasm_relaxed_min_f32x4(vmax, vacc2x4567);
166
167 if XNN_LIKELY(nc >= 8) {
168 wasm_v128_store(c2, vacc2x0123);
169 wasm_v128_store(c2 + 4, vacc2x4567);
170 c2 = (float*) ((uintptr_t) c2 + cn_stride);
171 wasm_v128_store(c1, vacc1x0123);
172 wasm_v128_store(c1 + 4, vacc1x4567);
173 c1 = (float*) ((uintptr_t) c1 + cn_stride);
174 wasm_v128_store(c0, vacc0x0123);
175 wasm_v128_store(c0 + 4, vacc0x4567);
176 c0 = (float*) ((uintptr_t) c0 + cn_stride);
177
178 a2 = (const float*) ((uintptr_t) a2 - kc);
179 a1 = (const float*) ((uintptr_t) a1 - kc);
180 a0 = (const float*) ((uintptr_t) a0 - kc);
181
182 nc -= 8;
183 } else {
184 if (nc & 4) {
185 wasm_v128_store(c2, vacc2x0123);
186 wasm_v128_store(c1, vacc1x0123);
187 wasm_v128_store(c0, vacc0x0123);
188
189 vacc2x0123 = vacc2x4567;
190 vacc1x0123 = vacc1x4567;
191 vacc0x0123 = vacc0x4567;
192
193 c2 += 4;
194 c1 += 4;
195 c0 += 4;
196 }
197 if (nc & 2) {
198 *((double*) c2) = wasm_f64x2_extract_lane(vacc2x0123, 0);
199 *((double*) c1) = wasm_f64x2_extract_lane(vacc1x0123, 0);
200 *((double*) c0) = wasm_f64x2_extract_lane(vacc0x0123, 0);
201
202 vacc2x0123 = wasm_v32x4_shuffle(vacc2x0123, vacc2x0123, 2, 3, 2, 3);
203 vacc1x0123 = wasm_v32x4_shuffle(vacc1x0123, vacc1x0123, 2, 3, 2, 3);
204 vacc0x0123 = wasm_v32x4_shuffle(vacc0x0123, vacc0x0123, 2, 3, 2, 3);
205
206 c2 += 2;
207 c1 += 2;
208 c0 += 2;
209 }
210 if (nc & 1) {
211 *c2 = wasm_f32x4_extract_lane(vacc2x0123, 0);
212 *c1 = wasm_f32x4_extract_lane(vacc1x0123, 0);
213 *c0 = wasm_f32x4_extract_lane(vacc0x0123, 0);
214 }
215
216 nc = 0;
217 }
218 } while (nc != 0);
219 }
220