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