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_up8x4__wasmsimd_x86_acc2(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_up8x4__wasmsimd_x86_acc2(
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(¶ms->scalar.min);
33 const v128_t vmax = wasm_v32x4_load_splat(¶ms->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 input = (const float**) ((uintptr_t) input + input_stride);
56
57 size_t c = channels;
58 const float* w = weights;
59 for (; c >= 8; c -= 8) {
60 v128_t vacc0123p0 = wasm_v128_load(w);
61 v128_t vacc4567p0 = wasm_v128_load(w + 4);
62
63
64 const v128_t vi0x0123 = wasm_v128_load(i0);
65 const v128_t vi0x4567 = wasm_v128_load(i0 + 4);
66 i0 += 8;
67
68 const v128_t vk0x0123 = wasm_v128_load(w + 8);
69 const v128_t vk0x4567 = wasm_v128_load(w + 12);
70 vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi0x0123, vk0x0123));
71 vacc4567p0 = wasm_f32x4_add(vacc4567p0, wasm_f32x4_mul(vi0x4567, vk0x4567));
72
73 const v128_t vi1x0123 = wasm_v128_load(i1);
74 const v128_t vi1x4567 = wasm_v128_load(i1 + 4);
75 i1 += 8;
76
77 const v128_t vk1x0123 = wasm_v128_load(w + 16);
78 const v128_t vk1x4567 = wasm_v128_load(w + 20);
79 v128_t vacc0123p1 = wasm_f32x4_mul(vi1x0123, vk1x0123);
80 v128_t vacc4567p1 = wasm_f32x4_mul(vi1x4567, vk1x4567);
81
82 const v128_t vi2x0123 = wasm_v128_load(i2);
83 const v128_t vi2x4567 = wasm_v128_load(i2 + 4);
84 i2 += 8;
85
86 const v128_t vk2x0123 = wasm_v128_load(w + 24);
87 const v128_t vk2x4567 = wasm_v128_load(w + 28);
88 vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi2x0123, vk2x0123));
89 vacc4567p0 = wasm_f32x4_add(vacc4567p0, wasm_f32x4_mul(vi2x4567, vk2x4567));
90
91 const v128_t vi3x0123 = wasm_v128_load(i3);
92 const v128_t vi3x4567 = wasm_v128_load(i3 + 4);
93 i3 += 8;
94
95 const v128_t vk3x0123 = wasm_v128_load(w + 32);
96 const v128_t vk3x4567 = wasm_v128_load(w + 36);
97 vacc0123p1 = wasm_f32x4_add(vacc0123p1, wasm_f32x4_mul(vi3x0123, vk3x0123));
98 vacc4567p1 = wasm_f32x4_add(vacc4567p1, wasm_f32x4_mul(vi3x4567, vk3x4567));
99
100 w += 40;
101
102 // Add up all accumulators to vacc01234567p0
103 vacc0123p0 = wasm_f32x4_add(vacc0123p0, vacc0123p1);
104 vacc4567p0 = wasm_f32x4_add(vacc4567p0, vacc4567p1);
105
106 v128_t vacc0123 = wasm_v128_bitselect(vmin, vacc0123p0, wasm_f32x4_lt(vacc0123p0, vmin));
107 v128_t vacc4567 = wasm_v128_bitselect(vmin, vacc4567p0, wasm_f32x4_lt(vacc4567p0, vmin));
108
109 vacc0123 = wasm_v128_bitselect(vacc0123, vmax, wasm_f32x4_le(vacc0123, vmax));
110 vacc4567 = wasm_v128_bitselect(vacc4567, vmax, wasm_f32x4_le(vacc4567, vmax));
111
112 wasm_v128_store(output, vacc0123);
113 wasm_v128_store(output + 4, vacc4567);
114 output += 8;
115 }
116 for (; c >= 4; c -= 4) {
117 v128_t vacc0123p0 = wasm_v128_load(w);
118
119 const v128_t vi0x0123 = wasm_v128_load(i0);
120 i0 += 4;
121
122 const v128_t vk0x0123 = wasm_v128_load(w + 8);
123 vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi0x0123, vk0x0123));
124
125 const v128_t vi1x0123 = wasm_v128_load(i1);
126 i1 += 4;
127
128 const v128_t vk1x0123 = wasm_v128_load(w + 16);
129 v128_t vacc0123p1 = wasm_f32x4_mul(vi1x0123, vk1x0123);
130
131 const v128_t vi2x0123 = wasm_v128_load(i2);
132 i2 += 4;
133
134 const v128_t vk2x0123 = wasm_v128_load(w + 24);
135 vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi2x0123, vk2x0123));
136
137 const v128_t vi3x0123 = wasm_v128_load(i3);
138 i3 += 4;
139
140 const v128_t vk3x0123 = wasm_v128_load(w + 32);
141 vacc0123p1 = wasm_f32x4_add(vacc0123p1, wasm_f32x4_mul(vi3x0123, vk3x0123));
142
143 w += 4;
144
145 // Add up all accumulators to vacc01234567p0
146 vacc0123p0 = wasm_f32x4_add(vacc0123p0, vacc0123p1);
147
148 v128_t vacc0123 = wasm_v128_bitselect(vmin, vacc0123p0, wasm_f32x4_lt(vacc0123p0, vmin));
149 vacc0123 = wasm_v128_bitselect(vacc0123, vmax, wasm_f32x4_le(vacc0123, vmax));
150
151 wasm_v128_store(output, vacc0123);
152 output += 4;
153 }
154 if XNN_UNLIKELY(c != 0) {
155 v128_t vacc0123p0 = wasm_v128_load(w);
156
157 const v128_t vi0x0123 = wasm_v128_load(i0);
158 const v128_t vk0x0123 = wasm_v128_load(w + 8);
159 vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi0x0123, vk0x0123));
160
161 const v128_t vi1x0123 = wasm_v128_load(i1);
162 const v128_t vk1x0123 = wasm_v128_load(w + 16);
163 v128_t vacc0123p1 = wasm_f32x4_mul(vi1x0123, vk1x0123);
164
165 const v128_t vi2x0123 = wasm_v128_load(i2);
166 const v128_t vk2x0123 = wasm_v128_load(w + 24);
167 vacc0123p0 = wasm_f32x4_add(vacc0123p0, wasm_f32x4_mul(vi2x0123, vk2x0123));
168
169 const v128_t vi3x0123 = wasm_v128_load(i3);
170 const v128_t vk3x0123 = wasm_v128_load(w + 32);
171 vacc0123p1 = wasm_f32x4_add(vacc0123p1, wasm_f32x4_mul(vi3x0123, vk3x0123));
172
173 // Add up all accumulators to vacc01234567p0
174 vacc0123p0 = wasm_f32x4_add(vacc0123p0, vacc0123p1);
175
176 v128_t vacc0123 = wasm_v128_bitselect(vmin, vacc0123p0, wasm_f32x4_lt(vacc0123p0, vmin));
177 vacc0123 = wasm_v128_bitselect(vacc0123, vmax, wasm_f32x4_le(vacc0123, vmax));
178
179 if (c & 2) {
180 *((double*) output) = wasm_f64x2_extract_lane(vacc0123, 0);
181 vacc0123 = wasm_v32x4_shuffle(vacc0123, vacc0123, 2, 3, 2, 3);
182 output += 2;
183 }
184 if (c & 1) {
185 *output = wasm_f32x4_extract_lane(vacc0123, 0);
186 output += 1;
187 }
188 }
189
190 output = (float*) ((uintptr_t) output + output_increment);
191 } while (--output_width != 0);
192 }
193