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