1 // Auto-generated file. Do not edit!
2 // Template: src/f32-gemm/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/gemm.h>
15
16
xnn_f32_gemminc_minmax_ukernel_4x8__relaxedwasmsimd_splat(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 float * restrict acc,const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])17 void xnn_f32_gemminc_minmax_ukernel_4x8__relaxedwasmsimd_splat(
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 float*restrict acc,
28 const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)])
29 {
30 assert(mr != 0);
31 assert(mr <= 4);
32 assert(nc != 0);
33 assert(kc != 0);
34 assert(kc % sizeof(float) == 0);
35 assert(a != NULL);
36 assert(w != NULL);
37 assert(c != NULL);
38 assert(acc != NULL);
39
40 const float* a0 = a;
41 float* c0 = c;
42 const float* a1 = (const float*) ((uintptr_t) a0 + a_stride);
43 float* c1 = (float*) ((uintptr_t) c0 + cm_stride);
44 if XNN_UNPREDICTABLE(mr < 2) {
45 a1 = a0;
46 c1 = c0;
47 }
48 const float* a2 = (const float*) ((uintptr_t) a1 + a_stride);
49 float* c2 = (float*) ((uintptr_t) c1 + cm_stride);
50 if XNN_UNPREDICTABLE(mr <= 2) {
51 a2 = a1;
52 c2 = c1;
53 }
54 const float* a3 = (const float*) ((uintptr_t) a2 + a_stride);
55 float* c3 = (float*) ((uintptr_t) c2 + cm_stride);
56 if XNN_UNPREDICTABLE(mr != 4) {
57 a3 = a2;
58 c3 = c2;
59 }
60
61 const v128_t vmin = wasm_v128_load64_splat(params->wasmsimd.min);
62 const v128_t vmax = wasm_v128_load64_splat(params->wasmsimd.max);
63 do {
64 v128_t vacc0x0123 = wasm_v128_load(acc + 0);
65 v128_t vacc0x4567 = wasm_v128_load(acc + 4);
66 v128_t vacc1x0123 = wasm_v128_load(acc + 8);
67 v128_t vacc1x4567 = wasm_v128_load(acc + 12);
68 v128_t vacc2x0123 = wasm_v128_load(acc + 16);
69 v128_t vacc2x4567 = wasm_v128_load(acc + 20);
70 v128_t vacc3x0123 = wasm_v128_load(acc + 24);
71 v128_t vacc3x4567 = wasm_v128_load(acc + 28);
72 acc += 32;
73
74 size_t k = kc;
75 while (k >= 4 * sizeof(float)) {
76 const v128_t va0 = wasm_v128_load(a0);
77 a0 += 4;
78 const v128_t va1 = wasm_v128_load(a1);
79 a1 += 4;
80 const v128_t va2 = wasm_v128_load(a2);
81 a2 += 4;
82 const v128_t va3 = wasm_v128_load(a3);
83 a3 += 4;
84
85 const v128_t va0c0 = wasm_v32x4_shuffle(va0, va0, 0, 0, 0, 0);
86 const v128_t va1c0 = wasm_v32x4_shuffle(va1, va1, 0, 0, 0, 0);
87 const v128_t va2c0 = wasm_v32x4_shuffle(va2, va2, 0, 0, 0, 0);
88 const v128_t va3c0 = wasm_v32x4_shuffle(va3, va3, 0, 0, 0, 0);
89
90 const v128_t vb0123c0 = wasm_v128_load(w + 0);
91 const v128_t vb4567c0 = wasm_v128_load(w + 4);
92
93 vacc0x0123 = wasm_f32x4_add(vacc0x0123, wasm_f32x4_mul(va0c0, vb0123c0));
94 vacc1x0123 = wasm_f32x4_add(vacc1x0123, wasm_f32x4_mul(va1c0, vb0123c0));
95 vacc2x0123 = wasm_f32x4_add(vacc2x0123, wasm_f32x4_mul(va2c0, vb0123c0));
96 vacc3x0123 = wasm_f32x4_add(vacc3x0123, wasm_f32x4_mul(va3c0, vb0123c0));
97 vacc0x4567 = wasm_f32x4_add(vacc0x4567, wasm_f32x4_mul(va0c0, vb4567c0));
98 vacc1x4567 = wasm_f32x4_add(vacc1x4567, wasm_f32x4_mul(va1c0, vb4567c0));
99 vacc2x4567 = wasm_f32x4_add(vacc2x4567, wasm_f32x4_mul(va2c0, vb4567c0));
100 vacc3x4567 = wasm_f32x4_add(vacc3x4567, wasm_f32x4_mul(va3c0, vb4567c0));
101 const v128_t va0c1 = wasm_v32x4_shuffle(va0, va0, 1, 1, 1, 1);
102 const v128_t va1c1 = wasm_v32x4_shuffle(va1, va1, 1, 1, 1, 1);
103 const v128_t va2c1 = wasm_v32x4_shuffle(va2, va2, 1, 1, 1, 1);
104 const v128_t va3c1 = wasm_v32x4_shuffle(va3, va3, 1, 1, 1, 1);
105
106 const v128_t vb0123c1 = wasm_v128_load(w + 8);
107 const v128_t vb4567c1 = wasm_v128_load(w + 12);
108
109 vacc0x0123 = wasm_f32x4_add(vacc0x0123, wasm_f32x4_mul(va0c1, vb0123c1));
110 vacc1x0123 = wasm_f32x4_add(vacc1x0123, wasm_f32x4_mul(va1c1, vb0123c1));
111 vacc2x0123 = wasm_f32x4_add(vacc2x0123, wasm_f32x4_mul(va2c1, vb0123c1));
112 vacc3x0123 = wasm_f32x4_add(vacc3x0123, wasm_f32x4_mul(va3c1, vb0123c1));
113 vacc0x4567 = wasm_f32x4_add(vacc0x4567, wasm_f32x4_mul(va0c1, vb4567c1));
114 vacc1x4567 = wasm_f32x4_add(vacc1x4567, wasm_f32x4_mul(va1c1, vb4567c1));
115 vacc2x4567 = wasm_f32x4_add(vacc2x4567, wasm_f32x4_mul(va2c1, vb4567c1));
116 vacc3x4567 = wasm_f32x4_add(vacc3x4567, wasm_f32x4_mul(va3c1, vb4567c1));
117 const v128_t va0c2 = wasm_v32x4_shuffle(va0, va0, 2, 2, 2, 2);
118 const v128_t va1c2 = wasm_v32x4_shuffle(va1, va1, 2, 2, 2, 2);
119 const v128_t va2c2 = wasm_v32x4_shuffle(va2, va2, 2, 2, 2, 2);
120 const v128_t va3c2 = wasm_v32x4_shuffle(va3, va3, 2, 2, 2, 2);
121
122 const v128_t vb0123c2 = wasm_v128_load(w + 16);
123 const v128_t vb4567c2 = wasm_v128_load(w + 20);
124
125 vacc0x0123 = wasm_f32x4_add(vacc0x0123, wasm_f32x4_mul(va0c2, vb0123c2));
126 vacc1x0123 = wasm_f32x4_add(vacc1x0123, wasm_f32x4_mul(va1c2, vb0123c2));
127 vacc2x0123 = wasm_f32x4_add(vacc2x0123, wasm_f32x4_mul(va2c2, vb0123c2));
128 vacc3x0123 = wasm_f32x4_add(vacc3x0123, wasm_f32x4_mul(va3c2, vb0123c2));
129 vacc0x4567 = wasm_f32x4_add(vacc0x4567, wasm_f32x4_mul(va0c2, vb4567c2));
130 vacc1x4567 = wasm_f32x4_add(vacc1x4567, wasm_f32x4_mul(va1c2, vb4567c2));
131 vacc2x4567 = wasm_f32x4_add(vacc2x4567, wasm_f32x4_mul(va2c2, vb4567c2));
132 vacc3x4567 = wasm_f32x4_add(vacc3x4567, wasm_f32x4_mul(va3c2, vb4567c2));
133 const v128_t va0c3 = wasm_v32x4_shuffle(va0, va0, 3, 3, 3, 3);
134 const v128_t va1c3 = wasm_v32x4_shuffle(va1, va1, 3, 3, 3, 3);
135 const v128_t va2c3 = wasm_v32x4_shuffle(va2, va2, 3, 3, 3, 3);
136 const v128_t va3c3 = wasm_v32x4_shuffle(va3, va3, 3, 3, 3, 3);
137
138 const v128_t vb0123c3 = wasm_v128_load(w + 24);
139 const v128_t vb4567c3 = wasm_v128_load(w + 28);
140
141 vacc0x0123 = wasm_f32x4_add(vacc0x0123, wasm_f32x4_mul(va0c3, vb0123c3));
142 vacc1x0123 = wasm_f32x4_add(vacc1x0123, wasm_f32x4_mul(va1c3, vb0123c3));
143 vacc2x0123 = wasm_f32x4_add(vacc2x0123, wasm_f32x4_mul(va2c3, vb0123c3));
144 vacc3x0123 = wasm_f32x4_add(vacc3x0123, wasm_f32x4_mul(va3c3, vb0123c3));
145 vacc0x4567 = wasm_f32x4_add(vacc0x4567, wasm_f32x4_mul(va0c3, vb4567c3));
146 vacc1x4567 = wasm_f32x4_add(vacc1x4567, wasm_f32x4_mul(va1c3, vb4567c3));
147 vacc2x4567 = wasm_f32x4_add(vacc2x4567, wasm_f32x4_mul(va2c3, vb4567c3));
148 vacc3x4567 = wasm_f32x4_add(vacc3x4567, wasm_f32x4_mul(va3c3, vb4567c3));
149
150 w += 32;
151 k -= 4 * sizeof(float);
152 }
153 if XNN_UNLIKELY(k != 0) {
154 do {
155 const v128_t va0 = wasm_v128_load32_splat(a0);
156 a0 += 1;
157 const v128_t va1 = wasm_v128_load32_splat(a1);
158 a1 += 1;
159 const v128_t va2 = wasm_v128_load32_splat(a2);
160 a2 += 1;
161 const v128_t va3 = wasm_v128_load32_splat(a3);
162 a3 += 1;
163
164 const v128_t vb0123 = wasm_v128_load(w);
165 const v128_t vb4567 = wasm_v128_load(w + 4);
166 w += 8;
167
168 vacc0x0123 = wasm_f32x4_add(vacc0x0123, wasm_f32x4_mul(va0, vb0123));
169 vacc1x0123 = wasm_f32x4_add(vacc1x0123, wasm_f32x4_mul(va1, vb0123));
170 vacc2x0123 = wasm_f32x4_add(vacc2x0123, wasm_f32x4_mul(va2, vb0123));
171 vacc3x0123 = wasm_f32x4_add(vacc3x0123, wasm_f32x4_mul(va3, vb0123));
172 vacc0x4567 = wasm_f32x4_add(vacc0x4567, wasm_f32x4_mul(va0, vb4567));
173 vacc1x4567 = wasm_f32x4_add(vacc1x4567, wasm_f32x4_mul(va1, vb4567));
174 vacc2x4567 = wasm_f32x4_add(vacc2x4567, wasm_f32x4_mul(va2, vb4567));
175 vacc3x4567 = wasm_f32x4_add(vacc3x4567, wasm_f32x4_mul(va3, vb4567));
176
177 k -= sizeof(float);
178 } while (k != 0);
179 }
180
181 vacc0x0123 = __builtin_wasm_relaxed_max_f32x4(vmin, vacc0x0123);
182 vacc1x0123 = __builtin_wasm_relaxed_max_f32x4(vmin, vacc1x0123);
183 vacc2x0123 = __builtin_wasm_relaxed_max_f32x4(vmin, vacc2x0123);
184 vacc3x0123 = __builtin_wasm_relaxed_max_f32x4(vmin, vacc3x0123);
185 vacc0x4567 = __builtin_wasm_relaxed_max_f32x4(vmin, vacc0x4567);
186 vacc1x4567 = __builtin_wasm_relaxed_max_f32x4(vmin, vacc1x4567);
187 vacc2x4567 = __builtin_wasm_relaxed_max_f32x4(vmin, vacc2x4567);
188 vacc3x4567 = __builtin_wasm_relaxed_max_f32x4(vmin, vacc3x4567);
189
190 vacc0x0123 = __builtin_wasm_relaxed_min_f32x4(vmax, vacc0x0123);
191 vacc1x0123 = __builtin_wasm_relaxed_min_f32x4(vmax, vacc1x0123);
192 vacc2x0123 = __builtin_wasm_relaxed_min_f32x4(vmax, vacc2x0123);
193 vacc3x0123 = __builtin_wasm_relaxed_min_f32x4(vmax, vacc3x0123);
194 vacc0x4567 = __builtin_wasm_relaxed_min_f32x4(vmax, vacc0x4567);
195 vacc1x4567 = __builtin_wasm_relaxed_min_f32x4(vmax, vacc1x4567);
196 vacc2x4567 = __builtin_wasm_relaxed_min_f32x4(vmax, vacc2x4567);
197 vacc3x4567 = __builtin_wasm_relaxed_min_f32x4(vmax, vacc3x4567);
198
199 if XNN_LIKELY(nc >= 8) {
200 wasm_v128_store(c3, vacc3x0123);
201 wasm_v128_store(c3 + 4, vacc3x4567);
202 c3 = (float*) ((uintptr_t) c3 + cn_stride);
203 wasm_v128_store(c2, vacc2x0123);
204 wasm_v128_store(c2 + 4, vacc2x4567);
205 c2 = (float*) ((uintptr_t) c2 + cn_stride);
206 wasm_v128_store(c1, vacc1x0123);
207 wasm_v128_store(c1 + 4, vacc1x4567);
208 c1 = (float*) ((uintptr_t) c1 + cn_stride);
209 wasm_v128_store(c0, vacc0x0123);
210 wasm_v128_store(c0 + 4, vacc0x4567);
211 c0 = (float*) ((uintptr_t) c0 + cn_stride);
212
213 a3 = (const float*) ((uintptr_t) a3 - kc);
214 a2 = (const float*) ((uintptr_t) a2 - kc);
215 a1 = (const float*) ((uintptr_t) a1 - kc);
216 a0 = (const float*) ((uintptr_t) a0 - kc);
217
218 nc -= 8;
219 } else {
220 if (nc & 4) {
221 wasm_v128_store(c3, vacc3x0123);
222 wasm_v128_store(c2, vacc2x0123);
223 wasm_v128_store(c1, vacc1x0123);
224 wasm_v128_store(c0, vacc0x0123);
225
226 vacc3x0123 = vacc3x4567;
227 vacc2x0123 = vacc2x4567;
228 vacc1x0123 = vacc1x4567;
229 vacc0x0123 = vacc0x4567;
230
231 c3 += 4;
232 c2 += 4;
233 c1 += 4;
234 c0 += 4;
235 }
236 if (nc & 2) {
237 *((double*) c3) = wasm_f64x2_extract_lane(vacc3x0123, 0);
238 *((double*) c2) = wasm_f64x2_extract_lane(vacc2x0123, 0);
239 *((double*) c1) = wasm_f64x2_extract_lane(vacc1x0123, 0);
240 *((double*) c0) = wasm_f64x2_extract_lane(vacc0x0123, 0);
241
242 vacc3x0123 = wasm_v32x4_shuffle(vacc3x0123, vacc3x0123, 2, 3, 2, 3);
243 vacc2x0123 = wasm_v32x4_shuffle(vacc2x0123, vacc2x0123, 2, 3, 2, 3);
244 vacc1x0123 = wasm_v32x4_shuffle(vacc1x0123, vacc1x0123, 2, 3, 2, 3);
245 vacc0x0123 = wasm_v32x4_shuffle(vacc0x0123, vacc0x0123, 2, 3, 2, 3);
246
247 c3 += 2;
248 c2 += 2;
249 c1 += 2;
250 c0 += 2;
251 }
252 if (nc & 1) {
253 *c3 = wasm_f32x4_extract_lane(vacc3x0123, 0);
254 *c2 = wasm_f32x4_extract_lane(vacc2x0123, 0);
255 *c1 = wasm_f32x4_extract_lane(vacc1x0123, 0);
256 *c0 = wasm_f32x4_extract_lane(vacc0x0123, 0);
257 }
258
259 nc = 0;
260 }
261 } while (nc != 0);
262 }
263