1 // Auto-generated file. Do not edit!
2 //   Template: src/f32-dwconv/up-wasmsimd.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/dwconv.h>
15 
16 
xnn_f32_dwconv_minmax_ukernel_up4x25__wasmsimd_x86(size_t channels,size_t output_width,const float ** input,const float * weights,float * output,size_t input_stride,size_t output_increment,size_t input_offset,const float * zero,const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])17 void xnn_f32_dwconv_minmax_ukernel_up4x25__wasmsimd_x86(
18     size_t channels,
19     size_t output_width,
20     const float** input,
21     const float* weights,
22     float* output,
23     size_t input_stride,
24     size_t output_increment,
25     size_t input_offset,
26     const float* zero,
27     const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_DISABLE_TSAN
28 {
29   assert(channels != 0);
30   assert(output_width != 0);
31 
32   const v128_t vmin = wasm_v32x4_load_splat(&params->scalar.min);
33   const v128_t vmax = wasm_v32x4_load_splat(&params->scalar.max);
34   do {
35     const float* i0 = input[0];
36     assert(i0 != NULL);
37     if XNN_UNPREDICTABLE(i0 != zero) {
38       i0 = (const float*) ((uintptr_t) i0 + input_offset);
39     }
40     const float* i1 = input[1];
41     assert(i1 != NULL);
42     if XNN_UNPREDICTABLE(i1 != zero) {
43       i1 = (const float*) ((uintptr_t) i1 + input_offset);
44     }
45     const float* i2 = input[2];
46     assert(i2 != NULL);
47     if XNN_UNPREDICTABLE(i2 != zero) {
48       i2 = (const float*) ((uintptr_t) i2 + input_offset);
49     }
50     const float* i3 = input[3];
51     assert(i3 != NULL);
52     if XNN_UNPREDICTABLE(i3 != zero) {
53       i3 = (const float*) ((uintptr_t) i3 + input_offset);
54     }
55     const float* i4 = input[4];
56     assert(i4 != NULL);
57     if XNN_UNPREDICTABLE(i4 != zero) {
58       i4 = (const float*) ((uintptr_t) i4 + input_offset);
59     }
60     const float* i5 = input[5];
61     assert(i5 != NULL);
62     if XNN_UNPREDICTABLE(i5 != zero) {
63       i5 = (const float*) ((uintptr_t) i5 + input_offset);
64     }
65     const float* i6 = input[6];
66     assert(i6 != NULL);
67     if XNN_UNPREDICTABLE(i6 != zero) {
68       i6 = (const float*) ((uintptr_t) i6 + input_offset);
69     }
70     const float* i7 = input[7];
71     assert(i7 != NULL);
72     if XNN_UNPREDICTABLE(i7 != zero) {
73       i7 = (const float*) ((uintptr_t) i7 + input_offset);
74     }
75     const float* i8 = input[8];
76     assert(i8 != NULL);
77     if XNN_UNPREDICTABLE(i8 != zero) {
78       i8 = (const float*) ((uintptr_t) i8 + input_offset);
79     }
80     const float* i9 = input[9];
81     assert(i9 != NULL);
82     if XNN_UNPREDICTABLE(i9 != zero) {
83       i9 = (const float*) ((uintptr_t) i9 + input_offset);
84     }
85     const float* i10 = input[10];
86     assert(i10 != NULL);
87     if XNN_UNPREDICTABLE(i10 != zero) {
88       i10 = (const float*) ((uintptr_t) i10 + input_offset);
89     }
90     const float* i11 = input[11];
91     assert(i11 != NULL);
92     if XNN_UNPREDICTABLE(i11 != zero) {
93       i11 = (const float*) ((uintptr_t) i11 + input_offset);
94     }
95     const float* i12 = input[12];
96     assert(i12 != NULL);
97     if XNN_UNPREDICTABLE(i12 != zero) {
98       i12 = (const float*) ((uintptr_t) i12 + input_offset);
99     }
100     const float* i13 = input[13];
101     assert(i13 != NULL);
102     if XNN_UNPREDICTABLE(i13 != zero) {
103       i13 = (const float*) ((uintptr_t) i13 + input_offset);
104     }
105     const float* i14 = input[14];
106     assert(i14 != NULL);
107     if XNN_UNPREDICTABLE(i14 != zero) {
108       i14 = (const float*) ((uintptr_t) i14 + input_offset);
109     }
110     const float* i15 = input[15];
111     assert(i15 != NULL);
112     if XNN_UNPREDICTABLE(i15 != zero) {
113       i15 = (const float*) ((uintptr_t) i15 + input_offset);
114     }
115     const float* i16 = input[16];
116     assert(i16 != NULL);
117     if XNN_UNPREDICTABLE(i16 != zero) {
118       i16 = (const float*) ((uintptr_t) i16 + input_offset);
119     }
120     const float* i17 = input[17];
121     assert(i17 != NULL);
122     if XNN_UNPREDICTABLE(i17 != zero) {
123       i17 = (const float*) ((uintptr_t) i17 + input_offset);
124     }
125     const float* i18 = input[18];
126     assert(i18 != NULL);
127     if XNN_UNPREDICTABLE(i18 != zero) {
128       i18 = (const float*) ((uintptr_t) i18 + input_offset);
129     }
130     const float* i19 = input[19];
131     assert(i19 != NULL);
132     if XNN_UNPREDICTABLE(i19 != zero) {
133       i19 = (const float*) ((uintptr_t) i19 + input_offset);
134     }
135     const float* i20 = input[20];
136     assert(i20 != NULL);
137     if XNN_UNPREDICTABLE(i20 != zero) {
138       i20 = (const float*) ((uintptr_t) i20 + input_offset);
139     }
140     const float* i21 = input[21];
141     assert(i21 != NULL);
142     if XNN_UNPREDICTABLE(i21 != zero) {
143       i21 = (const float*) ((uintptr_t) i21 + input_offset);
144     }
145     const float* i22 = input[22];
146     assert(i22 != NULL);
147     if XNN_UNPREDICTABLE(i22 != zero) {
148       i22 = (const float*) ((uintptr_t) i22 + input_offset);
149     }
150     const float* i23 = input[23];
151     assert(i23 != NULL);
152     if XNN_UNPREDICTABLE(i23 != zero) {
153       i23 = (const float*) ((uintptr_t) i23 + input_offset);
154     }
155     const float* i24 = input[24];
156     assert(i24 != NULL);
157     if XNN_UNPREDICTABLE(i24 != zero) {
158       i24 = (const float*) ((uintptr_t) i24 + input_offset);
159     }
160     input = (const float**) ((uintptr_t) input + input_stride);
161 
162     size_t c = channels;
163     const float* w = weights;
164     for (; c >= 4; c -= 4) {
165       v128_t vacc0123p0 = wasm_v128_load(w);
166 
167 
168       const v128_t vi0x0123 = wasm_v128_load(i0);
169       i0 += 4;
170 
171       const v128_t vk0x0123 = wasm_v128_load(w + 4);
172       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi0x0123, vk0x0123));
173 
174       const v128_t vi1x0123 = wasm_v128_load(i1);
175       i1 += 4;
176 
177       const v128_t vk1x0123 = wasm_v128_load(w + 8);
178       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi1x0123, vk1x0123));
179 
180       const v128_t vi2x0123 = wasm_v128_load(i2);
181       i2 += 4;
182 
183       const v128_t vk2x0123 = wasm_v128_load(w + 12);
184       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi2x0123, vk2x0123));
185 
186       const v128_t vi3x0123 = wasm_v128_load(i3);
187       i3 += 4;
188 
189       const v128_t vk3x0123 = wasm_v128_load(w + 16);
190       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi3x0123, vk3x0123));
191 
192       const v128_t vi4x0123 = wasm_v128_load(i4);
193       i4 += 4;
194 
195       const v128_t vk4x0123 = wasm_v128_load(w + 20);
196       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi4x0123, vk4x0123));
197 
198       const v128_t vi5x0123 = wasm_v128_load(i5);
199       i5 += 4;
200 
201       const v128_t vk5x0123 = wasm_v128_load(w + 24);
202       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi5x0123, vk5x0123));
203 
204       const v128_t vi6x0123 = wasm_v128_load(i6);
205       i6 += 4;
206 
207       const v128_t vk6x0123 = wasm_v128_load(w + 28);
208       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi6x0123, vk6x0123));
209 
210       const v128_t vi7x0123 = wasm_v128_load(i7);
211       i7 += 4;
212 
213       const v128_t vk7x0123 = wasm_v128_load(w + 32);
214       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi7x0123, vk7x0123));
215 
216       const v128_t vi8x0123 = wasm_v128_load(i8);
217       i8 += 4;
218 
219       const v128_t vk8x0123 = wasm_v128_load(w + 36);
220       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi8x0123, vk8x0123));
221 
222       const v128_t vi9x0123 = wasm_v128_load(i9);
223       i9 += 4;
224 
225       const v128_t vk9x0123 = wasm_v128_load(w + 40);
226       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi9x0123, vk9x0123));
227 
228       const v128_t vi10x0123 = wasm_v128_load(i10);
229       i10 += 4;
230 
231       const v128_t vk10x0123 = wasm_v128_load(w + 44);
232       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi10x0123, vk10x0123));
233 
234       const v128_t vi11x0123 = wasm_v128_load(i11);
235       i11 += 4;
236 
237       const v128_t vk11x0123 = wasm_v128_load(w + 48);
238       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi11x0123, vk11x0123));
239 
240       const v128_t vi12x0123 = wasm_v128_load(i12);
241       i12 += 4;
242 
243       const v128_t vk12x0123 = wasm_v128_load(w + 52);
244       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi12x0123, vk12x0123));
245 
246       const v128_t vi13x0123 = wasm_v128_load(i13);
247       i13 += 4;
248 
249       const v128_t vk13x0123 = wasm_v128_load(w + 56);
250       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi13x0123, vk13x0123));
251 
252       const v128_t vi14x0123 = wasm_v128_load(i14);
253       i14 += 4;
254 
255       const v128_t vk14x0123 = wasm_v128_load(w + 60);
256       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi14x0123, vk14x0123));
257 
258       const v128_t vi15x0123 = wasm_v128_load(i15);
259       i15 += 4;
260 
261       const v128_t vk15x0123 = wasm_v128_load(w + 64);
262       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi15x0123, vk15x0123));
263 
264       const v128_t vi16x0123 = wasm_v128_load(i16);
265       i16 += 4;
266 
267       const v128_t vk16x0123 = wasm_v128_load(w + 68);
268       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi16x0123, vk16x0123));
269 
270       const v128_t vi17x0123 = wasm_v128_load(i17);
271       i17 += 4;
272 
273       const v128_t vk17x0123 = wasm_v128_load(w + 72);
274       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi17x0123, vk17x0123));
275 
276       const v128_t vi18x0123 = wasm_v128_load(i18);
277       i18 += 4;
278 
279       const v128_t vk18x0123 = wasm_v128_load(w + 76);
280       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi18x0123, vk18x0123));
281 
282       const v128_t vi19x0123 = wasm_v128_load(i19);
283       i19 += 4;
284 
285       const v128_t vk19x0123 = wasm_v128_load(w + 80);
286       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi19x0123, vk19x0123));
287 
288       const v128_t vi20x0123 = wasm_v128_load(i20);
289       i20 += 4;
290 
291       const v128_t vk20x0123 = wasm_v128_load(w + 84);
292       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi20x0123, vk20x0123));
293 
294       const v128_t vi21x0123 = wasm_v128_load(i21);
295       i21 += 4;
296 
297       const v128_t vk21x0123 = wasm_v128_load(w + 88);
298       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi21x0123, vk21x0123));
299 
300       const v128_t vi22x0123 = wasm_v128_load(i22);
301       i22 += 4;
302 
303       const v128_t vk22x0123 = wasm_v128_load(w + 92);
304       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi22x0123, vk22x0123));
305 
306       const v128_t vi23x0123 = wasm_v128_load(i23);
307       i23 += 4;
308 
309       const v128_t vk23x0123 = wasm_v128_load(w + 96);
310       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi23x0123, vk23x0123));
311 
312       const v128_t vi24x0123 = wasm_v128_load(i24);
313       i24 += 4;
314 
315       const v128_t vk24x0123 = wasm_v128_load(w + 100);
316       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi24x0123, vk24x0123));
317 
318       w += 104;
319 
320 
321       v128_t vacc0123 = wasm_v128_bitselect(vmin, vacc0123p0, wasm_f32x4_lt(vacc0123p0, vmin));
322 
323       vacc0123 = wasm_v128_bitselect(vacc0123, vmax, wasm_f32x4_le(vacc0123, vmax));
324 
325       wasm_v128_store(output, vacc0123);
326       output += 4;
327     }
328     if XNN_UNLIKELY(c != 0) {
329       v128_t vacc0123p0 = wasm_v128_load(w);
330 
331       const v128_t vi0x0123 = wasm_v128_load(i0);
332       const v128_t vk0x0123 = wasm_v128_load(w + 4);
333       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi0x0123, vk0x0123));
334 
335       const v128_t vi1x0123 = wasm_v128_load(i1);
336       const v128_t vk1x0123 = wasm_v128_load(w + 8);
337       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi1x0123, vk1x0123));
338 
339       const v128_t vi2x0123 = wasm_v128_load(i2);
340       const v128_t vk2x0123 = wasm_v128_load(w + 12);
341       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi2x0123, vk2x0123));
342 
343       const v128_t vi3x0123 = wasm_v128_load(i3);
344       const v128_t vk3x0123 = wasm_v128_load(w + 16);
345       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi3x0123, vk3x0123));
346 
347       const v128_t vi4x0123 = wasm_v128_load(i4);
348       const v128_t vk4x0123 = wasm_v128_load(w + 20);
349       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi4x0123, vk4x0123));
350 
351       const v128_t vi5x0123 = wasm_v128_load(i5);
352       const v128_t vk5x0123 = wasm_v128_load(w + 24);
353       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi5x0123, vk5x0123));
354 
355       const v128_t vi6x0123 = wasm_v128_load(i6);
356       const v128_t vk6x0123 = wasm_v128_load(w + 28);
357       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi6x0123, vk6x0123));
358 
359       const v128_t vi7x0123 = wasm_v128_load(i7);
360       const v128_t vk7x0123 = wasm_v128_load(w + 32);
361       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi7x0123, vk7x0123));
362 
363       const v128_t vi8x0123 = wasm_v128_load(i8);
364       const v128_t vk8x0123 = wasm_v128_load(w + 36);
365       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi8x0123, vk8x0123));
366 
367       const v128_t vi9x0123 = wasm_v128_load(i9);
368       const v128_t vk9x0123 = wasm_v128_load(w + 40);
369       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi9x0123, vk9x0123));
370 
371       const v128_t vi10x0123 = wasm_v128_load(i10);
372       const v128_t vk10x0123 = wasm_v128_load(w + 44);
373       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi10x0123, vk10x0123));
374 
375       const v128_t vi11x0123 = wasm_v128_load(i11);
376       const v128_t vk11x0123 = wasm_v128_load(w + 48);
377       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi11x0123, vk11x0123));
378 
379       const v128_t vi12x0123 = wasm_v128_load(i12);
380       const v128_t vk12x0123 = wasm_v128_load(w + 52);
381       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi12x0123, vk12x0123));
382 
383       const v128_t vi13x0123 = wasm_v128_load(i13);
384       const v128_t vk13x0123 = wasm_v128_load(w + 56);
385       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi13x0123, vk13x0123));
386 
387       const v128_t vi14x0123 = wasm_v128_load(i14);
388       const v128_t vk14x0123 = wasm_v128_load(w + 60);
389       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi14x0123, vk14x0123));
390 
391       const v128_t vi15x0123 = wasm_v128_load(i15);
392       const v128_t vk15x0123 = wasm_v128_load(w + 64);
393       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi15x0123, vk15x0123));
394 
395       const v128_t vi16x0123 = wasm_v128_load(i16);
396       const v128_t vk16x0123 = wasm_v128_load(w + 68);
397       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi16x0123, vk16x0123));
398 
399       const v128_t vi17x0123 = wasm_v128_load(i17);
400       const v128_t vk17x0123 = wasm_v128_load(w + 72);
401       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi17x0123, vk17x0123));
402 
403       const v128_t vi18x0123 = wasm_v128_load(i18);
404       const v128_t vk18x0123 = wasm_v128_load(w + 76);
405       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi18x0123, vk18x0123));
406 
407       const v128_t vi19x0123 = wasm_v128_load(i19);
408       const v128_t vk19x0123 = wasm_v128_load(w + 80);
409       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi19x0123, vk19x0123));
410 
411       const v128_t vi20x0123 = wasm_v128_load(i20);
412       const v128_t vk20x0123 = wasm_v128_load(w + 84);
413       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi20x0123, vk20x0123));
414 
415       const v128_t vi21x0123 = wasm_v128_load(i21);
416       const v128_t vk21x0123 = wasm_v128_load(w + 88);
417       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi21x0123, vk21x0123));
418 
419       const v128_t vi22x0123 = wasm_v128_load(i22);
420       const v128_t vk22x0123 = wasm_v128_load(w + 92);
421       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi22x0123, vk22x0123));
422 
423       const v128_t vi23x0123 = wasm_v128_load(i23);
424       const v128_t vk23x0123 = wasm_v128_load(w + 96);
425       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi23x0123, vk23x0123));
426 
427       const v128_t vi24x0123 = wasm_v128_load(i24);
428       const v128_t vk24x0123 = wasm_v128_load(w + 100);
429       vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi24x0123, vk24x0123));
430 
431 
432       v128_t vacc0123 = wasm_v128_bitselect(vmin, vacc0123p0, wasm_f32x4_lt(vacc0123p0, vmin));
433       vacc0123 = wasm_v128_bitselect(vacc0123, vmax, wasm_f32x4_le(vacc0123, vmax));
434 
435       if (c & 2) {
436         *((double*) output) = wasm_f64x2_extract_lane(vacc0123, 0);
437         vacc0123 = wasm_v32x4_shuffle(vacc0123, vacc0123, 2, 3, 2, 3);
438         output += 2;
439       }
440       if (c & 1) {
441         *output = wasm_f32x4_extract_lane(vacc0123, 0);
442         output += 1;
443       }
444     }
445 
446     output = (float*) ((uintptr_t) output + output_increment);
447   } while (--output_width != 0);
448 }
449