• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Auto-generated file. Do not edit!
2 //   Template: src/f32-gemm/wasmsimd-loadsplat.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_ukernel_6x8__wasmrelaxedsimd_fma_loadsplat(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_default_params params[restrict XNN_MIN_ELEMENTS (1)])17 void xnn_f32_gemm_ukernel_6x8__wasmrelaxedsimd_fma_loadsplat(
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_default_params params[restrict XNN_MIN_ELEMENTS(1)])
28 {
29   assert(mr != 0);
30   assert(mr <= 6);
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   const float* a3 = (const float*) ((uintptr_t) a2 + a_stride);
53   float* c3 = (float*) ((uintptr_t) c2 + cm_stride);
54   if XNN_UNPREDICTABLE(mr < 4) {
55     a3 = a2;
56     c3 = c2;
57   }
58   const float* a4 = (const float*) ((uintptr_t) a3 + a_stride);
59   float* c4 = (float*) ((uintptr_t) c3 + cm_stride);
60   if XNN_UNPREDICTABLE(mr <= 4) {
61     a4 = a3;
62     c4 = c3;
63   }
64   const float* a5 = (const float*) ((uintptr_t) a4 + a_stride);
65   float* c5 = (float*) ((uintptr_t) c4 + cm_stride);
66   if XNN_UNPREDICTABLE(mr != 6) {
67     a5 = a4;
68     c5 = c4;
69   }
70 
71   do {
72     v128_t vacc0x0123 = wasm_v128_load(w + 0);
73     v128_t vacc0x4567 = wasm_v128_load(w + 4);
74     v128_t vacc1x0123 = vacc0x0123;
75     v128_t vacc1x4567 = vacc0x4567;
76     v128_t vacc2x0123 = vacc0x0123;
77     v128_t vacc2x4567 = vacc0x4567;
78     v128_t vacc3x0123 = vacc0x0123;
79     v128_t vacc3x4567 = vacc0x4567;
80     v128_t vacc4x0123 = vacc0x0123;
81     v128_t vacc4x4567 = vacc0x4567;
82     v128_t vacc5x0123 = vacc0x0123;
83     v128_t vacc5x4567 = vacc0x4567;
84     w += 8;
85 
86     size_t k = kc;
87     do {
88       const v128_t va0 = wasm_v128_load32_splat(a0);
89       a0 += 1;
90       const v128_t va1 = wasm_v128_load32_splat(a1);
91       a1 += 1;
92       const v128_t va2 = wasm_v128_load32_splat(a2);
93       a2 += 1;
94       const v128_t va3 = wasm_v128_load32_splat(a3);
95       a3 += 1;
96       const v128_t va4 = wasm_v128_load32_splat(a4);
97       a4 += 1;
98       const v128_t va5 = wasm_v128_load32_splat(a5);
99       a5 += 1;
100 
101       const v128_t vb0123 = wasm_v128_load(w);
102       const v128_t vb4567 = wasm_v128_load(w + 4);
103       w += 8;
104 
105       vacc0x0123 = __builtin_wasm_fma_f32x4(vacc0x0123, va0, vb0123);
106       vacc1x0123 = __builtin_wasm_fma_f32x4(vacc1x0123, va1, vb0123);
107       vacc2x0123 = __builtin_wasm_fma_f32x4(vacc2x0123, va2, vb0123);
108       vacc3x0123 = __builtin_wasm_fma_f32x4(vacc3x0123, va3, vb0123);
109       vacc4x0123 = __builtin_wasm_fma_f32x4(vacc4x0123, va4, vb0123);
110       vacc5x0123 = __builtin_wasm_fma_f32x4(vacc5x0123, va5, vb0123);
111       vacc0x4567 = __builtin_wasm_fma_f32x4(vacc0x4567, va0, vb4567);
112       vacc1x4567 = __builtin_wasm_fma_f32x4(vacc1x4567, va1, vb4567);
113       vacc2x4567 = __builtin_wasm_fma_f32x4(vacc2x4567, va2, vb4567);
114       vacc3x4567 = __builtin_wasm_fma_f32x4(vacc3x4567, va3, vb4567);
115       vacc4x4567 = __builtin_wasm_fma_f32x4(vacc4x4567, va4, vb4567);
116       vacc5x4567 = __builtin_wasm_fma_f32x4(vacc5x4567, va5, vb4567);
117 
118       k -= sizeof(float);
119     } while (k != 0);
120 
121 
122     if XNN_LIKELY(nc >= 8) {
123       wasm_v128_store(c5, vacc5x0123);
124       wasm_v128_store(c5 + 4, vacc5x4567);
125       c5 = (float*) ((uintptr_t) c5 + cn_stride);
126       wasm_v128_store(c4, vacc4x0123);
127       wasm_v128_store(c4 + 4, vacc4x4567);
128       c4 = (float*) ((uintptr_t) c4 + cn_stride);
129       wasm_v128_store(c3, vacc3x0123);
130       wasm_v128_store(c3 + 4, vacc3x4567);
131       c3 = (float*) ((uintptr_t) c3 + cn_stride);
132       wasm_v128_store(c2, vacc2x0123);
133       wasm_v128_store(c2 + 4, vacc2x4567);
134       c2 = (float*) ((uintptr_t) c2 + cn_stride);
135       wasm_v128_store(c1, vacc1x0123);
136       wasm_v128_store(c1 + 4, vacc1x4567);
137       c1 = (float*) ((uintptr_t) c1 + cn_stride);
138       wasm_v128_store(c0, vacc0x0123);
139       wasm_v128_store(c0 + 4, vacc0x4567);
140       c0 = (float*) ((uintptr_t) c0 + cn_stride);
141 
142       a5 = (const float*) ((uintptr_t) a5 - kc);
143       a4 = (const float*) ((uintptr_t) a4 - kc);
144       a3 = (const float*) ((uintptr_t) a3 - kc);
145       a2 = (const float*) ((uintptr_t) a2 - kc);
146       a1 = (const float*) ((uintptr_t) a1 - kc);
147       a0 = (const float*) ((uintptr_t) a0 - kc);
148 
149       nc -= 8;
150     } else {
151       if (nc & 4) {
152         wasm_v128_store(c5, vacc5x0123);
153         wasm_v128_store(c4, vacc4x0123);
154         wasm_v128_store(c3, vacc3x0123);
155         wasm_v128_store(c2, vacc2x0123);
156         wasm_v128_store(c1, vacc1x0123);
157         wasm_v128_store(c0, vacc0x0123);
158 
159         vacc5x0123 = vacc5x4567;
160         vacc4x0123 = vacc4x4567;
161         vacc3x0123 = vacc3x4567;
162         vacc2x0123 = vacc2x4567;
163         vacc1x0123 = vacc1x4567;
164         vacc0x0123 = vacc0x4567;
165 
166         c5 += 4;
167         c4 += 4;
168         c3 += 4;
169         c2 += 4;
170         c1 += 4;
171         c0 += 4;
172       }
173       if (nc & 2) {
174         *((double*) c5) = wasm_f64x2_extract_lane(vacc5x0123, 0);
175         *((double*) c4) = wasm_f64x2_extract_lane(vacc4x0123, 0);
176         *((double*) c3) = wasm_f64x2_extract_lane(vacc3x0123, 0);
177         *((double*) c2) = wasm_f64x2_extract_lane(vacc2x0123, 0);
178         *((double*) c1) = wasm_f64x2_extract_lane(vacc1x0123, 0);
179         *((double*) c0) = wasm_f64x2_extract_lane(vacc0x0123, 0);
180 
181         vacc5x0123 = wasm_v32x4_shuffle(vacc5x0123, vacc5x0123, 2, 3, 2, 3);
182         vacc4x0123 = wasm_v32x4_shuffle(vacc4x0123, vacc4x0123, 2, 3, 2, 3);
183         vacc3x0123 = wasm_v32x4_shuffle(vacc3x0123, vacc3x0123, 2, 3, 2, 3);
184         vacc2x0123 = wasm_v32x4_shuffle(vacc2x0123, vacc2x0123, 2, 3, 2, 3);
185         vacc1x0123 = wasm_v32x4_shuffle(vacc1x0123, vacc1x0123, 2, 3, 2, 3);
186         vacc0x0123 = wasm_v32x4_shuffle(vacc0x0123, vacc0x0123, 2, 3, 2, 3);
187 
188         c5 += 2;
189         c4 += 2;
190         c3 += 2;
191         c2 += 2;
192         c1 += 2;
193         c0 += 2;
194       }
195       if (nc & 1) {
196         *c5 = wasm_f32x4_extract_lane(vacc5x0123, 0);
197         *c4 = wasm_f32x4_extract_lane(vacc4x0123, 0);
198         *c3 = wasm_f32x4_extract_lane(vacc3x0123, 0);
199         *c2 = wasm_f32x4_extract_lane(vacc2x0123, 0);
200         *c1 = wasm_f32x4_extract_lane(vacc1x0123, 0);
201         *c0 = wasm_f32x4_extract_lane(vacc0x0123, 0);
202       }
203 
204       nc = 0;
205     }
206   } while (nc != 0);
207 }
208