1 // Auto-generated file. Do not edit!
2 // Template: src/f32-ibilinear-chw/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/ibilinear.h>
15
16
xnn_f32_ibilinear_chw_ukernel__neon_p16(size_t output_pixels,size_t channels,const float ** restrict input,size_t input_offset,const float * restrict weights,float * restrict output,size_t input_increment)17 void xnn_f32_ibilinear_chw_ukernel__neon_p16(
18 size_t output_pixels,
19 size_t channels,
20 const float**restrict input,
21 size_t input_offset,
22 const float*restrict weights,
23 float*restrict output,
24 size_t input_increment) XNN_OOB_READS
25 {
26 assert(output_pixels != 0);
27 assert(channels != 0);
28 assert(input_increment % sizeof(float) == 0);
29
30 do {
31 const float** i = input;
32 const float* w = weights;
33 size_t p = output_pixels;
34 for (; p >= 16; p -= 16) {
35 const float* itl0 = (const float*) ((uintptr_t) i[0] + input_offset);
36 const float* ibl0 = (const float*) ((uintptr_t) i[1] + input_offset);
37 const float* itl1 = (const float*) ((uintptr_t) i[2] + input_offset);
38 const float* ibl1 = (const float*) ((uintptr_t) i[3] + input_offset);
39 const float* itl2 = (const float*) ((uintptr_t) i[4] + input_offset);
40 const float* ibl2 = (const float*) ((uintptr_t) i[5] + input_offset);
41 const float* itl3 = (const float*) ((uintptr_t) i[6] + input_offset);
42 const float* ibl3 = (const float*) ((uintptr_t) i[7] + input_offset);
43 const float* itl4 = (const float*) ((uintptr_t) i[8] + input_offset);
44 const float* ibl4 = (const float*) ((uintptr_t) i[9] + input_offset);
45 const float* itl5 = (const float*) ((uintptr_t) i[10] + input_offset);
46 const float* ibl5 = (const float*) ((uintptr_t) i[11] + input_offset);
47 const float* itl6 = (const float*) ((uintptr_t) i[12] + input_offset);
48 const float* ibl6 = (const float*) ((uintptr_t) i[13] + input_offset);
49 const float* itl7 = (const float*) ((uintptr_t) i[14] + input_offset);
50 const float* ibl7 = (const float*) ((uintptr_t) i[15] + input_offset);
51 const float* itl8 = (const float*) ((uintptr_t) i[16] + input_offset);
52 const float* ibl8 = (const float*) ((uintptr_t) i[17] + input_offset);
53 const float* itl9 = (const float*) ((uintptr_t) i[18] + input_offset);
54 const float* ibl9 = (const float*) ((uintptr_t) i[19] + input_offset);
55 const float* itlA = (const float*) ((uintptr_t) i[20] + input_offset);
56 const float* iblA = (const float*) ((uintptr_t) i[21] + input_offset);
57 const float* itlB = (const float*) ((uintptr_t) i[22] + input_offset);
58 const float* iblB = (const float*) ((uintptr_t) i[23] + input_offset);
59 const float* itlC = (const float*) ((uintptr_t) i[24] + input_offset);
60 const float* iblC = (const float*) ((uintptr_t) i[25] + input_offset);
61 const float* itlD = (const float*) ((uintptr_t) i[26] + input_offset);
62 const float* iblD = (const float*) ((uintptr_t) i[27] + input_offset);
63 const float* itlE = (const float*) ((uintptr_t) i[28] + input_offset);
64 const float* iblE = (const float*) ((uintptr_t) i[29] + input_offset);
65 const float* itlF = (const float*) ((uintptr_t) i[30] + input_offset);
66 const float* iblF = (const float*) ((uintptr_t) i[31] + input_offset);
67 i += 2 * 16;
68
69 const float32x4x2_t vw0123 = vld2q_f32(w + 0);
70 const float32x4x2_t vw4567 = vld2q_f32(w + 8);
71 const float32x4x2_t vw89AB = vld2q_f32(w + 16);
72 const float32x4x2_t vwCDEF = vld2q_f32(w + 24);
73 w += 2 * 16;
74
75 const float32x2_t vtltr0 = vld1_f32(itl0);
76 const float32x2_t vblbr0 = vld1_f32(ibl0);
77 const float32x2_t vtltr1 = vld1_f32(itl1);
78 const float32x2_t vblbr1 = vld1_f32(ibl1);
79 const float32x2_t vtltr2 = vld1_f32(itl2);
80 const float32x2_t vblbr2 = vld1_f32(ibl2);
81 const float32x2_t vtltr3 = vld1_f32(itl3);
82 const float32x2_t vblbr3 = vld1_f32(ibl3);
83 const float32x2_t vtltr4 = vld1_f32(itl4);
84 const float32x2_t vblbr4 = vld1_f32(ibl4);
85 const float32x2_t vtltr5 = vld1_f32(itl5);
86 const float32x2_t vblbr5 = vld1_f32(ibl5);
87 const float32x2_t vtltr6 = vld1_f32(itl6);
88 const float32x2_t vblbr6 = vld1_f32(ibl6);
89 const float32x2_t vtltr7 = vld1_f32(itl7);
90 const float32x2_t vblbr7 = vld1_f32(ibl7);
91 const float32x2_t vtltr8 = vld1_f32(itl8);
92 const float32x2_t vblbr8 = vld1_f32(ibl8);
93 const float32x2_t vtltr9 = vld1_f32(itl9);
94 const float32x2_t vblbr9 = vld1_f32(ibl9);
95 const float32x2_t vtltrA = vld1_f32(itlA);
96 const float32x2_t vblbrA = vld1_f32(iblA);
97 const float32x2_t vtltrB = vld1_f32(itlB);
98 const float32x2_t vblbrB = vld1_f32(iblB);
99 const float32x2_t vtltrC = vld1_f32(itlC);
100 const float32x2_t vblbrC = vld1_f32(iblC);
101 const float32x2_t vtltrD = vld1_f32(itlD);
102 const float32x2_t vblbrD = vld1_f32(iblD);
103 const float32x2_t vtltrE = vld1_f32(itlE);
104 const float32x2_t vblbrE = vld1_f32(iblE);
105 const float32x2_t vtltrF = vld1_f32(itlF);
106 const float32x2_t vblbrF = vld1_f32(iblF);
107
108 const float32x4_t valphah0123 = vw0123.val[0];
109 const float32x4_t valphav0123 = vw0123.val[1];
110 const float32x4_t valphah4567 = vw4567.val[0];
111 const float32x4_t valphav4567 = vw4567.val[1];
112 const float32x4_t valphah89AB = vw89AB.val[0];
113 const float32x4_t valphav89AB = vw89AB.val[1];
114 const float32x4_t valphahCDEF = vwCDEF.val[0];
115 const float32x4_t valphavCDEF = vwCDEF.val[1];
116
117 const float32x4_t vtltr01 = vcombine_f32(vtltr0, vtltr1);
118 const float32x4_t vblbr01 = vcombine_f32(vblbr0, vblbr1);
119 const float32x4_t vtltr23 = vcombine_f32(vtltr2, vtltr3);
120 const float32x4_t vblbr23 = vcombine_f32(vblbr2, vblbr3);
121 const float32x4_t vtltr45 = vcombine_f32(vtltr4, vtltr5);
122 const float32x4_t vblbr45 = vcombine_f32(vblbr4, vblbr5);
123 const float32x4_t vtltr67 = vcombine_f32(vtltr6, vtltr7);
124 const float32x4_t vblbr67 = vcombine_f32(vblbr6, vblbr7);
125 const float32x4_t vtltr89 = vcombine_f32(vtltr8, vtltr9);
126 const float32x4_t vblbr89 = vcombine_f32(vblbr8, vblbr9);
127 const float32x4_t vtltrAB = vcombine_f32(vtltrA, vtltrB);
128 const float32x4_t vblbrAB = vcombine_f32(vblbrA, vblbrB);
129 const float32x4_t vtltrCD = vcombine_f32(vtltrC, vtltrD);
130 const float32x4_t vblbrCD = vcombine_f32(vblbrC, vblbrD);
131 const float32x4_t vtltrEF = vcombine_f32(vtltrE, vtltrF);
132 const float32x4_t vblbrEF = vcombine_f32(vblbrE, vblbrF);
133
134 const float32x4_t vldrd01 = vsubq_f32(vblbr01, vtltr01);
135 const float32x4_t vldrd23 = vsubq_f32(vblbr23, vtltr23);
136 const float32x4_t vldrd45 = vsubq_f32(vblbr45, vtltr45);
137 const float32x4_t vldrd67 = vsubq_f32(vblbr67, vtltr67);
138 const float32x4_t vldrd89 = vsubq_f32(vblbr89, vtltr89);
139 const float32x4_t vldrdAB = vsubq_f32(vblbrAB, vtltrAB);
140 const float32x4_t vldrdCD = vsubq_f32(vblbrCD, vtltrCD);
141 const float32x4_t vldrdEF = vsubq_f32(vblbrEF, vtltrEF);
142
143 const float32x4x2_t vld_t0123 = vuzpq_f32(vldrd01, vldrd23);
144 const float32x4_t vld0123 = vld_t0123.val[0];
145 const float32x4_t vrd0123 = vld_t0123.val[1];
146 const float32x4x2_t vld_t4567 = vuzpq_f32(vldrd45, vldrd67);
147 const float32x4_t vld4567 = vld_t4567.val[0];
148 const float32x4_t vrd4567 = vld_t4567.val[1];
149 const float32x4x2_t vld_t89AB = vuzpq_f32(vldrd89, vldrdAB);
150 const float32x4_t vld89AB = vld_t89AB.val[0];
151 const float32x4_t vrd89AB = vld_t89AB.val[1];
152 const float32x4x2_t vld_tCDEF = vuzpq_f32(vldrdCD, vldrdEF);
153 const float32x4_t vldCDEF = vld_tCDEF.val[0];
154 const float32x4_t vrdCDEF = vld_tCDEF.val[1];
155
156 const float32x4x2_t vtl_t0123 = vuzpq_f32(vtltr01, vtltr23);
157 const float32x4_t vtl0123 = vtl_t0123.val[0];
158 const float32x4_t vtr0123 = vtl_t0123.val[1];
159 const float32x4x2_t vtl_t4567 = vuzpq_f32(vtltr45, vtltr67);
160 const float32x4_t vtl4567 = vtl_t4567.val[0];
161 const float32x4_t vtr4567 = vtl_t4567.val[1];
162 const float32x4x2_t vtl_t89AB = vuzpq_f32(vtltr89, vtltrAB);
163 const float32x4_t vtl89AB = vtl_t89AB.val[0];
164 const float32x4_t vtr89AB = vtl_t89AB.val[1];
165 const float32x4x2_t vtl_tCDEF = vuzpq_f32(vtltrCD, vtltrEF);
166 const float32x4_t vtlCDEF = vtl_tCDEF.val[0];
167 const float32x4_t vtrCDEF = vtl_tCDEF.val[1];
168
169 const float32x4_t vl0123 = vmlaq_f32(vtl0123, vld0123, valphav0123);
170 const float32x4_t vr0123 = vmlaq_f32(vtr0123, vrd0123, valphav0123);
171 const float32x4_t vl4567 = vmlaq_f32(vtl4567, vld4567, valphav4567);
172 const float32x4_t vr4567 = vmlaq_f32(vtr4567, vrd4567, valphav4567);
173 const float32x4_t vl89AB = vmlaq_f32(vtl89AB, vld89AB, valphav89AB);
174 const float32x4_t vr89AB = vmlaq_f32(vtr89AB, vrd89AB, valphav89AB);
175 const float32x4_t vlCDEF = vmlaq_f32(vtlCDEF, vldCDEF, valphavCDEF);
176 const float32x4_t vrCDEF = vmlaq_f32(vtrCDEF, vrdCDEF, valphavCDEF);
177
178 const float32x4_t vd0123 = vsubq_f32(vr0123, vl0123);
179 const float32x4_t vd4567 = vsubq_f32(vr4567, vl4567);
180 const float32x4_t vd89AB = vsubq_f32(vr89AB, vl89AB);
181 const float32x4_t vdCDEF = vsubq_f32(vrCDEF, vlCDEF);
182
183 const float32x4_t vo0123 = vmlaq_f32(vl0123, vd0123, valphah0123);
184 const float32x4_t vo4567 = vmlaq_f32(vl4567, vd4567, valphah4567);
185 const float32x4_t vo89AB = vmlaq_f32(vl89AB, vd89AB, valphah89AB);
186 const float32x4_t voCDEF = vmlaq_f32(vlCDEF, vdCDEF, valphahCDEF);
187
188 vst1q_f32(output + 0, vo0123);
189 vst1q_f32(output + 4, vo4567);
190 vst1q_f32(output + 8, vo89AB);
191 vst1q_f32(output + 12, voCDEF);
192 output += 16;
193 }
194
195 for (; p >= 4; p -= 4) {
196 const float* itl0 = (const float*) ((uintptr_t) i[0] + input_offset);
197 const float* ibl0 = (const float*) ((uintptr_t) i[1] + input_offset);
198 const float* itl1 = (const float*) ((uintptr_t) i[2] + input_offset);
199 const float* ibl1 = (const float*) ((uintptr_t) i[3] + input_offset);
200 const float* itl2 = (const float*) ((uintptr_t) i[4] + input_offset);
201 const float* ibl2 = (const float*) ((uintptr_t) i[5] + input_offset);
202 const float* itl3 = (const float*) ((uintptr_t) i[6] + input_offset);
203 const float* ibl3 = (const float*) ((uintptr_t) i[7] + input_offset);
204 i += 8;
205
206 const float32x4x2_t vw = vld2q_f32(w);
207 w += 8;
208
209 const float32x2_t vtltr0 = vld1_f32(itl0);
210 const float32x2_t vblbr0 = vld1_f32(ibl0);
211 const float32x2_t vtltr1 = vld1_f32(itl1);
212 const float32x2_t vblbr1 = vld1_f32(ibl1);
213 const float32x2_t vtltr2 = vld1_f32(itl2);
214 const float32x2_t vblbr2 = vld1_f32(ibl2);
215 const float32x2_t vtltr3 = vld1_f32(itl3);
216 const float32x2_t vblbr3 = vld1_f32(ibl3);
217
218 const float32x4_t valphah = vw.val[0];
219 const float32x4_t valphav = vw.val[1];
220
221 const float32x4_t vtltr01 = vcombine_f32(vtltr0, vtltr1);
222 const float32x4_t vblbr01 = vcombine_f32(vblbr0, vblbr1);
223 const float32x4_t vtltr23 = vcombine_f32(vtltr2, vtltr3);
224 const float32x4_t vblbr23 = vcombine_f32(vblbr2, vblbr3);
225
226 const float32x4_t vldrd01 = vsubq_f32(vblbr01, vtltr01);
227 const float32x4_t vldrd23 = vsubq_f32(vblbr23, vtltr23);
228
229 const float32x4x2_t vld_t = vuzpq_f32(vldrd01, vldrd23);
230 const float32x4_t vld = vld_t.val[0];
231 const float32x4_t vrd = vld_t.val[1];
232
233 const float32x4x2_t vtl_t = vuzpq_f32(vtltr01, vtltr23);
234 const float32x4_t vtl = vtl_t.val[0];
235 const float32x4_t vtr = vtl_t.val[1];
236
237 const float32x4_t vl = vmlaq_f32(vtl, vld, valphav);
238 const float32x4_t vr = vmlaq_f32(vtr, vrd, valphav);
239
240 const float32x4_t vd = vsubq_f32(vr, vl);
241 const float32x4_t vo = vmlaq_f32(vl, vd, valphah);
242
243 vst1q_f32(output, vo);
244 output += 4;
245 }
246
247 if XNN_UNLIKELY(p != 0) {
248 if (p & 2) {
249 const float32x2x2_t vw = vld2_f32(w);
250 w += 4;
251
252 const float32x2_t valphah = vw.val[0];
253 const float32x2_t valphav = vw.val[1];
254
255 const float* itl0 = (const float*) ((uintptr_t) i[0] + input_offset);
256 const float* ibl0 = (const float*) ((uintptr_t) i[1] + input_offset);
257 const float* itl1 = (const float*) ((uintptr_t) i[2] + input_offset);
258 const float* ibl1 = (const float*) ((uintptr_t) i[3] + input_offset);
259 i += 4;
260
261 const float32x2_t vtltr0 = vld1_f32(itl0);
262 const float32x2_t vblbr0 = vld1_f32(ibl0);
263 const float32x2_t vtltr1 = vld1_f32(itl1);
264 const float32x2_t vblbr1 = vld1_f32(ibl1);
265
266 const float32x2_t vldrd0 = vsub_f32(vblbr0, vtltr0);
267 const float32x2_t vldrd1 = vsub_f32(vblbr1, vtltr1);
268
269 const float32x2x2_t vld_t = vuzp_f32(vldrd0, vldrd1);
270 const float32x2_t vld = vld_t.val[0];
271 const float32x2_t vrd = vld_t.val[1];
272
273 const float32x2x2_t vtl_t = vuzp_f32(vtltr0, vtltr1);
274 const float32x2_t vtl = vtl_t.val[0];
275 const float32x2_t vtr = vtl_t.val[1];
276
277 const float32x2_t vl = vmla_f32(vtl, vld, valphav);
278 const float32x2_t vr = vmla_f32(vtr, vrd, valphav);
279
280 const float32x2_t vd = vsub_f32(vr, vl);
281 const float32x2_t vo = vmla_f32(vl, vd, valphah);
282
283 vst1_f32(output, vo);
284 output += 2;
285 }
286
287 if (p & 1) {
288 // We are computing the following formula:
289 // result = (1 - alpha_h) * (1 - alpha_v) * top_left +
290 // alpha_h * (1 - alpha_v) * top_right +
291 // (1 - alpha_h) * alpha_v * bottom_left +
292 // alpha_h * alpha_v * bottom_right.
293 //
294 // Rearranging gives
295 // result = left + alpha_h * (right - left),
296 // where
297 // left = top_left + alpha_v * (bottom_left - top_left),
298 // right = top_right + alpha_v * (bottom_right - top_right).
299
300 const float alphah = *w;
301 const float32x2_t valphav = vld1_dup_f32(w + 1);
302 w += 2;
303
304 const float* itl = (const float*) ((uintptr_t) i[0] + input_offset);
305 const float* ibl = (const float*) ((uintptr_t) i[1] + input_offset);
306 i += 2;
307
308 const float32x2_t vtltr = vld1_f32(itl);
309 const float32x2_t vblbr = vld1_f32(ibl);
310
311 // Compute at once
312 // left_diff = bottom_left - top_left
313 // right_diff = bottom_right - top_right
314 const float32x2_t vldrd = vsub_f32(vblbr, vtltr);
315 const float32x2_t vlr = vmla_f32(vtltr, vldrd, valphav);
316
317 // Extract them and compute the result.
318 const float l = vget_lane_f32(vlr, 0);
319 const float r = vget_lane_f32(vlr, 1);
320
321 *output++ = l + alphah * (r - l);
322 }
323 }
324
325 input_offset += input_increment;
326 } while (--channels != 0);
327 }
328