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