• 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_minmax_ukernel_6x8__wasmsimd_arm_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_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])17 void xnn_f32_gemm_minmax_ukernel_6x8__wasmsimd_arm_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_minmax_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   const v128_t vmin = wasm_v32x4_load_splat(&params->scalar.min);
72   const v128_t vmax = wasm_v32x4_load_splat(&params->scalar.max);
73   do {
74     v128_t vacc0x0123 = wasm_v128_load(w + 0);
75     v128_t vacc0x4567 = wasm_v128_load(w + 4);
76     v128_t vacc1x0123 = vacc0x0123;
77     v128_t vacc1x4567 = vacc0x4567;
78     v128_t vacc2x0123 = vacc0x0123;
79     v128_t vacc2x4567 = vacc0x4567;
80     v128_t vacc3x0123 = vacc0x0123;
81     v128_t vacc3x4567 = vacc0x4567;
82     v128_t vacc4x0123 = vacc0x0123;
83     v128_t vacc4x4567 = vacc0x4567;
84     v128_t vacc5x0123 = vacc0x0123;
85     v128_t vacc5x4567 = vacc0x4567;
86     w += 8;
87 
88     size_t k = kc;
89     do {
90       const v128_t va0 = wasm_v32x4_load_splat(a0);
91       a0 += 1;
92       const v128_t va1 = wasm_v32x4_load_splat(a1);
93       a1 += 1;
94       const v128_t va2 = wasm_v32x4_load_splat(a2);
95       a2 += 1;
96       const v128_t va3 = wasm_v32x4_load_splat(a3);
97       a3 += 1;
98       const v128_t va4 = wasm_v32x4_load_splat(a4);
99       a4 += 1;
100       const v128_t va5 = wasm_v32x4_load_splat(a5);
101       a5 += 1;
102 
103       const v128_t vb0123 = wasm_v128_load(w);
104       const v128_t vb4567 = wasm_v128_load(w + 4);
105       w += 8;
106 
107       vacc0x0123 = wasm_f32x4_add(vacc0x0123, wasm_f32x4_mul(va0, vb0123));
108       vacc1x0123 = wasm_f32x4_add(vacc1x0123, wasm_f32x4_mul(va1, vb0123));
109       vacc2x0123 = wasm_f32x4_add(vacc2x0123, wasm_f32x4_mul(va2, vb0123));
110       vacc3x0123 = wasm_f32x4_add(vacc3x0123, wasm_f32x4_mul(va3, vb0123));
111       vacc4x0123 = wasm_f32x4_add(vacc4x0123, wasm_f32x4_mul(va4, vb0123));
112       vacc5x0123 = wasm_f32x4_add(vacc5x0123, wasm_f32x4_mul(va5, vb0123));
113       vacc0x4567 = wasm_f32x4_add(vacc0x4567, wasm_f32x4_mul(va0, vb4567));
114       vacc1x4567 = wasm_f32x4_add(vacc1x4567, wasm_f32x4_mul(va1, vb4567));
115       vacc2x4567 = wasm_f32x4_add(vacc2x4567, wasm_f32x4_mul(va2, vb4567));
116       vacc3x4567 = wasm_f32x4_add(vacc3x4567, wasm_f32x4_mul(va3, vb4567));
117       vacc4x4567 = wasm_f32x4_add(vacc4x4567, wasm_f32x4_mul(va4, vb4567));
118       vacc5x4567 = wasm_f32x4_add(vacc5x4567, wasm_f32x4_mul(va5, vb4567));
119 
120       k -= sizeof(float);
121     } while (k != 0);
122 
123     vacc0x0123 = wasm_f32x4_max(vacc0x0123, vmin);
124     vacc1x0123 = wasm_f32x4_max(vacc1x0123, vmin);
125     vacc2x0123 = wasm_f32x4_max(vacc2x0123, vmin);
126     vacc3x0123 = wasm_f32x4_max(vacc3x0123, vmin);
127     vacc4x0123 = wasm_f32x4_max(vacc4x0123, vmin);
128     vacc5x0123 = wasm_f32x4_max(vacc5x0123, vmin);
129     vacc0x4567 = wasm_f32x4_max(vacc0x4567, vmin);
130     vacc1x4567 = wasm_f32x4_max(vacc1x4567, vmin);
131     vacc2x4567 = wasm_f32x4_max(vacc2x4567, vmin);
132     vacc3x4567 = wasm_f32x4_max(vacc3x4567, vmin);
133     vacc4x4567 = wasm_f32x4_max(vacc4x4567, vmin);
134     vacc5x4567 = wasm_f32x4_max(vacc5x4567, vmin);
135 
136     vacc0x0123 = wasm_f32x4_min(vacc0x0123, vmax);
137     vacc1x0123 = wasm_f32x4_min(vacc1x0123, vmax);
138     vacc2x0123 = wasm_f32x4_min(vacc2x0123, vmax);
139     vacc3x0123 = wasm_f32x4_min(vacc3x0123, vmax);
140     vacc4x0123 = wasm_f32x4_min(vacc4x0123, vmax);
141     vacc5x0123 = wasm_f32x4_min(vacc5x0123, vmax);
142     vacc0x4567 = wasm_f32x4_min(vacc0x4567, vmax);
143     vacc1x4567 = wasm_f32x4_min(vacc1x4567, vmax);
144     vacc2x4567 = wasm_f32x4_min(vacc2x4567, vmax);
145     vacc3x4567 = wasm_f32x4_min(vacc3x4567, vmax);
146     vacc4x4567 = wasm_f32x4_min(vacc4x4567, vmax);
147     vacc5x4567 = wasm_f32x4_min(vacc5x4567, vmax);
148 
149     if XNN_LIKELY(nc >= 8) {
150       wasm_v128_store(c5, vacc5x0123);
151       wasm_v128_store(c5 + 4, vacc5x4567);
152       c5 = (float*) ((uintptr_t) c5 + cn_stride);
153       wasm_v128_store(c4, vacc4x0123);
154       wasm_v128_store(c4 + 4, vacc4x4567);
155       c4 = (float*) ((uintptr_t) c4 + cn_stride);
156       wasm_v128_store(c3, vacc3x0123);
157       wasm_v128_store(c3 + 4, vacc3x4567);
158       c3 = (float*) ((uintptr_t) c3 + cn_stride);
159       wasm_v128_store(c2, vacc2x0123);
160       wasm_v128_store(c2 + 4, vacc2x4567);
161       c2 = (float*) ((uintptr_t) c2 + cn_stride);
162       wasm_v128_store(c1, vacc1x0123);
163       wasm_v128_store(c1 + 4, vacc1x4567);
164       c1 = (float*) ((uintptr_t) c1 + cn_stride);
165       wasm_v128_store(c0, vacc0x0123);
166       wasm_v128_store(c0 + 4, vacc0x4567);
167       c0 = (float*) ((uintptr_t) c0 + cn_stride);
168 
169       a5 = (const float*) ((uintptr_t) a5 - kc);
170       a4 = (const float*) ((uintptr_t) a4 - kc);
171       a3 = (const float*) ((uintptr_t) a3 - kc);
172       a2 = (const float*) ((uintptr_t) a2 - kc);
173       a1 = (const float*) ((uintptr_t) a1 - kc);
174       a0 = (const float*) ((uintptr_t) a0 - kc);
175 
176       nc -= 8;
177     } else {
178       if (nc & 4) {
179         wasm_v128_store(c5, vacc5x0123);
180         wasm_v128_store(c4, vacc4x0123);
181         wasm_v128_store(c3, vacc3x0123);
182         wasm_v128_store(c2, vacc2x0123);
183         wasm_v128_store(c1, vacc1x0123);
184         wasm_v128_store(c0, vacc0x0123);
185 
186         vacc5x0123 = vacc5x4567;
187         vacc4x0123 = vacc4x4567;
188         vacc3x0123 = vacc3x4567;
189         vacc2x0123 = vacc2x4567;
190         vacc1x0123 = vacc1x4567;
191         vacc0x0123 = vacc0x4567;
192 
193         c5 += 4;
194         c4 += 4;
195         c3 += 4;
196         c2 += 4;
197         c1 += 4;
198         c0 += 4;
199       }
200       if (nc & 2) {
201         *((double*) c5) = wasm_f64x2_extract_lane(vacc5x0123, 0);
202         *((double*) c4) = wasm_f64x2_extract_lane(vacc4x0123, 0);
203         *((double*) c3) = wasm_f64x2_extract_lane(vacc3x0123, 0);
204         *((double*) c2) = wasm_f64x2_extract_lane(vacc2x0123, 0);
205         *((double*) c1) = wasm_f64x2_extract_lane(vacc1x0123, 0);
206         *((double*) c0) = wasm_f64x2_extract_lane(vacc0x0123, 0);
207 
208         vacc5x0123 = wasm_v32x4_shuffle(vacc5x0123, vacc5x0123, 2, 3, 2, 3);
209         vacc4x0123 = wasm_v32x4_shuffle(vacc4x0123, vacc4x0123, 2, 3, 2, 3);
210         vacc3x0123 = wasm_v32x4_shuffle(vacc3x0123, vacc3x0123, 2, 3, 2, 3);
211         vacc2x0123 = wasm_v32x4_shuffle(vacc2x0123, vacc2x0123, 2, 3, 2, 3);
212         vacc1x0123 = wasm_v32x4_shuffle(vacc1x0123, vacc1x0123, 2, 3, 2, 3);
213         vacc0x0123 = wasm_v32x4_shuffle(vacc0x0123, vacc0x0123, 2, 3, 2, 3);
214 
215         c5 += 2;
216         c4 += 2;
217         c3 += 2;
218         c2 += 2;
219         c1 += 2;
220         c0 += 2;
221       }
222       if (nc & 1) {
223         *c5 = wasm_f32x4_extract_lane(vacc5x0123, 0);
224         *c4 = wasm_f32x4_extract_lane(vacc4x0123, 0);
225         *c3 = wasm_f32x4_extract_lane(vacc3x0123, 0);
226         *c2 = wasm_f32x4_extract_lane(vacc2x0123, 0);
227         *c1 = wasm_f32x4_extract_lane(vacc1x0123, 0);
228         *c0 = wasm_f32x4_extract_lane(vacc0x0123, 0);
229       }
230 
231       nc = 0;
232     }
233   } while (nc != 0);
234 }
235