1 // Auto-generated file. Do not edit!
2 // Template: src/f32-gemm/wasmsimd-s4.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_6x8s4__wasmsimd_x86(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_6x8s4__wasmsimd_x86(
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 <= 6);
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 const float* a4 = (const float*) ((uintptr_t) a3 + a_stride);
61 float* c4 = (float*) ((uintptr_t) c3 + cm_stride);
62 if XNN_UNPREDICTABLE(mr <= 4) {
63 a4 = a3;
64 c4 = c3;
65 }
66 const float* a5 = (const float*) ((uintptr_t) a4 + a_stride);
67 float* c5 = (float*) ((uintptr_t) c4 + cm_stride);
68 if XNN_UNPREDICTABLE(mr != 6) {
69 a5 = a4;
70 c5 = c4;
71 }
72
73 do {
74 v128_t vacc0x0123 = wasm_v128_load(acc + 0);
75 v128_t vacc0x4567 = wasm_v128_load(acc + 4);
76 v128_t vacc1x0123 = wasm_v128_load(acc + 8);
77 v128_t vacc1x4567 = wasm_v128_load(acc + 12);
78 v128_t vacc2x0123 = wasm_v128_load(acc + 16);
79 v128_t vacc2x4567 = wasm_v128_load(acc + 20);
80 v128_t vacc3x0123 = wasm_v128_load(acc + 24);
81 v128_t vacc3x4567 = wasm_v128_load(acc + 28);
82 v128_t vacc4x0123 = wasm_v128_load(acc + 32);
83 v128_t vacc4x4567 = wasm_v128_load(acc + 36);
84 v128_t vacc5x0123 = wasm_v128_load(acc + 40);
85 v128_t vacc5x4567 = wasm_v128_load(acc + 44);
86 acc += 48;
87
88 size_t k = kc;
89 while (k >= 4 * sizeof(float)) {
90 v128_t va0 = wasm_v128_load(a0);
91 a0 += 4;
92 v128_t va1 = wasm_v128_load(a1);
93 a1 += 4;
94 v128_t va2 = wasm_v128_load(a2);
95 a2 += 4;
96 v128_t va3 = wasm_v128_load(a3);
97 a3 += 4;
98 v128_t va4 = wasm_v128_load(a4);
99 a4 += 4;
100 v128_t va5 = wasm_v128_load(a5);
101 a5 += 4;
102
103
104 const v128_t vb0123c0 = wasm_v128_load(w + 0);
105 const v128_t vb4567c0 = wasm_v128_load(w + 4);
106
107 vacc0x0123 = wasm_f32x4_add(vacc0x0123, wasm_f32x4_mul(va0, vb0123c0));
108 vacc1x0123 = wasm_f32x4_add(vacc1x0123, wasm_f32x4_mul(va1, vb0123c0));
109 vacc2x0123 = wasm_f32x4_add(vacc2x0123, wasm_f32x4_mul(va2, vb0123c0));
110 vacc3x0123 = wasm_f32x4_add(vacc3x0123, wasm_f32x4_mul(va3, vb0123c0));
111 vacc4x0123 = wasm_f32x4_add(vacc4x0123, wasm_f32x4_mul(va4, vb0123c0));
112 vacc5x0123 = wasm_f32x4_add(vacc5x0123, wasm_f32x4_mul(va5, vb0123c0));
113 vacc0x4567 = wasm_f32x4_add(vacc0x4567, wasm_f32x4_mul(va0, vb4567c0));
114 vacc1x4567 = wasm_f32x4_add(vacc1x4567, wasm_f32x4_mul(va1, vb4567c0));
115 vacc2x4567 = wasm_f32x4_add(vacc2x4567, wasm_f32x4_mul(va2, vb4567c0));
116 vacc3x4567 = wasm_f32x4_add(vacc3x4567, wasm_f32x4_mul(va3, vb4567c0));
117 vacc4x4567 = wasm_f32x4_add(vacc4x4567, wasm_f32x4_mul(va4, vb4567c0));
118 vacc5x4567 = wasm_f32x4_add(vacc5x4567, wasm_f32x4_mul(va5, vb4567c0));
119
120 va0 = wasm_v32x4_shuffle(va0, va0, 1, 2, 3, 0);
121 va1 = wasm_v32x4_shuffle(va1, va1, 1, 2, 3, 0);
122 va2 = wasm_v32x4_shuffle(va2, va2, 1, 2, 3, 0);
123 va3 = wasm_v32x4_shuffle(va3, va3, 1, 2, 3, 0);
124 va4 = wasm_v32x4_shuffle(va4, va4, 1, 2, 3, 0);
125 va5 = wasm_v32x4_shuffle(va5, va5, 1, 2, 3, 0);
126
127 const v128_t vb0123c1 = wasm_v128_load(w + 8);
128 const v128_t vb4567c1 = wasm_v128_load(w + 12);
129
130 vacc0x0123 = wasm_f32x4_add(vacc0x0123, wasm_f32x4_mul(va0, vb0123c1));
131 vacc1x0123 = wasm_f32x4_add(vacc1x0123, wasm_f32x4_mul(va1, vb0123c1));
132 vacc2x0123 = wasm_f32x4_add(vacc2x0123, wasm_f32x4_mul(va2, vb0123c1));
133 vacc3x0123 = wasm_f32x4_add(vacc3x0123, wasm_f32x4_mul(va3, vb0123c1));
134 vacc4x0123 = wasm_f32x4_add(vacc4x0123, wasm_f32x4_mul(va4, vb0123c1));
135 vacc5x0123 = wasm_f32x4_add(vacc5x0123, wasm_f32x4_mul(va5, vb0123c1));
136 vacc0x4567 = wasm_f32x4_add(vacc0x4567, wasm_f32x4_mul(va0, vb4567c1));
137 vacc1x4567 = wasm_f32x4_add(vacc1x4567, wasm_f32x4_mul(va1, vb4567c1));
138 vacc2x4567 = wasm_f32x4_add(vacc2x4567, wasm_f32x4_mul(va2, vb4567c1));
139 vacc3x4567 = wasm_f32x4_add(vacc3x4567, wasm_f32x4_mul(va3, vb4567c1));
140 vacc4x4567 = wasm_f32x4_add(vacc4x4567, wasm_f32x4_mul(va4, vb4567c1));
141 vacc5x4567 = wasm_f32x4_add(vacc5x4567, wasm_f32x4_mul(va5, vb4567c1));
142
143 va0 = wasm_v32x4_shuffle(va0, va0, 1, 2, 3, 0);
144 va1 = wasm_v32x4_shuffle(va1, va1, 1, 2, 3, 0);
145 va2 = wasm_v32x4_shuffle(va2, va2, 1, 2, 3, 0);
146 va3 = wasm_v32x4_shuffle(va3, va3, 1, 2, 3, 0);
147 va4 = wasm_v32x4_shuffle(va4, va4, 1, 2, 3, 0);
148 va5 = wasm_v32x4_shuffle(va5, va5, 1, 2, 3, 0);
149
150 const v128_t vb0123c2 = wasm_v128_load(w + 16);
151 const v128_t vb4567c2 = wasm_v128_load(w + 20);
152
153 vacc0x0123 = wasm_f32x4_add(vacc0x0123, wasm_f32x4_mul(va0, vb0123c2));
154 vacc1x0123 = wasm_f32x4_add(vacc1x0123, wasm_f32x4_mul(va1, vb0123c2));
155 vacc2x0123 = wasm_f32x4_add(vacc2x0123, wasm_f32x4_mul(va2, vb0123c2));
156 vacc3x0123 = wasm_f32x4_add(vacc3x0123, wasm_f32x4_mul(va3, vb0123c2));
157 vacc4x0123 = wasm_f32x4_add(vacc4x0123, wasm_f32x4_mul(va4, vb0123c2));
158 vacc5x0123 = wasm_f32x4_add(vacc5x0123, wasm_f32x4_mul(va5, vb0123c2));
159 vacc0x4567 = wasm_f32x4_add(vacc0x4567, wasm_f32x4_mul(va0, vb4567c2));
160 vacc1x4567 = wasm_f32x4_add(vacc1x4567, wasm_f32x4_mul(va1, vb4567c2));
161 vacc2x4567 = wasm_f32x4_add(vacc2x4567, wasm_f32x4_mul(va2, vb4567c2));
162 vacc3x4567 = wasm_f32x4_add(vacc3x4567, wasm_f32x4_mul(va3, vb4567c2));
163 vacc4x4567 = wasm_f32x4_add(vacc4x4567, wasm_f32x4_mul(va4, vb4567c2));
164 vacc5x4567 = wasm_f32x4_add(vacc5x4567, wasm_f32x4_mul(va5, vb4567c2));
165
166 va0 = wasm_v32x4_shuffle(va0, va0, 1, 2, 3, 0);
167 va1 = wasm_v32x4_shuffle(va1, va1, 1, 2, 3, 0);
168 va2 = wasm_v32x4_shuffle(va2, va2, 1, 2, 3, 0);
169 va3 = wasm_v32x4_shuffle(va3, va3, 1, 2, 3, 0);
170 va4 = wasm_v32x4_shuffle(va4, va4, 1, 2, 3, 0);
171 va5 = wasm_v32x4_shuffle(va5, va5, 1, 2, 3, 0);
172
173 const v128_t vb0123c3 = wasm_v128_load(w + 24);
174 const v128_t vb4567c3 = wasm_v128_load(w + 28);
175
176 vacc0x0123 = wasm_f32x4_add(vacc0x0123, wasm_f32x4_mul(va0, vb0123c3));
177 vacc1x0123 = wasm_f32x4_add(vacc1x0123, wasm_f32x4_mul(va1, vb0123c3));
178 vacc2x0123 = wasm_f32x4_add(vacc2x0123, wasm_f32x4_mul(va2, vb0123c3));
179 vacc3x0123 = wasm_f32x4_add(vacc3x0123, wasm_f32x4_mul(va3, vb0123c3));
180 vacc4x0123 = wasm_f32x4_add(vacc4x0123, wasm_f32x4_mul(va4, vb0123c3));
181 vacc5x0123 = wasm_f32x4_add(vacc5x0123, wasm_f32x4_mul(va5, vb0123c3));
182 vacc0x4567 = wasm_f32x4_add(vacc0x4567, wasm_f32x4_mul(va0, vb4567c3));
183 vacc1x4567 = wasm_f32x4_add(vacc1x4567, wasm_f32x4_mul(va1, vb4567c3));
184 vacc2x4567 = wasm_f32x4_add(vacc2x4567, wasm_f32x4_mul(va2, vb4567c3));
185 vacc3x4567 = wasm_f32x4_add(vacc3x4567, wasm_f32x4_mul(va3, vb4567c3));
186 vacc4x4567 = wasm_f32x4_add(vacc4x4567, wasm_f32x4_mul(va4, vb4567c3));
187 vacc5x4567 = wasm_f32x4_add(vacc5x4567, wasm_f32x4_mul(va5, vb4567c3));
188
189
190 w += 32;
191 k -= 4 * sizeof(float);
192 }
193 if XNN_UNLIKELY(k != 0) {
194 do {
195 const v128_t va0 = wasm_v32x4_load_splat(a0);
196 a0 += 1;
197 const v128_t va1 = wasm_v32x4_load_splat(a1);
198 a1 += 1;
199 const v128_t va2 = wasm_v32x4_load_splat(a2);
200 a2 += 1;
201 const v128_t va3 = wasm_v32x4_load_splat(a3);
202 a3 += 1;
203 const v128_t va4 = wasm_v32x4_load_splat(a4);
204 a4 += 1;
205 const v128_t va5 = wasm_v32x4_load_splat(a5);
206 a5 += 1;
207
208 const v128_t vb0123 = wasm_v128_load(w);
209 const v128_t vb4567 = wasm_v128_load(w + 4);
210 w += 8;
211
212 vacc0x0123 = wasm_f32x4_add(vacc0x0123, wasm_f32x4_mul(va0, vb0123));
213 vacc1x0123 = wasm_f32x4_add(vacc1x0123, wasm_f32x4_mul(va1, vb0123));
214 vacc2x0123 = wasm_f32x4_add(vacc2x0123, wasm_f32x4_mul(va2, vb0123));
215 vacc3x0123 = wasm_f32x4_add(vacc3x0123, wasm_f32x4_mul(va3, vb0123));
216 vacc4x0123 = wasm_f32x4_add(vacc4x0123, wasm_f32x4_mul(va4, vb0123));
217 vacc5x0123 = wasm_f32x4_add(vacc5x0123, wasm_f32x4_mul(va5, vb0123));
218 vacc0x4567 = wasm_f32x4_add(vacc0x4567, wasm_f32x4_mul(va0, vb4567));
219 vacc1x4567 = wasm_f32x4_add(vacc1x4567, wasm_f32x4_mul(va1, vb4567));
220 vacc2x4567 = wasm_f32x4_add(vacc2x4567, wasm_f32x4_mul(va2, vb4567));
221 vacc3x4567 = wasm_f32x4_add(vacc3x4567, wasm_f32x4_mul(va3, vb4567));
222 vacc4x4567 = wasm_f32x4_add(vacc4x4567, wasm_f32x4_mul(va4, vb4567));
223 vacc5x4567 = wasm_f32x4_add(vacc5x4567, wasm_f32x4_mul(va5, vb4567));
224
225 k -= sizeof(float);
226 } while (k != 0);
227 }
228
229 const v128_t vmin = wasm_v32x4_load_splat(¶ms->scalar.min);
230 vacc0x0123 = wasm_v128_bitselect(vmin, vacc0x0123, wasm_f32x4_lt(vacc0x0123, vmin));
231 vacc1x0123 = wasm_v128_bitselect(vmin, vacc1x0123, wasm_f32x4_lt(vacc1x0123, vmin));
232 vacc2x0123 = wasm_v128_bitselect(vmin, vacc2x0123, wasm_f32x4_lt(vacc2x0123, vmin));
233 vacc3x0123 = wasm_v128_bitselect(vmin, vacc3x0123, wasm_f32x4_lt(vacc3x0123, vmin));
234 vacc4x0123 = wasm_v128_bitselect(vmin, vacc4x0123, wasm_f32x4_lt(vacc4x0123, vmin));
235 vacc5x0123 = wasm_v128_bitselect(vmin, vacc5x0123, wasm_f32x4_lt(vacc5x0123, vmin));
236 vacc0x4567 = wasm_v128_bitselect(vmin, vacc0x4567, wasm_f32x4_lt(vacc0x4567, vmin));
237 vacc1x4567 = wasm_v128_bitselect(vmin, vacc1x4567, wasm_f32x4_lt(vacc1x4567, vmin));
238 vacc2x4567 = wasm_v128_bitselect(vmin, vacc2x4567, wasm_f32x4_lt(vacc2x4567, vmin));
239 vacc3x4567 = wasm_v128_bitselect(vmin, vacc3x4567, wasm_f32x4_lt(vacc3x4567, vmin));
240 vacc4x4567 = wasm_v128_bitselect(vmin, vacc4x4567, wasm_f32x4_lt(vacc4x4567, vmin));
241 vacc5x4567 = wasm_v128_bitselect(vmin, vacc5x4567, wasm_f32x4_lt(vacc5x4567, vmin));
242
243 const v128_t vmax = wasm_v32x4_load_splat(¶ms->scalar.max);
244 vacc0x0123 = wasm_v128_bitselect(vacc0x0123, vmax, wasm_f32x4_le(vacc0x0123, vmax));
245 vacc1x0123 = wasm_v128_bitselect(vacc1x0123, vmax, wasm_f32x4_le(vacc1x0123, vmax));
246 vacc2x0123 = wasm_v128_bitselect(vacc2x0123, vmax, wasm_f32x4_le(vacc2x0123, vmax));
247 vacc3x0123 = wasm_v128_bitselect(vacc3x0123, vmax, wasm_f32x4_le(vacc3x0123, vmax));
248 vacc4x0123 = wasm_v128_bitselect(vacc4x0123, vmax, wasm_f32x4_le(vacc4x0123, vmax));
249 vacc5x0123 = wasm_v128_bitselect(vacc5x0123, vmax, wasm_f32x4_le(vacc5x0123, vmax));
250 vacc0x4567 = wasm_v128_bitselect(vacc0x4567, vmax, wasm_f32x4_le(vacc0x4567, vmax));
251 vacc1x4567 = wasm_v128_bitselect(vacc1x4567, vmax, wasm_f32x4_le(vacc1x4567, vmax));
252 vacc2x4567 = wasm_v128_bitselect(vacc2x4567, vmax, wasm_f32x4_le(vacc2x4567, vmax));
253 vacc3x4567 = wasm_v128_bitselect(vacc3x4567, vmax, wasm_f32x4_le(vacc3x4567, vmax));
254 vacc4x4567 = wasm_v128_bitselect(vacc4x4567, vmax, wasm_f32x4_le(vacc4x4567, vmax));
255 vacc5x4567 = wasm_v128_bitselect(vacc5x4567, vmax, wasm_f32x4_le(vacc5x4567, vmax));
256
257 if XNN_LIKELY(nc >= 8) {
258 wasm_v128_store(c5, vacc5x0123);
259 wasm_v128_store(c5 + 4, vacc5x4567);
260 c5 = (float*) ((uintptr_t) c5 + cn_stride);
261 wasm_v128_store(c4, vacc4x0123);
262 wasm_v128_store(c4 + 4, vacc4x4567);
263 c4 = (float*) ((uintptr_t) c4 + cn_stride);
264 wasm_v128_store(c3, vacc3x0123);
265 wasm_v128_store(c3 + 4, vacc3x4567);
266 c3 = (float*) ((uintptr_t) c3 + cn_stride);
267 wasm_v128_store(c2, vacc2x0123);
268 wasm_v128_store(c2 + 4, vacc2x4567);
269 c2 = (float*) ((uintptr_t) c2 + cn_stride);
270 wasm_v128_store(c1, vacc1x0123);
271 wasm_v128_store(c1 + 4, vacc1x4567);
272 c1 = (float*) ((uintptr_t) c1 + cn_stride);
273 wasm_v128_store(c0, vacc0x0123);
274 wasm_v128_store(c0 + 4, vacc0x4567);
275 c0 = (float*) ((uintptr_t) c0 + cn_stride);
276
277 a5 = (const float*) ((uintptr_t) a5 - kc);
278 a4 = (const float*) ((uintptr_t) a4 - kc);
279 a3 = (const float*) ((uintptr_t) a3 - kc);
280 a2 = (const float*) ((uintptr_t) a2 - kc);
281 a1 = (const float*) ((uintptr_t) a1 - kc);
282 a0 = (const float*) ((uintptr_t) a0 - kc);
283
284 nc -= 8;
285 } else {
286 if (nc & 4) {
287 wasm_v128_store(c5, vacc5x0123);
288 wasm_v128_store(c4, vacc4x0123);
289 wasm_v128_store(c3, vacc3x0123);
290 wasm_v128_store(c2, vacc2x0123);
291 wasm_v128_store(c1, vacc1x0123);
292 wasm_v128_store(c0, vacc0x0123);
293
294 vacc5x0123 = vacc5x4567;
295 vacc4x0123 = vacc4x4567;
296 vacc3x0123 = vacc3x4567;
297 vacc2x0123 = vacc2x4567;
298 vacc1x0123 = vacc1x4567;
299 vacc0x0123 = vacc0x4567;
300
301 c5 += 4;
302 c4 += 4;
303 c3 += 4;
304 c2 += 4;
305 c1 += 4;
306 c0 += 4;
307 }
308 if (nc & 2) {
309 *((double*) c5) = wasm_f64x2_extract_lane(vacc5x0123, 0);
310 *((double*) c4) = wasm_f64x2_extract_lane(vacc4x0123, 0);
311 *((double*) c3) = wasm_f64x2_extract_lane(vacc3x0123, 0);
312 *((double*) c2) = wasm_f64x2_extract_lane(vacc2x0123, 0);
313 *((double*) c1) = wasm_f64x2_extract_lane(vacc1x0123, 0);
314 *((double*) c0) = wasm_f64x2_extract_lane(vacc0x0123, 0);
315
316 vacc5x0123 = wasm_v32x4_shuffle(vacc5x0123, vacc5x0123, 2, 3, 2, 3);
317 vacc4x0123 = wasm_v32x4_shuffle(vacc4x0123, vacc4x0123, 2, 3, 2, 3);
318 vacc3x0123 = wasm_v32x4_shuffle(vacc3x0123, vacc3x0123, 2, 3, 2, 3);
319 vacc2x0123 = wasm_v32x4_shuffle(vacc2x0123, vacc2x0123, 2, 3, 2, 3);
320 vacc1x0123 = wasm_v32x4_shuffle(vacc1x0123, vacc1x0123, 2, 3, 2, 3);
321 vacc0x0123 = wasm_v32x4_shuffle(vacc0x0123, vacc0x0123, 2, 3, 2, 3);
322
323 c5 += 2;
324 c4 += 2;
325 c3 += 2;
326 c2 += 2;
327 c1 += 2;
328 c0 += 2;
329 }
330 if (nc & 1) {
331 *c5 = wasm_f32x4_extract_lane(vacc5x0123, 0);
332 *c4 = wasm_f32x4_extract_lane(vacc4x0123, 0);
333 *c3 = wasm_f32x4_extract_lane(vacc3x0123, 0);
334 *c2 = wasm_f32x4_extract_lane(vacc2x0123, 0);
335 *c1 = wasm_f32x4_extract_lane(vacc1x0123, 0);
336 *c0 = wasm_f32x4_extract_lane(vacc0x0123, 0);
337 }
338
339 nc = 0;
340 }
341 } while (nc != 0);
342 }
343