• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_gemminc_minmax_ukernel_5x8__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 float * restrict acc,const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])17 void xnn_f32_gemminc_minmax_ukernel_5x8__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 float*restrict acc,
28     const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)])
29 {
30   assert(mr != 0);
31   assert(mr <= 5);
32   assert(nc != 0);
33   assert(kc != 0);
34   assert(kc % sizeof(float) == 0);
35   assert(a != NULL);
36   assert(w != NULL);
37   assert(c != NULL);
38   assert(acc != NULL);
39 
40   const float* a0 = a;
41   float* c0 = c;
42   const float* a1 = (const float*) ((uintptr_t) a0 + a_stride);
43   float* c1 = (float*) ((uintptr_t) c0 + cm_stride);
44   if XNN_UNPREDICTABLE(mr < 2) {
45     a1 = a0;
46     c1 = c0;
47   }
48   const float* a2 = (const float*) ((uintptr_t) a1 + a_stride);
49   float* c2 = (float*) ((uintptr_t) c1 + cm_stride);
50   if XNN_UNPREDICTABLE(mr <= 2) {
51     a2 = a1;
52     c2 = c1;
53   }
54   const float* a3 = (const float*) ((uintptr_t) a2 + a_stride);
55   float* c3 = (float*) ((uintptr_t) c2 + cm_stride);
56   if XNN_UNPREDICTABLE(mr < 4) {
57     a3 = a2;
58     c3 = c2;
59   }
60   const float* a4 = (const float*) ((uintptr_t) a3 + a_stride);
61   float* c4 = (float*) ((uintptr_t) c3 + cm_stride);
62   if XNN_UNPREDICTABLE(mr <= 4) {
63     a4 = a3;
64     c4 = c3;
65   }
66 
67   const v128_t vmin = wasm_v128_load64_splat(params->wasmsimd.min);
68   const v128_t vmax = wasm_v128_load64_splat(params->wasmsimd.max);
69   do {
70     v128_t vacc0x0123 = wasm_v128_load(acc + 0);
71     v128_t vacc0x4567 = wasm_v128_load(acc + 4);
72     v128_t vacc1x0123 = wasm_v128_load(acc + 8);
73     v128_t vacc1x4567 = wasm_v128_load(acc + 12);
74     v128_t vacc2x0123 = wasm_v128_load(acc + 16);
75     v128_t vacc2x4567 = wasm_v128_load(acc + 20);
76     v128_t vacc3x0123 = wasm_v128_load(acc + 24);
77     v128_t vacc3x4567 = wasm_v128_load(acc + 28);
78     v128_t vacc4x0123 = wasm_v128_load(acc + 32);
79     v128_t vacc4x4567 = wasm_v128_load(acc + 36);
80     acc += 40;
81 
82     size_t k = kc;
83     while (k >= 4 * sizeof(float)) {
84       const v128_t va0 = wasm_v128_load(a0);
85       a0 += 4;
86       const v128_t va1 = wasm_v128_load(a1);
87       a1 += 4;
88       const v128_t va2 = wasm_v128_load(a2);
89       a2 += 4;
90       const v128_t va3 = wasm_v128_load(a3);
91       a3 += 4;
92       const v128_t va4 = wasm_v128_load(a4);
93       a4 += 4;
94 
95       const v128_t va0c0 = wasm_v32x4_shuffle(va0, va0, 0, 0, 0, 0);
96       const v128_t va1c0 = wasm_v32x4_shuffle(va1, va1, 0, 0, 0, 0);
97       const v128_t va2c0 = wasm_v32x4_shuffle(va2, va2, 0, 0, 0, 0);
98       const v128_t va3c0 = wasm_v32x4_shuffle(va3, va3, 0, 0, 0, 0);
99       const v128_t va4c0 = wasm_v32x4_shuffle(va4, va4, 0, 0, 0, 0);
100 
101       const v128_t vb0123c0 = wasm_v128_load(w + 0);
102       const v128_t vb4567c0 = wasm_v128_load(w + 4);
103 
104       vacc0x0123 = wasm_f32x4_add(vacc0x0123, wasm_f32x4_mul(va0c0, vb0123c0));
105       vacc1x0123 = wasm_f32x4_add(vacc1x0123, wasm_f32x4_mul(va1c0, vb0123c0));
106       vacc2x0123 = wasm_f32x4_add(vacc2x0123, wasm_f32x4_mul(va2c0, vb0123c0));
107       vacc3x0123 = wasm_f32x4_add(vacc3x0123, wasm_f32x4_mul(va3c0, vb0123c0));
108       vacc4x0123 = wasm_f32x4_add(vacc4x0123, wasm_f32x4_mul(va4c0, vb0123c0));
109       vacc0x4567 = wasm_f32x4_add(vacc0x4567, wasm_f32x4_mul(va0c0, vb4567c0));
110       vacc1x4567 = wasm_f32x4_add(vacc1x4567, wasm_f32x4_mul(va1c0, vb4567c0));
111       vacc2x4567 = wasm_f32x4_add(vacc2x4567, wasm_f32x4_mul(va2c0, vb4567c0));
112       vacc3x4567 = wasm_f32x4_add(vacc3x4567, wasm_f32x4_mul(va3c0, vb4567c0));
113       vacc4x4567 = wasm_f32x4_add(vacc4x4567, wasm_f32x4_mul(va4c0, vb4567c0));
114       const v128_t va0c1 = wasm_v32x4_shuffle(va0, va0, 1, 1, 1, 1);
115       const v128_t va1c1 = wasm_v32x4_shuffle(va1, va1, 1, 1, 1, 1);
116       const v128_t va2c1 = wasm_v32x4_shuffle(va2, va2, 1, 1, 1, 1);
117       const v128_t va3c1 = wasm_v32x4_shuffle(va3, va3, 1, 1, 1, 1);
118       const v128_t va4c1 = wasm_v32x4_shuffle(va4, va4, 1, 1, 1, 1);
119 
120       const v128_t vb0123c1 = wasm_v128_load(w + 8);
121       const v128_t vb4567c1 = wasm_v128_load(w + 12);
122 
123       vacc0x0123 = wasm_f32x4_add(vacc0x0123, wasm_f32x4_mul(va0c1, vb0123c1));
124       vacc1x0123 = wasm_f32x4_add(vacc1x0123, wasm_f32x4_mul(va1c1, vb0123c1));
125       vacc2x0123 = wasm_f32x4_add(vacc2x0123, wasm_f32x4_mul(va2c1, vb0123c1));
126       vacc3x0123 = wasm_f32x4_add(vacc3x0123, wasm_f32x4_mul(va3c1, vb0123c1));
127       vacc4x0123 = wasm_f32x4_add(vacc4x0123, wasm_f32x4_mul(va4c1, vb0123c1));
128       vacc0x4567 = wasm_f32x4_add(vacc0x4567, wasm_f32x4_mul(va0c1, vb4567c1));
129       vacc1x4567 = wasm_f32x4_add(vacc1x4567, wasm_f32x4_mul(va1c1, vb4567c1));
130       vacc2x4567 = wasm_f32x4_add(vacc2x4567, wasm_f32x4_mul(va2c1, vb4567c1));
131       vacc3x4567 = wasm_f32x4_add(vacc3x4567, wasm_f32x4_mul(va3c1, vb4567c1));
132       vacc4x4567 = wasm_f32x4_add(vacc4x4567, wasm_f32x4_mul(va4c1, vb4567c1));
133       const v128_t va0c2 = wasm_v32x4_shuffle(va0, va0, 2, 2, 2, 2);
134       const v128_t va1c2 = wasm_v32x4_shuffle(va1, va1, 2, 2, 2, 2);
135       const v128_t va2c2 = wasm_v32x4_shuffle(va2, va2, 2, 2, 2, 2);
136       const v128_t va3c2 = wasm_v32x4_shuffle(va3, va3, 2, 2, 2, 2);
137       const v128_t va4c2 = wasm_v32x4_shuffle(va4, va4, 2, 2, 2, 2);
138 
139       const v128_t vb0123c2 = wasm_v128_load(w + 16);
140       const v128_t vb4567c2 = wasm_v128_load(w + 20);
141 
142       vacc0x0123 = wasm_f32x4_add(vacc0x0123, wasm_f32x4_mul(va0c2, vb0123c2));
143       vacc1x0123 = wasm_f32x4_add(vacc1x0123, wasm_f32x4_mul(va1c2, vb0123c2));
144       vacc2x0123 = wasm_f32x4_add(vacc2x0123, wasm_f32x4_mul(va2c2, vb0123c2));
145       vacc3x0123 = wasm_f32x4_add(vacc3x0123, wasm_f32x4_mul(va3c2, vb0123c2));
146       vacc4x0123 = wasm_f32x4_add(vacc4x0123, wasm_f32x4_mul(va4c2, vb0123c2));
147       vacc0x4567 = wasm_f32x4_add(vacc0x4567, wasm_f32x4_mul(va0c2, vb4567c2));
148       vacc1x4567 = wasm_f32x4_add(vacc1x4567, wasm_f32x4_mul(va1c2, vb4567c2));
149       vacc2x4567 = wasm_f32x4_add(vacc2x4567, wasm_f32x4_mul(va2c2, vb4567c2));
150       vacc3x4567 = wasm_f32x4_add(vacc3x4567, wasm_f32x4_mul(va3c2, vb4567c2));
151       vacc4x4567 = wasm_f32x4_add(vacc4x4567, wasm_f32x4_mul(va4c2, vb4567c2));
152       const v128_t va0c3 = wasm_v32x4_shuffle(va0, va0, 3, 3, 3, 3);
153       const v128_t va1c3 = wasm_v32x4_shuffle(va1, va1, 3, 3, 3, 3);
154       const v128_t va2c3 = wasm_v32x4_shuffle(va2, va2, 3, 3, 3, 3);
155       const v128_t va3c3 = wasm_v32x4_shuffle(va3, va3, 3, 3, 3, 3);
156       const v128_t va4c3 = wasm_v32x4_shuffle(va4, va4, 3, 3, 3, 3);
157 
158       const v128_t vb0123c3 = wasm_v128_load(w + 24);
159       const v128_t vb4567c3 = wasm_v128_load(w + 28);
160 
161       vacc0x0123 = wasm_f32x4_add(vacc0x0123, wasm_f32x4_mul(va0c3, vb0123c3));
162       vacc1x0123 = wasm_f32x4_add(vacc1x0123, wasm_f32x4_mul(va1c3, vb0123c3));
163       vacc2x0123 = wasm_f32x4_add(vacc2x0123, wasm_f32x4_mul(va2c3, vb0123c3));
164       vacc3x0123 = wasm_f32x4_add(vacc3x0123, wasm_f32x4_mul(va3c3, vb0123c3));
165       vacc4x0123 = wasm_f32x4_add(vacc4x0123, wasm_f32x4_mul(va4c3, vb0123c3));
166       vacc0x4567 = wasm_f32x4_add(vacc0x4567, wasm_f32x4_mul(va0c3, vb4567c3));
167       vacc1x4567 = wasm_f32x4_add(vacc1x4567, wasm_f32x4_mul(va1c3, vb4567c3));
168       vacc2x4567 = wasm_f32x4_add(vacc2x4567, wasm_f32x4_mul(va2c3, vb4567c3));
169       vacc3x4567 = wasm_f32x4_add(vacc3x4567, wasm_f32x4_mul(va3c3, vb4567c3));
170       vacc4x4567 = wasm_f32x4_add(vacc4x4567, wasm_f32x4_mul(va4c3, vb4567c3));
171 
172       w += 32;
173       k -= 4 * sizeof(float);
174     }
175     if XNN_UNLIKELY(k != 0) {
176       do {
177         const v128_t va0 = wasm_v128_load32_splat(a0);
178         a0 += 1;
179         const v128_t va1 = wasm_v128_load32_splat(a1);
180         a1 += 1;
181         const v128_t va2 = wasm_v128_load32_splat(a2);
182         a2 += 1;
183         const v128_t va3 = wasm_v128_load32_splat(a3);
184         a3 += 1;
185         const v128_t va4 = wasm_v128_load32_splat(a4);
186         a4 += 1;
187 
188         const v128_t vb0123 = wasm_v128_load(w);
189         const v128_t vb4567 = wasm_v128_load(w + 4);
190         w += 8;
191 
192         vacc0x0123 = __builtin_wasm_fma_f32x4(vacc0x0123, va0, vb0123);
193         vacc1x0123 = __builtin_wasm_fma_f32x4(vacc1x0123, va1, vb0123);
194         vacc2x0123 = __builtin_wasm_fma_f32x4(vacc2x0123, va2, vb0123);
195         vacc3x0123 = __builtin_wasm_fma_f32x4(vacc3x0123, va3, vb0123);
196         vacc4x0123 = __builtin_wasm_fma_f32x4(vacc4x0123, va4, vb0123);
197         vacc0x4567 = __builtin_wasm_fma_f32x4(vacc0x4567, va0, vb4567);
198         vacc1x4567 = __builtin_wasm_fma_f32x4(vacc1x4567, va1, vb4567);
199         vacc2x4567 = __builtin_wasm_fma_f32x4(vacc2x4567, va2, vb4567);
200         vacc3x4567 = __builtin_wasm_fma_f32x4(vacc3x4567, va3, vb4567);
201         vacc4x4567 = __builtin_wasm_fma_f32x4(vacc4x4567, va4, vb4567);
202 
203         k -= sizeof(float);
204       } while (k != 0);
205     }
206 
207     vacc0x0123 = __builtin_wasm_relaxed_max_f32x4(vmin, vacc0x0123);
208     vacc1x0123 = __builtin_wasm_relaxed_max_f32x4(vmin, vacc1x0123);
209     vacc2x0123 = __builtin_wasm_relaxed_max_f32x4(vmin, vacc2x0123);
210     vacc3x0123 = __builtin_wasm_relaxed_max_f32x4(vmin, vacc3x0123);
211     vacc4x0123 = __builtin_wasm_relaxed_max_f32x4(vmin, vacc4x0123);
212     vacc0x4567 = __builtin_wasm_relaxed_max_f32x4(vmin, vacc0x4567);
213     vacc1x4567 = __builtin_wasm_relaxed_max_f32x4(vmin, vacc1x4567);
214     vacc2x4567 = __builtin_wasm_relaxed_max_f32x4(vmin, vacc2x4567);
215     vacc3x4567 = __builtin_wasm_relaxed_max_f32x4(vmin, vacc3x4567);
216     vacc4x4567 = __builtin_wasm_relaxed_max_f32x4(vmin, vacc4x4567);
217 
218     vacc0x0123 = __builtin_wasm_relaxed_min_f32x4(vmax, vacc0x0123);
219     vacc1x0123 = __builtin_wasm_relaxed_min_f32x4(vmax, vacc1x0123);
220     vacc2x0123 = __builtin_wasm_relaxed_min_f32x4(vmax, vacc2x0123);
221     vacc3x0123 = __builtin_wasm_relaxed_min_f32x4(vmax, vacc3x0123);
222     vacc4x0123 = __builtin_wasm_relaxed_min_f32x4(vmax, vacc4x0123);
223     vacc0x4567 = __builtin_wasm_relaxed_min_f32x4(vmax, vacc0x4567);
224     vacc1x4567 = __builtin_wasm_relaxed_min_f32x4(vmax, vacc1x4567);
225     vacc2x4567 = __builtin_wasm_relaxed_min_f32x4(vmax, vacc2x4567);
226     vacc3x4567 = __builtin_wasm_relaxed_min_f32x4(vmax, vacc3x4567);
227     vacc4x4567 = __builtin_wasm_relaxed_min_f32x4(vmax, vacc4x4567);
228 
229     if XNN_LIKELY(nc >= 8) {
230       wasm_v128_store(c4, vacc4x0123);
231       wasm_v128_store(c4 + 4, vacc4x4567);
232       c4 = (float*) ((uintptr_t) c4 + cn_stride);
233       wasm_v128_store(c3, vacc3x0123);
234       wasm_v128_store(c3 + 4, vacc3x4567);
235       c3 = (float*) ((uintptr_t) c3 + cn_stride);
236       wasm_v128_store(c2, vacc2x0123);
237       wasm_v128_store(c2 + 4, vacc2x4567);
238       c2 = (float*) ((uintptr_t) c2 + cn_stride);
239       wasm_v128_store(c1, vacc1x0123);
240       wasm_v128_store(c1 + 4, vacc1x4567);
241       c1 = (float*) ((uintptr_t) c1 + cn_stride);
242       wasm_v128_store(c0, vacc0x0123);
243       wasm_v128_store(c0 + 4, vacc0x4567);
244       c0 = (float*) ((uintptr_t) c0 + cn_stride);
245 
246       a4 = (const float*) ((uintptr_t) a4 - kc);
247       a3 = (const float*) ((uintptr_t) a3 - kc);
248       a2 = (const float*) ((uintptr_t) a2 - kc);
249       a1 = (const float*) ((uintptr_t) a1 - kc);
250       a0 = (const float*) ((uintptr_t) a0 - kc);
251 
252       nc -= 8;
253     } else {
254       if (nc & 4) {
255         wasm_v128_store(c4, vacc4x0123);
256         wasm_v128_store(c3, vacc3x0123);
257         wasm_v128_store(c2, vacc2x0123);
258         wasm_v128_store(c1, vacc1x0123);
259         wasm_v128_store(c0, vacc0x0123);
260 
261         vacc4x0123 = vacc4x4567;
262         vacc3x0123 = vacc3x4567;
263         vacc2x0123 = vacc2x4567;
264         vacc1x0123 = vacc1x4567;
265         vacc0x0123 = vacc0x4567;
266 
267         c4 += 4;
268         c3 += 4;
269         c2 += 4;
270         c1 += 4;
271         c0 += 4;
272       }
273       if (nc & 2) {
274         *((double*) c4) = wasm_f64x2_extract_lane(vacc4x0123, 0);
275         *((double*) c3) = wasm_f64x2_extract_lane(vacc3x0123, 0);
276         *((double*) c2) = wasm_f64x2_extract_lane(vacc2x0123, 0);
277         *((double*) c1) = wasm_f64x2_extract_lane(vacc1x0123, 0);
278         *((double*) c0) = wasm_f64x2_extract_lane(vacc0x0123, 0);
279 
280         vacc4x0123 = wasm_v32x4_shuffle(vacc4x0123, vacc4x0123, 2, 3, 2, 3);
281         vacc3x0123 = wasm_v32x4_shuffle(vacc3x0123, vacc3x0123, 2, 3, 2, 3);
282         vacc2x0123 = wasm_v32x4_shuffle(vacc2x0123, vacc2x0123, 2, 3, 2, 3);
283         vacc1x0123 = wasm_v32x4_shuffle(vacc1x0123, vacc1x0123, 2, 3, 2, 3);
284         vacc0x0123 = wasm_v32x4_shuffle(vacc0x0123, vacc0x0123, 2, 3, 2, 3);
285 
286         c4 += 2;
287         c3 += 2;
288         c2 += 2;
289         c1 += 2;
290         c0 += 2;
291       }
292       if (nc & 1) {
293         *c4 = wasm_f32x4_extract_lane(vacc4x0123, 0);
294         *c3 = wasm_f32x4_extract_lane(vacc3x0123, 0);
295         *c2 = wasm_f32x4_extract_lane(vacc2x0123, 0);
296         *c1 = wasm_f32x4_extract_lane(vacc1x0123, 0);
297         *c0 = wasm_f32x4_extract_lane(vacc0x0123, 0);
298       }
299 
300       nc = 0;
301     }
302   } while (nc != 0);
303 }
304