1 // Auto-generated file. Do not edit!
2 // Template: src/f32-dwconv2d-chw/5x5s2p2-neon.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 <arm_neon.h>
13
14 #include <xnnpack/dwconv.h>
15 #include <xnnpack/math.h>
16
17
xnn_f32_dwconv2d_chw_ukernel_5x5s2p2__neonfma_3x4_acc2(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)])18 void xnn_f32_dwconv2d_chw_ukernel_5x5s2p2__neonfma_3x4_acc2(
19 size_t input_height,
20 size_t input_width,
21 const float* input,
22 const float* weights,
23 const float* zero,
24 float* output,
25 uint32_t padding_top,
26 const union xnn_f32_chw_params params[restrict XNN_MIN_ELEMENTS(1)])
27 {
28 assert(input_height != 0);
29 assert(input_width != 0);
30 assert(input_width % sizeof(float) == 0);
31 assert(padding_top >= 1);
32 assert(padding_top <= 2);
33
34 const uint32x4_t vmask_even = vld1q_u32(params->neon.mask_even);
35 const uint32x4_t vmask_odd = vld1q_u32(params->neon.mask_odd);
36 const float32x4_t vmax = vld1q_dup_f32(¶ms->neon.max);
37 const float32x4_t vmin = vld1q_dup_f32(¶ms->neon.min);
38
39 const float32x4_t vw0123 = vld1q_f32(weights);
40 const float32x4_t vw4567 = vld1q_f32(weights + 4);
41 const float32x4_t vw89AB = vld1q_f32(weights + 8);
42 const float32x4_t vwCDEF = vld1q_f32(weights + 12);
43 const float32x4_t vwGHIJ = vld1q_f32(weights + 16);
44 const float32x4_t vwKLMN = vld1q_f32(weights + 20);
45 const float32x2_t vwOP = vld1_f32(weights + 24);
46
47 const uint32_t padding_top_less_1 = padding_top - 1;
48 const size_t input_decrement = round_up_po2(input_width, 8 * sizeof(float));
49
50 const float* i0 = zero;
51 const float* i1 = (const float*) ((uintptr_t) input - ((-padding_top_less_1) & input_width));
52 const float* i2 = (const float*) ((uintptr_t) i1 + input_width);
53 if XNN_UNPREDICTABLE(padding_top_less_1 != 0) {
54 i1 = zero;
55 }
56 const float* i3 = (const float*) ((uintptr_t) i2 + input_width);
57 const float* i4 = (const float*) ((uintptr_t) i3 + input_width);
58 const float* i5 = (const float*) ((uintptr_t) i4 + input_width);
59 const float* i6 = (const float*) ((uintptr_t) i5 + input_width);
60 const float* i7 = (const float*) ((uintptr_t) i6 + input_width);
61 const float* i8 = (const float*) ((uintptr_t) i7 + input_width);
62
63 const size_t output_width = round_down_po2((input_width + (2 /* padding */ - 3 /* kernel size */ + 2 /* subsampling */) * sizeof(float)) / 2, sizeof(float));
64
65 float* o0 = output;
66 float* o1 = (float*) ((uintptr_t) o0 + output_width);
67 float* o2 = (float*) ((uintptr_t) o1 + output_width);
68
69 size_t padded_input_height = input_height + (padding_top_less_1 + 1) + 2 /* padding bottom */;
70 size_t output_height = (padded_input_height - 5 /* kernel size */ + 2 /* subsampling */) / 2;
71 do {
72 if XNN_UNPREDICTABLE(padded_input_height < 6) {
73 i3 = zero;
74 }
75 if XNN_UNPREDICTABLE(padded_input_height < 7) {
76 i4 = zero;
77 o1 = o0;
78 }
79 if XNN_UNPREDICTABLE(padded_input_height < 8) {
80 i5 = zero;
81 }
82 if XNN_UNPREDICTABLE(padded_input_height < 9) {
83 i6 = zero;
84 o2 = o1;
85 }
86 if XNN_UNPREDICTABLE(padded_input_height < 10) {
87 i7 = zero;
88 }
89 if XNN_UNPREDICTABLE(padded_input_height < 11) {
90 i8 = zero;
91 }
92
93 float32x4_t vi0x0246 = vmovq_n_f32(0.0f);
94 float32x4_t vi1x0246 = vmovq_n_f32(0.0f);
95 float32x4_t vi2x0246 = vmovq_n_f32(0.0f);
96 float32x4_t vi3x0246 = vmovq_n_f32(0.0f);
97 float32x4_t vi4x0246 = vmovq_n_f32(0.0f);
98 float32x4_t vi5x0246 = vmovq_n_f32(0.0f);
99 float32x4_t vi6x0246 = vmovq_n_f32(0.0f);
100 float32x4_t vi7x0246 = vmovq_n_f32(0.0f);
101 float32x4_t vi8x0246 = vmovq_n_f32(0.0f);
102
103 float32x4_t vi0x1357 = vmovq_n_f32(0.0f);
104 float32x4_t vi1x1357 = vmovq_n_f32(0.0f);
105 float32x4_t vi2x1357 = vmovq_n_f32(0.0f);
106 float32x4_t vi3x1357 = vmovq_n_f32(0.0f);
107 float32x4_t vi4x1357 = vmovq_n_f32(0.0f);
108 float32x4_t vi5x1357 = vmovq_n_f32(0.0f);
109 float32x4_t vi6x1357 = vmovq_n_f32(0.0f);
110 float32x4_t vi7x1357 = vmovq_n_f32(0.0f);
111 float32x4_t vi8x1357 = vmovq_n_f32(0.0f);
112
113 float32x4x2_t vi0x8ACE9BDF = vld2q_f32(i0); i0 += 8;
114 float32x4x2_t vi1x8ACE9BDF = vld2q_f32(i1); i1 += 8;
115 float32x4x2_t vi2x8ACE9BDF = vld2q_f32(i2); i2 += 8;
116 float32x4x2_t vi3x8ACE9BDF = vld2q_f32(i3); i3 += 8;
117 float32x4x2_t vi4x8ACE9BDF = vld2q_f32(i4); i4 += 8;
118 float32x4x2_t vi5x8ACE9BDF = vld2q_f32(i5); i5 += 8;
119 float32x4x2_t vi6x8ACE9BDF = vld2q_f32(i6); i6 += 8;
120 float32x4x2_t vi7x8ACE9BDF = vld2q_f32(i7); i7 += 8;
121 float32x4x2_t vi8x8ACE9BDF = vld2q_f32(i8); i8 += 8;
122
123 size_t w = input_width;
124 for (; w > 8 * sizeof(float); w -= 8 * sizeof(float)) {
125 float32x4_t vo0p0 = vdupq_lane_f32(vget_low_f32(vw0123), 0);
126 float32x4_t vo1p0 = vdupq_lane_f32(vget_low_f32(vw0123), 0);
127 float32x4_t vo2p0 = vdupq_lane_f32(vget_low_f32(vw0123), 0);
128
129 float32x4_t vo0p1 = vmulq_lane_f32(vi0x8ACE9BDF.val[0], vget_high_f32(vw0123), 1);
130 float32x4_t vo1p1 = vmulq_lane_f32(vi2x8ACE9BDF.val[0], vget_high_f32(vw0123), 1);
131 float32x4_t vo2p1 = vmulq_lane_f32(vi4x8ACE9BDF.val[0], vget_high_f32(vw0123), 1);
132
133 vo0p0 = vfmaq_lane_f32(vo0p0, vi1x8ACE9BDF.val[0], vget_low_f32(vw89AB), 0);
134 vo1p0 = vfmaq_lane_f32(vo1p0, vi3x8ACE9BDF.val[0], vget_low_f32(vw89AB), 0);
135 vo2p0 = vfmaq_lane_f32(vo2p0, vi5x8ACE9BDF.val[0], vget_low_f32(vw89AB), 0);
136
137 vo0p0 = vfmaq_lane_f32(vo0p0, vi2x8ACE9BDF.val[0], vget_low_f32(vwCDEF), 1);
138 vo1p0 = vfmaq_lane_f32(vo1p0, vi4x8ACE9BDF.val[0], vget_low_f32(vwCDEF), 1);
139 vo2p0 = vfmaq_lane_f32(vo2p0, vi6x8ACE9BDF.val[0], vget_low_f32(vwCDEF), 1);
140
141 vo0p1 = vfmaq_lane_f32(vo0p1, vi3x8ACE9BDF.val[0], vget_high_f32(vwGHIJ), 0);
142 vo1p1 = vfmaq_lane_f32(vo1p1, vi5x8ACE9BDF.val[0], vget_high_f32(vwGHIJ), 0);
143 vo2p1 = vfmaq_lane_f32(vo2p1, vi7x8ACE9BDF.val[0], vget_high_f32(vwGHIJ), 0);
144
145 vo0p0 = vfmaq_lane_f32(vo0p0, vi4x8ACE9BDF.val[0], vget_high_f32(vwKLMN), 1);
146 vo1p0 = vfmaq_lane_f32(vo1p0, vi6x8ACE9BDF.val[0], vget_high_f32(vwKLMN), 1);
147 vo2p0 = vfmaq_lane_f32(vo2p0, vi8x8ACE9BDF.val[0], vget_high_f32(vwKLMN), 1);
148
149 vo0p1 = vfmaq_lane_f32(vo0p1, vi0x8ACE9BDF.val[1], vget_low_f32(vw4567), 0);
150 vo1p1 = vfmaq_lane_f32(vo1p1, vi2x8ACE9BDF.val[1], vget_low_f32(vw4567), 0);
151 vo2p1 = vfmaq_lane_f32(vo2p1, vi4x8ACE9BDF.val[1], vget_low_f32(vw4567), 0);
152
153 vo0p0 = vfmaq_lane_f32(vo0p0, vi1x8ACE9BDF.val[1], vget_low_f32(vw89AB), 1);
154 vo1p0 = vfmaq_lane_f32(vo1p0, vi3x8ACE9BDF.val[1], vget_low_f32(vw89AB), 1);
155 vo2p0 = vfmaq_lane_f32(vo2p0, vi5x8ACE9BDF.val[1], vget_low_f32(vw89AB), 1);
156
157 vo0p1 = vfmaq_lane_f32(vo0p1, vi2x8ACE9BDF.val[1], vget_high_f32(vwCDEF), 0);
158 vo1p1 = vfmaq_lane_f32(vo1p1, vi4x8ACE9BDF.val[1], vget_high_f32(vwCDEF), 0);
159 vo2p1 = vfmaq_lane_f32(vo2p1, vi6x8ACE9BDF.val[1], vget_high_f32(vwCDEF), 0);
160
161 vo0p0 = vfmaq_lane_f32(vo0p0, vi3x8ACE9BDF.val[1], vget_high_f32(vwGHIJ), 1);
162 vo1p0 = vfmaq_lane_f32(vo1p0, vi5x8ACE9BDF.val[1], vget_high_f32(vwGHIJ), 1);
163 vo2p0 = vfmaq_lane_f32(vo2p0, vi7x8ACE9BDF.val[1], vget_high_f32(vwGHIJ), 1);
164
165 vo0p1 = vfmaq_lane_f32(vo0p1, vi4x8ACE9BDF.val[1], vwOP, 0);
166 vo1p1 = vfmaq_lane_f32(vo1p1, vi6x8ACE9BDF.val[1], vwOP, 0);
167 vo2p1 = vfmaq_lane_f32(vo2p1, vi8x8ACE9BDF.val[1], vwOP, 0);
168
169 const float32x4_t vi0x68AC = vextq_f32(vi0x0246, vi0x8ACE9BDF.val[0], 3);
170 vi0x0246 = vi0x8ACE9BDF.val[0];
171 const float32x4_t vi1x68AC = vextq_f32(vi1x0246, vi1x8ACE9BDF.val[0], 3);
172 vi1x0246 = vi1x8ACE9BDF.val[0];
173 const float32x4_t vi2x68AC = vextq_f32(vi2x0246, vi2x8ACE9BDF.val[0], 3);
174 vi2x0246 = vi2x8ACE9BDF.val[0];
175 const float32x4_t vi3x68AC = vextq_f32(vi3x0246, vi3x8ACE9BDF.val[0], 3);
176 vi3x0246 = vi3x8ACE9BDF.val[0];
177 const float32x4_t vi4x68AC = vextq_f32(vi4x0246, vi4x8ACE9BDF.val[0], 3);
178 vi4x0246 = vi4x8ACE9BDF.val[0];
179 const float32x4_t vi5x68AC = vextq_f32(vi5x0246, vi5x8ACE9BDF.val[0], 3);
180 vi5x0246 = vi5x8ACE9BDF.val[0];
181 const float32x4_t vi6x68AC = vextq_f32(vi6x0246, vi6x8ACE9BDF.val[0], 3);
182 vi6x0246 = vi6x8ACE9BDF.val[0];
183 const float32x4_t vi7x68AC = vextq_f32(vi7x0246, vi7x8ACE9BDF.val[0], 3);
184 vi7x0246 = vi7x8ACE9BDF.val[0];
185 const float32x4_t vi8x68AC = vextq_f32(vi8x0246, vi8x8ACE9BDF.val[0], 3);
186 vi8x0246 = vi8x8ACE9BDF.val[0];
187
188 vo0p0 = vfmaq_lane_f32(vo0p0, vi0x68AC, vget_low_f32(vw0123), 1);
189 vo1p0 = vfmaq_lane_f32(vo1p0, vi2x68AC, vget_low_f32(vw0123), 1);
190 vo2p0 = vfmaq_lane_f32(vo2p0, vi4x68AC, vget_low_f32(vw0123), 1);
191
192 vo0p1 = vfmaq_lane_f32(vo0p1, vi1x68AC, vget_high_f32(vw4567), 0);
193 vo1p1 = vfmaq_lane_f32(vo1p1, vi3x68AC, vget_high_f32(vw4567), 0);
194 vo2p1 = vfmaq_lane_f32(vo2p1, vi5x68AC, vget_high_f32(vw4567), 0);
195
196 vo0p0 = vfmaq_lane_f32(vo0p0, vi2x68AC, vget_high_f32(vw89AB), 1);
197 vo1p0 = vfmaq_lane_f32(vo1p0, vi4x68AC, vget_high_f32(vw89AB), 1);
198 vo2p0 = vfmaq_lane_f32(vo2p0, vi6x68AC, vget_high_f32(vw89AB), 1);
199
200 vo0p1 = vfmaq_lane_f32(vo0p1, vi3x68AC, vget_low_f32(vwGHIJ), 0);
201 vo1p1 = vfmaq_lane_f32(vo1p1, vi5x68AC, vget_low_f32(vwGHIJ), 0);
202 vo2p1 = vfmaq_lane_f32(vo2p1, vi7x68AC, vget_low_f32(vwGHIJ), 0);
203
204 vo0p0 = vfmaq_lane_f32(vo0p0, vi4x68AC, vget_low_f32(vwKLMN), 1);
205 vo1p0 = vfmaq_lane_f32(vo1p0, vi6x68AC, vget_low_f32(vwKLMN), 1);
206 vo2p0 = vfmaq_lane_f32(vo2p0, vi8x68AC, vget_low_f32(vwKLMN), 1);
207
208 const float32x4_t vi0x79BD = vextq_f32(vi0x1357, vi0x8ACE9BDF.val[1], 3);
209 vi0x1357 = vi0x8ACE9BDF.val[1];
210 const float32x4_t vi1x79BD = vextq_f32(vi1x1357, vi1x8ACE9BDF.val[1], 3);
211 vi1x1357 = vi1x8ACE9BDF.val[1];
212 const float32x4_t vi2x79BD = vextq_f32(vi2x1357, vi2x8ACE9BDF.val[1], 3);
213 vi2x1357 = vi2x8ACE9BDF.val[1];
214 const float32x4_t vi3x79BD = vextq_f32(vi3x1357, vi3x8ACE9BDF.val[1], 3);
215 vi3x1357 = vi3x8ACE9BDF.val[1];
216 const float32x4_t vi4x79BD = vextq_f32(vi4x1357, vi4x8ACE9BDF.val[1], 3);
217 vi4x1357 = vi4x8ACE9BDF.val[1];
218 const float32x4_t vi5x79BD = vextq_f32(vi5x1357, vi5x8ACE9BDF.val[1], 3);
219 vi5x1357 = vi5x8ACE9BDF.val[1];
220 const float32x4_t vi6x79BD = vextq_f32(vi6x1357, vi6x8ACE9BDF.val[1], 3);
221 vi6x1357 = vi6x8ACE9BDF.val[1];
222 const float32x4_t vi7x79BD = vextq_f32(vi7x1357, vi7x8ACE9BDF.val[1], 3);
223 vi7x1357 = vi7x8ACE9BDF.val[1];
224 const float32x4_t vi8x79BD = vextq_f32(vi8x1357, vi8x8ACE9BDF.val[1], 3);
225 vi8x1357 = vi8x8ACE9BDF.val[1];
226
227 const float32x4x2_t vi0xGIKMHJLN = vld2q_f32(i0); i0 += 8;
228 const float32x4x2_t vi1xGIKMHJLN = vld2q_f32(i1); i1 += 8;
229 const float32x4x2_t vi2xGIKMHJLN = vld2q_f32(i2); i2 += 8;
230 const float32x4x2_t vi3xGIKMHJLN = vld2q_f32(i3); i3 += 8;
231 const float32x4x2_t vi4xGIKMHJLN = vld2q_f32(i4); i4 += 8;
232 const float32x4x2_t vi5xGIKMHJLN = vld2q_f32(i5); i5 += 8;
233 const float32x4x2_t vi6xGIKMHJLN = vld2q_f32(i6); i6 += 8;
234 const float32x4x2_t vi7xGIKMHJLN = vld2q_f32(i7); i7 += 8;
235 const float32x4x2_t vi8xGIKMHJLN = vld2q_f32(i8); i8 += 8;
236
237 vo0p1 = vfmaq_lane_f32(vo0p1, vi0x79BD, vget_high_f32(vw0123), 0);
238 vo1p1 = vfmaq_lane_f32(vo1p1, vi2x79BD, vget_high_f32(vw0123), 0);
239 vo2p1 = vfmaq_lane_f32(vo2p1, vi4x79BD, vget_high_f32(vw0123), 0);
240
241 vo0p0 = vfmaq_lane_f32(vo0p0, vi1x79BD, vget_high_f32(vw4567), 1);
242 vo1p0 = vfmaq_lane_f32(vo1p0, vi3x79BD, vget_high_f32(vw4567), 1);
243 vo2p0 = vfmaq_lane_f32(vo2p0, vi5x79BD, vget_high_f32(vw4567), 1);
244
245 vo0p1 = vfmaq_lane_f32(vo0p1, vi2x79BD, vget_low_f32(vwCDEF), 0);
246 vo1p1 = vfmaq_lane_f32(vo1p1, vi4x79BD, vget_low_f32(vwCDEF), 0);
247 vo2p1 = vfmaq_lane_f32(vo2p1, vi6x79BD, vget_low_f32(vwCDEF), 0);
248
249 vo0p0 = vfmaq_lane_f32(vo0p0, vi3x79BD, vget_low_f32(vwGHIJ), 1);
250 vo1p0 = vfmaq_lane_f32(vo1p0, vi5x79BD, vget_low_f32(vwGHIJ), 1);
251 vo2p0 = vfmaq_lane_f32(vo2p0, vi7x79BD, vget_low_f32(vwGHIJ), 1);
252
253 vo0p1 = vfmaq_lane_f32(vo0p1, vi4x79BD, vget_high_f32(vwKLMN), 0);
254 vo1p1 = vfmaq_lane_f32(vo1p1, vi6x79BD, vget_high_f32(vwKLMN), 0);
255 vo2p1 = vfmaq_lane_f32(vo2p1, vi8x79BD, vget_high_f32(vwKLMN), 0);
256
257 const float32x4_t vi0xACEG = vextq_f32(vi0x8ACE9BDF.val[0], vi0xGIKMHJLN.val[0], 1);
258 vi0x8ACE9BDF = vi0xGIKMHJLN;
259 const float32x4_t vi1xACEG = vextq_f32(vi1x8ACE9BDF.val[0], vi1xGIKMHJLN.val[0], 1);
260 vi1x8ACE9BDF = vi1xGIKMHJLN;
261 const float32x4_t vi2xACEG = vextq_f32(vi2x8ACE9BDF.val[0], vi2xGIKMHJLN.val[0], 1);
262 vi2x8ACE9BDF = vi2xGIKMHJLN;
263 const float32x4_t vi3xACEG = vextq_f32(vi3x8ACE9BDF.val[0], vi3xGIKMHJLN.val[0], 1);
264 vi3x8ACE9BDF = vi3xGIKMHJLN;
265 const float32x4_t vi4xACEG = vextq_f32(vi4x8ACE9BDF.val[0], vi4xGIKMHJLN.val[0], 1);
266 vi4x8ACE9BDF = vi4xGIKMHJLN;
267 const float32x4_t vi5xACEG = vextq_f32(vi5x8ACE9BDF.val[0], vi5xGIKMHJLN.val[0], 1);
268 vi5x8ACE9BDF = vi5xGIKMHJLN;
269 const float32x4_t vi6xACEG = vextq_f32(vi6x8ACE9BDF.val[0], vi6xGIKMHJLN.val[0], 1);
270 vi6x8ACE9BDF = vi6xGIKMHJLN;
271 const float32x4_t vi7xACEG = vextq_f32(vi7x8ACE9BDF.val[0], vi7xGIKMHJLN.val[0], 1);
272 vi7x8ACE9BDF = vi7xGIKMHJLN;
273 const float32x4_t vi8xACEG = vextq_f32(vi8x8ACE9BDF.val[0], vi8xGIKMHJLN.val[0], 1);
274 vi8x8ACE9BDF = vi8xGIKMHJLN;
275
276 vo0p0 = vfmaq_lane_f32(vo0p0, vi0xACEG, vget_low_f32(vw4567), 1);
277 vo1p0 = vfmaq_lane_f32(vo1p0, vi2xACEG, vget_low_f32(vw4567), 1);
278 vo2p0 = vfmaq_lane_f32(vo2p0, vi4xACEG, vget_low_f32(vw4567), 1);
279
280 vo0p1 = vfmaq_lane_f32(vo0p1, vi1xACEG, vget_high_f32(vw89AB), 0);
281 vo1p1 = vfmaq_lane_f32(vo1p1, vi3xACEG, vget_high_f32(vw89AB), 0);
282 vo2p1 = vfmaq_lane_f32(vo2p1, vi5xACEG, vget_high_f32(vw89AB), 0);
283
284 vo0p0 = vfmaq_lane_f32(vo0p0, vi2xACEG, vget_high_f32(vwCDEF), 1);
285 vo1p0 = vfmaq_lane_f32(vo1p0, vi4xACEG, vget_high_f32(vwCDEF), 1);
286 vo2p0 = vfmaq_lane_f32(vo2p0, vi6xACEG, vget_high_f32(vwCDEF), 1);
287
288 vo0p1 = vfmaq_lane_f32(vo0p1, vi3xACEG, vget_low_f32(vwKLMN), 0);
289 vo1p1 = vfmaq_lane_f32(vo1p1, vi5xACEG, vget_low_f32(vwKLMN), 0);
290 vo2p1 = vfmaq_lane_f32(vo2p1, vi7xACEG, vget_low_f32(vwKLMN), 0);
291
292 vo0p0 = vfmaq_lane_f32(vo0p0, vi4xACEG, vwOP, 1);
293 vo1p0 = vfmaq_lane_f32(vo1p0, vi6xACEG, vwOP, 1);
294 vo2p0 = vfmaq_lane_f32(vo2p0, vi8xACEG, vwOP, 1);
295
296 vo0p0 = vaddq_f32(vo0p0, vo0p1);
297 vo1p0 = vaddq_f32(vo1p0, vo1p1);
298 vo2p0 = vaddq_f32(vo2p0, vo2p1);
299
300 float32x4_t vo0 = vmaxq_f32(vo0p0, vmin);
301 float32x4_t vo1 = vmaxq_f32(vo1p0, vmin);
302 float32x4_t vo2 = vmaxq_f32(vo2p0, vmin);
303
304 vo0 = vminq_f32(vo0, vmax);
305 vo1 = vminq_f32(vo1, vmax);
306 vo2 = vminq_f32(vo2, vmax);
307
308 vst1q_f32(o2, vo2); o2 += 4;
309 vst1q_f32(o1, vo1); o1 += 4;
310 vst1q_f32(o0, vo0); o0 += 4;
311 }
312 // Last block has 1-8 pixels to process.
313 assert(w <= 8 * sizeof(float));
314 assert(w >= 1 * sizeof(float));
315 {
316 float32x4_t vo0p0 = vdupq_lane_f32(vget_low_f32(vw0123), 0);
317 float32x4_t vo1p0 = vdupq_lane_f32(vget_low_f32(vw0123), 0);
318 float32x4_t vo2p0 = vdupq_lane_f32(vget_low_f32(vw0123), 0);
319
320 const float32x4_t vi0x8ACE = vreinterpretq_f32_u32(vandq_u32(vmask_even, vreinterpretq_u32_f32(vi0x8ACE9BDF.val[0])));
321 const float32x4_t vi1x8ACE = vreinterpretq_f32_u32(vandq_u32(vmask_even, vreinterpretq_u32_f32(vi1x8ACE9BDF.val[0])));
322 const float32x4_t vi2x8ACE = vreinterpretq_f32_u32(vandq_u32(vmask_even, vreinterpretq_u32_f32(vi2x8ACE9BDF.val[0])));
323 const float32x4_t vi3x8ACE = vreinterpretq_f32_u32(vandq_u32(vmask_even, vreinterpretq_u32_f32(vi3x8ACE9BDF.val[0])));
324 const float32x4_t vi4x8ACE = vreinterpretq_f32_u32(vandq_u32(vmask_even, vreinterpretq_u32_f32(vi4x8ACE9BDF.val[0])));
325 const float32x4_t vi5x8ACE = vreinterpretq_f32_u32(vandq_u32(vmask_even, vreinterpretq_u32_f32(vi5x8ACE9BDF.val[0])));
326 const float32x4_t vi6x8ACE = vreinterpretq_f32_u32(vandq_u32(vmask_even, vreinterpretq_u32_f32(vi6x8ACE9BDF.val[0])));
327 const float32x4_t vi7x8ACE = vreinterpretq_f32_u32(vandq_u32(vmask_even, vreinterpretq_u32_f32(vi7x8ACE9BDF.val[0])));
328 const float32x4_t vi8x8ACE = vreinterpretq_f32_u32(vandq_u32(vmask_even, vreinterpretq_u32_f32(vi8x8ACE9BDF.val[0])));
329
330 const float32x4_t vi0x9BDF = vreinterpretq_f32_u32(vandq_u32(vmask_odd, vreinterpretq_u32_f32(vi0x8ACE9BDF.val[1])));
331 const float32x4_t vi1x9BDF = vreinterpretq_f32_u32(vandq_u32(vmask_odd, vreinterpretq_u32_f32(vi1x8ACE9BDF.val[1])));
332 const float32x4_t vi2x9BDF = vreinterpretq_f32_u32(vandq_u32(vmask_odd, vreinterpretq_u32_f32(vi2x8ACE9BDF.val[1])));
333 const float32x4_t vi3x9BDF = vreinterpretq_f32_u32(vandq_u32(vmask_odd, vreinterpretq_u32_f32(vi3x8ACE9BDF.val[1])));
334 const float32x4_t vi4x9BDF = vreinterpretq_f32_u32(vandq_u32(vmask_odd, vreinterpretq_u32_f32(vi4x8ACE9BDF.val[1])));
335 const float32x4_t vi5x9BDF = vreinterpretq_f32_u32(vandq_u32(vmask_odd, vreinterpretq_u32_f32(vi5x8ACE9BDF.val[1])));
336 const float32x4_t vi6x9BDF = vreinterpretq_f32_u32(vandq_u32(vmask_odd, vreinterpretq_u32_f32(vi6x8ACE9BDF.val[1])));
337 const float32x4_t vi7x9BDF = vreinterpretq_f32_u32(vandq_u32(vmask_odd, vreinterpretq_u32_f32(vi7x8ACE9BDF.val[1])));
338 const float32x4_t vi8x9BDF = vreinterpretq_f32_u32(vandq_u32(vmask_odd, vreinterpretq_u32_f32(vi8x8ACE9BDF.val[1])));
339
340 float32x4_t vo0p1 = vmulq_lane_f32(vi0x8ACE, vget_high_f32(vw0123), 1);
341 float32x4_t vo1p1 = vmulq_lane_f32(vi2x8ACE, vget_high_f32(vw0123), 1);
342 float32x4_t vo2p1 = vmulq_lane_f32(vi4x8ACE, vget_high_f32(vw0123), 1);
343
344 vo0p0 = vfmaq_lane_f32(vo0p0, vi1x8ACE, vget_low_f32(vw89AB), 0);
345 vo1p0 = vfmaq_lane_f32(vo1p0, vi3x8ACE, vget_low_f32(vw89AB), 0);
346 vo2p0 = vfmaq_lane_f32(vo2p0, vi5x8ACE, vget_low_f32(vw89AB), 0);
347
348 vo0p0 = vfmaq_lane_f32(vo0p0, vi2x8ACE, vget_low_f32(vwCDEF), 1);
349 vo1p0 = vfmaq_lane_f32(vo1p0, vi4x8ACE, vget_low_f32(vwCDEF), 1);
350 vo2p0 = vfmaq_lane_f32(vo2p0, vi6x8ACE, vget_low_f32(vwCDEF), 1);
351
352 vo0p1 = vfmaq_lane_f32(vo0p1, vi3x8ACE, vget_high_f32(vwGHIJ), 0);
353 vo1p1 = vfmaq_lane_f32(vo1p1, vi5x8ACE, vget_high_f32(vwGHIJ), 0);
354 vo2p1 = vfmaq_lane_f32(vo2p1, vi7x8ACE, vget_high_f32(vwGHIJ), 0);
355
356 vo0p0 = vfmaq_lane_f32(vo0p0, vi4x8ACE, vget_high_f32(vwKLMN), 1);
357 vo1p0 = vfmaq_lane_f32(vo1p0, vi6x8ACE, vget_high_f32(vwKLMN), 1);
358 vo2p0 = vfmaq_lane_f32(vo2p0, vi8x8ACE, vget_high_f32(vwKLMN), 1);
359
360 vo0p1 = vfmaq_lane_f32(vo0p1, vi0x9BDF, vget_low_f32(vw4567), 0);
361 vo1p1 = vfmaq_lane_f32(vo1p1, vi2x9BDF, vget_low_f32(vw4567), 0);
362 vo2p1 = vfmaq_lane_f32(vo2p1, vi4x9BDF, vget_low_f32(vw4567), 0);
363
364 vo0p0 = vfmaq_lane_f32(vo0p0, vi1x9BDF, vget_low_f32(vw89AB), 1);
365 vo1p0 = vfmaq_lane_f32(vo1p0, vi3x9BDF, vget_low_f32(vw89AB), 1);
366 vo2p0 = vfmaq_lane_f32(vo2p0, vi5x9BDF, vget_low_f32(vw89AB), 1);
367
368 vo0p1 = vfmaq_lane_f32(vo0p1, vi2x9BDF, vget_high_f32(vwCDEF), 0);
369 vo1p1 = vfmaq_lane_f32(vo1p1, vi4x9BDF, vget_high_f32(vwCDEF), 0);
370 vo2p1 = vfmaq_lane_f32(vo2p1, vi6x9BDF, vget_high_f32(vwCDEF), 0);
371
372 vo0p0 = vfmaq_lane_f32(vo0p0, vi3x9BDF, vget_high_f32(vwGHIJ), 1);
373 vo1p0 = vfmaq_lane_f32(vo1p0, vi5x9BDF, vget_high_f32(vwGHIJ), 1);
374 vo2p0 = vfmaq_lane_f32(vo2p0, vi7x9BDF, vget_high_f32(vwGHIJ), 1);
375
376 vo0p1 = vfmaq_lane_f32(vo0p1, vi4x9BDF, vwOP, 0);
377 vo1p1 = vfmaq_lane_f32(vo1p1, vi6x9BDF, vwOP, 0);
378 vo2p1 = vfmaq_lane_f32(vo2p1, vi8x9BDF, vwOP, 0);
379
380 const float32x4_t vi0x68AC = vextq_f32(vi0x0246, vi0x8ACE, 3);
381 const float32x4_t vi1x68AC = vextq_f32(vi1x0246, vi1x8ACE, 3);
382 const float32x4_t vi2x68AC = vextq_f32(vi2x0246, vi2x8ACE, 3);
383 const float32x4_t vi3x68AC = vextq_f32(vi3x0246, vi3x8ACE, 3);
384 const float32x4_t vi4x68AC = vextq_f32(vi4x0246, vi4x8ACE, 3);
385 const float32x4_t vi5x68AC = vextq_f32(vi5x0246, vi5x8ACE, 3);
386 const float32x4_t vi6x68AC = vextq_f32(vi6x0246, vi6x8ACE, 3);
387 const float32x4_t vi7x68AC = vextq_f32(vi7x0246, vi7x8ACE, 3);
388 const float32x4_t vi8x68AC = vextq_f32(vi8x0246, vi8x8ACE, 3);
389
390 vo0p0 = vfmaq_lane_f32(vo0p0, vi0x68AC, vget_low_f32(vw0123), 1);
391 vo1p0 = vfmaq_lane_f32(vo1p0, vi2x68AC, vget_low_f32(vw0123), 1);
392 vo2p0 = vfmaq_lane_f32(vo2p0, vi4x68AC, vget_low_f32(vw0123), 1);
393
394 vo0p1 = vfmaq_lane_f32(vo0p1, vi1x68AC, vget_high_f32(vw4567), 0);
395 vo1p1 = vfmaq_lane_f32(vo1p1, vi3x68AC, vget_high_f32(vw4567), 0);
396 vo2p1 = vfmaq_lane_f32(vo2p1, vi5x68AC, vget_high_f32(vw4567), 0);
397
398 vo0p0 = vfmaq_lane_f32(vo0p0, vi2x68AC, vget_high_f32(vw89AB), 1);
399 vo1p0 = vfmaq_lane_f32(vo1p0, vi4x68AC, vget_high_f32(vw89AB), 1);
400 vo2p0 = vfmaq_lane_f32(vo2p0, vi6x68AC, vget_high_f32(vw89AB), 1);
401
402 vo0p1 = vfmaq_lane_f32(vo0p1, vi3x68AC, vget_low_f32(vwGHIJ), 0);
403 vo1p1 = vfmaq_lane_f32(vo1p1, vi5x68AC, vget_low_f32(vwGHIJ), 0);
404 vo2p1 = vfmaq_lane_f32(vo2p1, vi7x68AC, vget_low_f32(vwGHIJ), 0);
405
406 vo0p0 = vfmaq_lane_f32(vo0p0, vi4x68AC, vget_low_f32(vwKLMN), 1);
407 vo1p0 = vfmaq_lane_f32(vo1p0, vi6x68AC, vget_low_f32(vwKLMN), 1);
408 vo2p0 = vfmaq_lane_f32(vo2p0, vi8x68AC, vget_low_f32(vwKLMN), 1);
409
410 const float32x4_t vi0x79BD = vextq_f32(vi0x1357, vi0x9BDF, 3);
411 const float32x4_t vi1x79BD = vextq_f32(vi1x1357, vi1x9BDF, 3);
412 const float32x4_t vi2x79BD = vextq_f32(vi2x1357, vi2x9BDF, 3);
413 const float32x4_t vi3x79BD = vextq_f32(vi3x1357, vi3x9BDF, 3);
414 const float32x4_t vi4x79BD = vextq_f32(vi4x1357, vi4x9BDF, 3);
415 const float32x4_t vi5x79BD = vextq_f32(vi5x1357, vi5x9BDF, 3);
416 const float32x4_t vi6x79BD = vextq_f32(vi6x1357, vi6x9BDF, 3);
417 const float32x4_t vi7x79BD = vextq_f32(vi7x1357, vi7x9BDF, 3);
418 const float32x4_t vi8x79BD = vextq_f32(vi8x1357, vi8x9BDF, 3);
419
420 vo0p1 = vfmaq_lane_f32(vo0p1, vi0x79BD, vget_high_f32(vw0123), 0);
421 vo1p1 = vfmaq_lane_f32(vo1p1, vi2x79BD, vget_high_f32(vw0123), 0);
422 vo2p1 = vfmaq_lane_f32(vo2p1, vi4x79BD, vget_high_f32(vw0123), 0);
423
424 vo0p0 = vfmaq_lane_f32(vo0p0, vi1x79BD, vget_high_f32(vw4567), 1);
425 vo1p0 = vfmaq_lane_f32(vo1p0, vi3x79BD, vget_high_f32(vw4567), 1);
426 vo2p0 = vfmaq_lane_f32(vo2p0, vi5x79BD, vget_high_f32(vw4567), 1);
427
428 vo0p1 = vfmaq_lane_f32(vo0p1, vi2x79BD, vget_low_f32(vwCDEF), 0);
429 vo1p1 = vfmaq_lane_f32(vo1p1, vi4x79BD, vget_low_f32(vwCDEF), 0);
430 vo2p1 = vfmaq_lane_f32(vo2p1, vi6x79BD, vget_low_f32(vwCDEF), 0);
431
432 vo0p0 = vfmaq_lane_f32(vo0p0, vi3x79BD, vget_low_f32(vwGHIJ), 1);
433 vo1p0 = vfmaq_lane_f32(vo1p0, vi5x79BD, vget_low_f32(vwGHIJ), 1);
434 vo2p0 = vfmaq_lane_f32(vo2p0, vi7x79BD, vget_low_f32(vwGHIJ), 1);
435
436 vo0p1 = vfmaq_lane_f32(vo0p1, vi4x79BD, vget_high_f32(vwKLMN), 0);
437 vo1p1 = vfmaq_lane_f32(vo1p1, vi6x79BD, vget_high_f32(vwKLMN), 0);
438 vo2p1 = vfmaq_lane_f32(vo2p1, vi8x79BD, vget_high_f32(vwKLMN), 0);
439
440 const float32x4_t vzero = vmovq_n_f32(0.0f);
441 const float32x4_t vi0xACEG = vextq_f32(vi0x8ACE, vzero, 1);
442 const float32x4_t vi1xACEG = vextq_f32(vi1x8ACE, vzero, 1);
443 const float32x4_t vi2xACEG = vextq_f32(vi2x8ACE, vzero, 1);
444 const float32x4_t vi3xACEG = vextq_f32(vi3x8ACE, vzero, 1);
445 const float32x4_t vi4xACEG = vextq_f32(vi4x8ACE, vzero, 1);
446 const float32x4_t vi5xACEG = vextq_f32(vi5x8ACE, vzero, 1);
447 const float32x4_t vi6xACEG = vextq_f32(vi6x8ACE, vzero, 1);
448 const float32x4_t vi7xACEG = vextq_f32(vi7x8ACE, vzero, 1);
449 const float32x4_t vi8xACEG = vextq_f32(vi8x8ACE, vzero, 1);
450
451 vo0p0 = vfmaq_lane_f32(vo0p0, vi0xACEG, vget_low_f32(vw4567), 1);
452 vo1p0 = vfmaq_lane_f32(vo1p0, vi2xACEG, vget_low_f32(vw4567), 1);
453 vo2p0 = vfmaq_lane_f32(vo2p0, vi4xACEG, vget_low_f32(vw4567), 1);
454
455 vo0p1 = vfmaq_lane_f32(vo0p1, vi1xACEG, vget_high_f32(vw89AB), 0);
456 vo1p1 = vfmaq_lane_f32(vo1p1, vi3xACEG, vget_high_f32(vw89AB), 0);
457 vo2p1 = vfmaq_lane_f32(vo2p1, vi5xACEG, vget_high_f32(vw89AB), 0);
458
459 vo0p0 = vfmaq_lane_f32(vo0p0, vi2xACEG, vget_high_f32(vwCDEF), 1);
460 vo1p0 = vfmaq_lane_f32(vo1p0, vi4xACEG, vget_high_f32(vwCDEF), 1);
461 vo2p0 = vfmaq_lane_f32(vo2p0, vi6xACEG, vget_high_f32(vwCDEF), 1);
462
463 vo0p1 = vfmaq_lane_f32(vo0p1, vi3xACEG, vget_low_f32(vwKLMN), 0);
464 vo1p1 = vfmaq_lane_f32(vo1p1, vi5xACEG, vget_low_f32(vwKLMN), 0);
465 vo2p1 = vfmaq_lane_f32(vo2p1, vi7xACEG, vget_low_f32(vwKLMN), 0);
466
467 vo0p0 = vfmaq_lane_f32(vo0p0, vi4xACEG, vwOP, 1);
468 vo1p0 = vfmaq_lane_f32(vo1p0, vi6xACEG, vwOP, 1);
469 vo2p0 = vfmaq_lane_f32(vo2p0, vi8xACEG, vwOP, 1);
470
471 vo0p0 = vaddq_f32(vo0p0, vo0p1);
472 vo1p0 = vaddq_f32(vo1p0, vo1p1);
473 vo2p0 = vaddq_f32(vo2p0, vo2p1);
474
475 float32x4_t vo0 = vmaxq_f32(vo0p0, vmin);
476 float32x4_t vo1 = vmaxq_f32(vo1p0, vmin);
477 float32x4_t vo2 = vmaxq_f32(vo2p0, vmin);
478
479 vo0 = vminq_f32(vo0, vmax);
480 vo1 = vminq_f32(vo1, vmax);
481 vo2 = vminq_f32(vo2, vmax);
482
483 size_t w_tmp = (w + 1 * sizeof(float)) / (2 * sizeof(float));
484 if XNN_LIKELY(w_tmp >= 4) {
485 vst1q_f32(o2, vo2); o2 += 4;
486 vst1q_f32(o1, vo1); o1 += 4;
487 vst1q_f32(o0, vo0); o0 += 4;
488 } else {
489 float32x2_t vo0_lo = vget_low_f32(vo0);
490 float32x2_t vo1_lo = vget_low_f32(vo1);
491 float32x2_t vo2_lo = vget_low_f32(vo2);
492 if (w_tmp & 2) {
493 vst1_f32(o2, vo2_lo); o2 += 2;
494 vst1_f32(o1, vo1_lo); o1 += 2;
495 vst1_f32(o0, vo0_lo); o0 += 2;
496
497 vo0_lo = vget_high_f32(vo0);
498 vo1_lo = vget_high_f32(vo1);
499 vo2_lo = vget_high_f32(vo2);
500 }
501 if (w_tmp & 1) {
502 vst1_lane_f32(o2, vo2_lo, 0); o2 += 1;
503 vst1_lane_f32(o1, vo1_lo, 0); o1 += 1;
504 vst1_lane_f32(o0, vo0_lo, 0); o0 += 1;
505 }
506 }
507 }
508
509 i0 = (const float*) ((uintptr_t) i6 - input_decrement);
510 i1 = (const float*) ((uintptr_t) i7 - input_decrement);
511 i2 = (const float*) ((uintptr_t) i8 - input_decrement);
512 i3 = (const float*) ((uintptr_t) i2 + input_width);
513 i4 = (const float*) ((uintptr_t) i3 + input_width);
514 i5 = (const float*) ((uintptr_t) i4 + input_width);
515 i6 = (const float*) ((uintptr_t) i5 + input_width);
516 i7 = (const float*) ((uintptr_t) i6 + input_width);
517 i8 = (const float*) ((uintptr_t) i7 + input_width);
518
519 o0 = o2;
520 o1 = (float*) ((uintptr_t) o0 + output_width);
521 o2 = (float*) ((uintptr_t) o1 + output_width);
522
523 output_height = doz(output_height, 3);
524 padded_input_height = doz(padded_input_height, 6);
525 } while (output_height != 0);
526 }
527