• 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_1x8__wasmrelaxedsimd_fma_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_1x8__wasmrelaxedsimd_fma_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 <= 1);
33   assert(nc != 0);
34   assert(kc != 0);
35   assert(kc % sizeof(float) == 0);
36   assert(ks != 0);
37   assert(ks % (1 * 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 
45   do {
46     v128_t vacc0x0123 = wasm_v128_load(w);
47     v128_t vacc0x4567 = wasm_v128_load(w + 4);
48     w += 8;
49 
50     size_t p = ks;
51     do {
52       const float* restrict a0 = a[0];
53       assert(a0 != NULL);
54       if XNN_UNPREDICTABLE(a0 != zero) {
55         a0 = (const float*) ((uintptr_t) a0 + a_offset);
56       }
57       a += 1;
58 
59       size_t k = kc;
60       while (k >= 4 * sizeof(float)) {
61         const v128_t va0 = wasm_v128_load(a0);
62         a0 += 4;
63 
64         const v128_t va0c0 = wasm_v32x4_shuffle(va0, va0, 0, 0, 0, 0);
65 
66         const v128_t vb0123c0 = wasm_v128_load(w + 0);
67         const v128_t vb4567c0 = wasm_v128_load(w + 4);
68 
69         vacc0x0123 = __builtin_wasm_fma_f32x4(vacc0x0123, va0c0, vb0123c0);
70         vacc0x4567 = __builtin_wasm_fma_f32x4(vacc0x4567, va0c0, vb4567c0);
71         const v128_t va0c1 = wasm_v32x4_shuffle(va0, va0, 1, 1, 1, 1);
72 
73         const v128_t vb0123c1 = wasm_v128_load(w + 8);
74         const v128_t vb4567c1 = wasm_v128_load(w + 12);
75 
76         vacc0x0123 = __builtin_wasm_fma_f32x4(vacc0x0123, va0c1, vb0123c1);
77         vacc0x4567 = __builtin_wasm_fma_f32x4(vacc0x4567, va0c1, vb4567c1);
78         const v128_t va0c2 = wasm_v32x4_shuffle(va0, va0, 2, 2, 2, 2);
79 
80         const v128_t vb0123c2 = wasm_v128_load(w + 16);
81         const v128_t vb4567c2 = wasm_v128_load(w + 20);
82 
83         vacc0x0123 = __builtin_wasm_fma_f32x4(vacc0x0123, va0c2, vb0123c2);
84         vacc0x4567 = __builtin_wasm_fma_f32x4(vacc0x4567, va0c2, vb4567c2);
85         const v128_t va0c3 = wasm_v32x4_shuffle(va0, va0, 3, 3, 3, 3);
86 
87         const v128_t vb0123c3 = wasm_v128_load(w + 24);
88         const v128_t vb4567c3 = wasm_v128_load(w + 28);
89 
90         vacc0x0123 = __builtin_wasm_fma_f32x4(vacc0x0123, va0c3, vb0123c3);
91         vacc0x4567 = __builtin_wasm_fma_f32x4(vacc0x4567, va0c3, vb4567c3);
92 
93         w += 32;
94         k -= 4 * sizeof(float);
95       }
96       if XNN_UNLIKELY(k != 0) {
97         do {
98           const v128_t vb0123 = wasm_v128_load(w);
99           const v128_t vb4567 = wasm_v128_load(w + 4);
100           w += 8;
101 
102           const v128_t va0 = wasm_v128_load32_splat(a0);
103           a0 += 1;
104 
105           vacc0x0123 = __builtin_wasm_fma_f32x4(vacc0x0123, va0, vb0123);
106           vacc0x4567 = __builtin_wasm_fma_f32x4(vacc0x4567, va0, vb4567);
107           k -= sizeof(float);
108         } while (k != 0);
109       }
110       p -= 1 * sizeof(void*);
111     } while (p != 0);
112 
113 
114     if XNN_LIKELY(nc >= 8) {
115       wasm_v128_store(c0, vacc0x0123);
116       wasm_v128_store(c0 + 4, vacc0x4567);
117       c0 = (float*) ((uintptr_t) c0 + cn_stride);
118 
119       a = (const float**restrict) ((uintptr_t) a - ks);
120       nc -= 8;
121     } else {
122       if (nc & 4) {
123         wasm_v128_store(c0, vacc0x0123);
124 
125         vacc0x0123 = vacc0x4567;
126 
127         c0 += 4;
128       }
129       if (nc & 2) {
130         *((double*) c0) = wasm_f64x2_extract_lane(vacc0x0123, 0);
131 
132         vacc0x0123 = wasm_v32x4_shuffle(vacc0x0123, vacc0x0123, 2, 3, 2, 3);
133 
134         c0 += 2;
135       }
136       if (nc & 1) {
137         *c0 = wasm_f32x4_extract_lane(vacc0x0123, 0);
138       }
139 
140       nc = 0;
141     }
142   } while (nc != 0);
143 }
144