1 // Auto-generated file. Do not edit!
2 // Template: src/f32-dwconv2d-chw/3x3p1-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/dwconv.h>
15 #include <xnnpack/math.h>
16
17
18
xnn_f32_dwconv2d_chw_ukernel_3x3p1__wasmsimd_arm_splat_2x4(size_t input_height,size_t input_width,const float * input,const float * weights,const float * zero,float * output,uint32_t padding_top,const union xnn_f32_chw_params params[restrict XNN_MIN_ELEMENTS (1)])19 void xnn_f32_dwconv2d_chw_ukernel_3x3p1__wasmsimd_arm_splat_2x4(
20 size_t input_height,
21 size_t input_width,
22 const float* input,
23 const float* weights,
24 const float* zero,
25 float* output,
26 uint32_t padding_top,
27 const union xnn_f32_chw_params params[restrict XNN_MIN_ELEMENTS(1)])
28 {
29 assert(input_height != 0);
30 assert(input_width != 0);
31 assert(input_width % sizeof(float) == 0);
32 assert(padding_top == 1);
33
34 const v128_t vmask = wasm_v128_load(params->scalar.mask);
35 const v128_t vmax = wasm_v32x4_load_splat(¶ms->scalar.max);
36 const v128_t vmin = wasm_v32x4_load_splat(¶ms->scalar.min);
37
38 const v128_t vw0123 = wasm_v128_load(weights);
39 const v128_t vw4567 = wasm_v128_load(weights + 4);
40 const v128_t vw89 = wasm_v64x2_load_splat(weights + 8);
41
42 const v128_t vzero = wasm_f32x4_splat(0.0f);
43
44 const size_t input_decrement = round_up_po2(input_width, 4 * sizeof(float));
45
46 const float* i0 = zero;
47 const float* i1 = input;
48 const float* i2 = (const float*) ((uintptr_t) i1 + input_width);
49 const float* i3 = (const float*) ((uintptr_t) i2 + input_width);
50
51 float* o0 = output;
52 float* o1 = (float*) ((uintptr_t) o0 + input_width);
53
54 size_t output_height = input_height;
55 do {
56 if XNN_UNPREDICTABLE(output_height < 2) {
57 i2 = zero;
58 o1 = o0;
59 }
60 if XNN_UNPREDICTABLE(output_height < 3) {
61 i3 = zero;
62 }
63
64 v128_t vi0x0123 = vzero;
65 v128_t vi1x0123 = vzero;
66 v128_t vi2x0123 = vzero;
67 v128_t vi3x0123 = vzero;
68
69 v128_t vi0x4567 = wasm_v128_load(i0); i0 += 4;
70 v128_t vi1x4567 = wasm_v128_load(i1); i1 += 4;
71 v128_t vi2x4567 = wasm_v128_load(i2); i2 += 4;
72 v128_t vi3x4567 = wasm_v128_load(i3); i3 += 4;
73
74 size_t w = input_width;
75 for (; w > 4 * sizeof(float); w -= 4 * sizeof(float)) {
76 v128_t vo0p0 = wasm_v32x4_shuffle(vw0123, vw0123, 0, 0, 0, 0);
77 v128_t vo1p0 = wasm_v32x4_shuffle(vw0123, vw0123, 0, 0, 0, 0);
78
79 const v128_t vi0x89AB = wasm_v128_load(i0); i0 += 4;
80 const v128_t vi1x89AB = wasm_v128_load(i1); i1 += 4;
81 const v128_t vi2x89AB = wasm_v128_load(i2); i2 += 4;
82 const v128_t vi3x89AB = wasm_v128_load(i3); i3 += 4;
83
84 vo0p0 = wasm_f32x4_add(vo0p0, wasm_f32x4_mul(vi0x4567, wasm_v32x4_shuffle(vw0123, vw0123, 2, 2, 2, 2)));
85 vo1p0 = wasm_f32x4_add(vo1p0, wasm_f32x4_mul(vi1x4567, wasm_v32x4_shuffle(vw0123, vw0123, 2, 2, 2, 2)));
86
87 vo0p0 = wasm_f32x4_add(vo0p0, wasm_f32x4_mul(vi1x4567, wasm_v32x4_shuffle(vw4567, vw4567, 1, 1, 1, 1)));
88 vo1p0 = wasm_f32x4_add(vo1p0, wasm_f32x4_mul(vi2x4567, wasm_v32x4_shuffle(vw4567, vw4567, 1, 1, 1, 1)));
89
90 vo0p0 = wasm_f32x4_add(vo0p0, wasm_f32x4_mul(vi2x4567, wasm_v32x4_shuffle(vw89, vw89, 0, 0, 0, 0)));
91 vo1p0 = wasm_f32x4_add(vo1p0, wasm_f32x4_mul(vi3x4567, wasm_v32x4_shuffle(vw89, vw89, 0, 0, 0, 0)));
92
93 const v128_t vi0x3456 = wasm_v32x4_shuffle(vi0x0123, vi0x4567, 3, 4, 5, 6);
94 const v128_t vi1x3456 = wasm_v32x4_shuffle(vi1x0123, vi1x4567, 3, 4, 5, 6);
95 const v128_t vi2x3456 = wasm_v32x4_shuffle(vi2x0123, vi2x4567, 3, 4, 5, 6);
96 const v128_t vi3x3456 = wasm_v32x4_shuffle(vi3x0123, vi3x4567, 3, 4, 5, 6);
97
98 vo0p0 = wasm_f32x4_add(vo0p0, wasm_f32x4_mul(vi0x3456, wasm_v32x4_shuffle(vw0123, vw0123, 1, 1, 1, 1)));
99 vo1p0 = wasm_f32x4_add(vo1p0, wasm_f32x4_mul(vi1x3456, wasm_v32x4_shuffle(vw0123, vw0123, 1, 1, 1, 1)));
100
101 vo0p0 = wasm_f32x4_add(vo0p0, wasm_f32x4_mul(vi1x3456, wasm_v32x4_shuffle(vw4567, vw4567, 0, 0, 0, 0)));
102 vo1p0 = wasm_f32x4_add(vo1p0, wasm_f32x4_mul(vi2x3456, wasm_v32x4_shuffle(vw4567, vw4567, 0, 0, 0, 0)));
103
104 vo0p0 = wasm_f32x4_add(vo0p0, wasm_f32x4_mul(vi2x3456, wasm_v32x4_shuffle(vw4567, vw4567, 3, 3, 3, 3)));
105 vo1p0 = wasm_f32x4_add(vo1p0, wasm_f32x4_mul(vi3x3456, wasm_v32x4_shuffle(vw4567, vw4567, 3, 3, 3, 3)));
106
107 vi0x0123 = vi0x4567;
108 vi1x0123 = vi1x4567;
109 vi2x0123 = vi2x4567;
110 vi3x0123 = vi3x4567;
111
112 const v128_t vi0x5678 = wasm_v32x4_shuffle(vi0x4567, vi0x89AB, 1, 2, 3, 4);
113 const v128_t vi1x5678 = wasm_v32x4_shuffle(vi1x4567, vi1x89AB, 1, 2, 3, 4);
114 const v128_t vi2x5678 = wasm_v32x4_shuffle(vi2x4567, vi2x89AB, 1, 2, 3, 4);
115 const v128_t vi3x5678 = wasm_v32x4_shuffle(vi3x4567, vi3x89AB, 1, 2, 3, 4);
116
117 vo0p0 = wasm_f32x4_add(vo0p0, wasm_f32x4_mul(vi0x5678, wasm_v32x4_shuffle(vw0123, vw0123, 3, 3, 3, 3)));
118 vo1p0 = wasm_f32x4_add(vo1p0, wasm_f32x4_mul(vi1x5678, wasm_v32x4_shuffle(vw0123, vw0123, 3, 3, 3, 3)));
119
120 vo0p0 = wasm_f32x4_add(vo0p0, wasm_f32x4_mul(vi1x5678, wasm_v32x4_shuffle(vw4567, vw4567, 2, 2, 2, 2)));
121 vo1p0 = wasm_f32x4_add(vo1p0, wasm_f32x4_mul(vi2x5678, wasm_v32x4_shuffle(vw4567, vw4567, 2, 2, 2, 2)));
122
123 vo0p0 = wasm_f32x4_add(vo0p0, wasm_f32x4_mul(vi2x5678, wasm_v32x4_shuffle(vw89, vw89, 1, 1, 1, 1)));
124 vo1p0 = wasm_f32x4_add(vo1p0, wasm_f32x4_mul(vi3x5678, wasm_v32x4_shuffle(vw89, vw89, 1, 1, 1, 1)));
125
126 vi0x4567 = vi0x89AB;
127 vi1x4567 = vi1x89AB;
128 vi2x4567 = vi2x89AB;
129 vi3x4567 = vi3x89AB;
130
131
132 v128_t vo0 = wasm_f32x4_max(vo0p0, vmin);
133 v128_t vo1 = wasm_f32x4_max(vo1p0, vmin);
134 vo0 = wasm_f32x4_min(vo0, vmax);
135 vo1 = wasm_f32x4_min(vo1, vmax);
136
137 wasm_v128_store(o1, vo1); o1 += 4;
138 wasm_v128_store(o0, vo0); o0 += 4;
139 }
140 // Always process the last block of 1..4 pixels.
141 assert(w >= 1 * sizeof(float));
142 assert(w <= 4 * sizeof(float));
143 {
144 v128_t vo0p0 = wasm_v32x4_shuffle(vw0123, vw0123, 0, 0, 0, 0);
145 v128_t vo1p0 = wasm_v32x4_shuffle(vw0123, vw0123, 0, 0, 0, 0);
146
147 vi0x4567 = wasm_v128_and(vmask, vi0x4567);
148 vi1x4567 = wasm_v128_and(vmask, vi1x4567);
149 vi2x4567 = wasm_v128_and(vmask, vi2x4567);
150 vi3x4567 = wasm_v128_and(vmask, vi3x4567);
151
152 vo0p0 = wasm_f32x4_add(vo0p0, wasm_f32x4_mul(vi0x4567, wasm_v32x4_shuffle(vw0123, vw0123, 2, 2, 2, 2)));
153 vo1p0 = wasm_f32x4_add(vo1p0, wasm_f32x4_mul(vi1x4567, wasm_v32x4_shuffle(vw0123, vw0123, 2, 2, 2, 2)));
154
155 vo0p0 = wasm_f32x4_add(vo0p0, wasm_f32x4_mul(vi1x4567, wasm_v32x4_shuffle(vw4567, vw4567, 1, 1, 1, 1)));
156 vo1p0 = wasm_f32x4_add(vo1p0, wasm_f32x4_mul(vi2x4567, wasm_v32x4_shuffle(vw4567, vw4567, 1, 1, 1, 1)));
157
158 vo0p0 = wasm_f32x4_add(vo0p0, wasm_f32x4_mul(vi2x4567, wasm_v32x4_shuffle(vw89, vw89, 0, 0, 0, 0)));
159 vo1p0 = wasm_f32x4_add(vo1p0, wasm_f32x4_mul(vi3x4567, wasm_v32x4_shuffle(vw89, vw89, 0, 0, 0, 0)));
160
161 const v128_t vi0x3456 = wasm_v32x4_shuffle(vi0x0123, vi0x4567, 3, 4, 5, 6);
162 const v128_t vi1x3456 = wasm_v32x4_shuffle(vi1x0123, vi1x4567, 3, 4, 5, 6);
163 const v128_t vi2x3456 = wasm_v32x4_shuffle(vi2x0123, vi2x4567, 3, 4, 5, 6);
164 const v128_t vi3x3456 = wasm_v32x4_shuffle(vi3x0123, vi3x4567, 3, 4, 5, 6);
165
166 vo0p0 = wasm_f32x4_add(vo0p0, wasm_f32x4_mul(vi0x3456, wasm_v32x4_shuffle(vw0123, vw0123, 1, 1, 1, 1)));
167 vo1p0 = wasm_f32x4_add(vo1p0, wasm_f32x4_mul(vi1x3456, wasm_v32x4_shuffle(vw0123, vw0123, 1, 1, 1, 1)));
168
169 vo0p0 = wasm_f32x4_add(vo0p0, wasm_f32x4_mul(vi1x3456, wasm_v32x4_shuffle(vw4567, vw4567, 0, 0, 0, 0)));
170 vo1p0 = wasm_f32x4_add(vo1p0, wasm_f32x4_mul(vi2x3456, wasm_v32x4_shuffle(vw4567, vw4567, 0, 0, 0, 0)));
171
172 vo0p0 = wasm_f32x4_add(vo0p0, wasm_f32x4_mul(vi2x3456, wasm_v32x4_shuffle(vw4567, vw4567, 3, 3, 3, 3)));
173 vo1p0 = wasm_f32x4_add(vo1p0, wasm_f32x4_mul(vi3x3456, wasm_v32x4_shuffle(vw4567, vw4567, 3, 3, 3, 3)));
174
175 const v128_t vi0x5678 = wasm_v32x4_shuffle(vi0x4567, vzero, 1, 2, 3, 4);
176 const v128_t vi1x5678 = wasm_v32x4_shuffle(vi1x4567, vzero, 1, 2, 3, 4);
177 const v128_t vi2x5678 = wasm_v32x4_shuffle(vi2x4567, vzero, 1, 2, 3, 4);
178 const v128_t vi3x5678 = wasm_v32x4_shuffle(vi3x4567, vzero, 1, 2, 3, 4);
179
180 vo0p0 = wasm_f32x4_add(vo0p0, wasm_f32x4_mul(vi0x5678, wasm_v32x4_shuffle(vw0123, vw0123, 3, 3, 3, 3)));
181 vo1p0 = wasm_f32x4_add(vo1p0, wasm_f32x4_mul(vi1x5678, wasm_v32x4_shuffle(vw0123, vw0123, 3, 3, 3, 3)));
182
183 vo0p0 = wasm_f32x4_add(vo0p0, wasm_f32x4_mul(vi1x5678, wasm_v32x4_shuffle(vw4567, vw4567, 2, 2, 2, 2)));
184 vo1p0 = wasm_f32x4_add(vo1p0, wasm_f32x4_mul(vi2x5678, wasm_v32x4_shuffle(vw4567, vw4567, 2, 2, 2, 2)));
185
186 vo0p0 = wasm_f32x4_add(vo0p0, wasm_f32x4_mul(vi2x5678, wasm_v32x4_shuffle(vw89, vw89, 1, 1, 1, 1)));
187 vo1p0 = wasm_f32x4_add(vo1p0, wasm_f32x4_mul(vi3x5678, wasm_v32x4_shuffle(vw89, vw89, 1, 1, 1, 1)));
188
189
190 v128_t vo0 = wasm_f32x4_max(vo0p0, vmin);
191 v128_t vo1 = wasm_f32x4_max(vo1p0, vmin);
192 vo0 = wasm_f32x4_min(vo0, vmax);
193 vo1 = wasm_f32x4_min(vo1, vmax);
194
195 if XNN_LIKELY(w == 4 * sizeof(float)) {
196 wasm_v128_store(o1, vo1); o1 += 4;
197 wasm_v128_store(o0, vo0); o0 += 4;
198 } else {
199 if (w & (2 * sizeof(float))) {
200 *((double*) o1) = wasm_f64x2_extract_lane(vo1, 0); o1 += 2;
201 *((double*) o0) = wasm_f64x2_extract_lane(vo0, 0); o0 += 2;
202
203 vo0 = wasm_v32x4_shuffle(vo0, vo0, 2, 3, 0, 1);
204 vo1 = wasm_v32x4_shuffle(vo1, vo1, 2, 3, 0, 1);
205 }
206 if (w & (1 * sizeof(float))) {
207 *o1 = wasm_f32x4_extract_lane(vo1, 0); o1 += 1;
208 *o0 = wasm_f32x4_extract_lane(vo0, 0); o0 += 1;
209 }
210 }
211 }
212
213 i0 = (const float*) ((uintptr_t) i2 - input_decrement);
214 i1 = (const float*) ((uintptr_t) i3 - input_decrement);
215 i2 = (const float*) ((uintptr_t) i1 + input_width);
216 i3 = (const float*) ((uintptr_t) i2 + input_width);
217
218 o0 = o1;
219 o1 = (float*) ((uintptr_t) o0 + input_width);
220
221 output_height = doz(output_height, 2);
222 } while (output_height != 0);
223 }
224