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_p4(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_p4(
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_DISABLE_TSAN
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 
35     for (; p >= 4; p -= 4) {
36       const float* itl0 = (const float*) ((uintptr_t) i[0] + input_offset);
37       const float* ibl0 = (const float*) ((uintptr_t) i[1] + input_offset);
38       const float* itl1 = (const float*) ((uintptr_t) i[2] + input_offset);
39       const float* ibl1 = (const float*) ((uintptr_t) i[3] + input_offset);
40       const float* itl2 = (const float*) ((uintptr_t) i[4] + input_offset);
41       const float* ibl2 = (const float*) ((uintptr_t) i[5] + input_offset);
42       const float* itl3 = (const float*) ((uintptr_t) i[6] + input_offset);
43       const float* ibl3 = (const float*) ((uintptr_t) i[7] + input_offset);
44       i += 8;
45 
46       const float32x4x2_t vw = vld2q_f32(w);
47       w += 8;
48 
49       const float32x2_t vtltr0 = vld1_f32(itl0);
50       const float32x2_t vblbr0 = vld1_f32(ibl0);
51       const float32x2_t vtltr1 = vld1_f32(itl1);
52       const float32x2_t vblbr1 = vld1_f32(ibl1);
53       const float32x2_t vtltr2 = vld1_f32(itl2);
54       const float32x2_t vblbr2 = vld1_f32(ibl2);
55       const float32x2_t vtltr3 = vld1_f32(itl3);
56       const float32x2_t vblbr3 = vld1_f32(ibl3);
57 
58       const float32x4_t valphah = vw.val[0];
59       const float32x4_t valphav = vw.val[1];
60 
61       const float32x4_t vtltr01 = vcombine_f32(vtltr0, vtltr1);
62       const float32x4_t vblbr01 = vcombine_f32(vblbr0, vblbr1);
63       const float32x4_t vtltr23 = vcombine_f32(vtltr2, vtltr3);
64       const float32x4_t vblbr23 = vcombine_f32(vblbr2, vblbr3);
65 
66       const float32x4_t vldrd01 = vsubq_f32(vblbr01, vtltr01);
67       const float32x4_t vldrd23 = vsubq_f32(vblbr23, vtltr23);
68 
69       const float32x4x2_t vld_t = vuzpq_f32(vldrd01, vldrd23);
70       const float32x4_t vld = vld_t.val[0];
71       const float32x4_t vrd = vld_t.val[1];
72 
73       const float32x4x2_t vtl_t = vuzpq_f32(vtltr01, vtltr23);
74       const float32x4_t vtl = vtl_t.val[0];
75       const float32x4_t vtr = vtl_t.val[1];
76 
77       const float32x4_t vl = vmlaq_f32(vtl, vld, valphav);
78       const float32x4_t vr = vmlaq_f32(vtr, vrd, valphav);
79 
80       const float32x4_t vd = vsubq_f32(vr, vl);
81       const float32x4_t vo = vmlaq_f32(vl, vd, valphah);
82 
83       vst1q_f32(output, vo);
84       output += 4;
85     }
86 
87     if XNN_UNLIKELY(p != 0) {
88       if (p & 2) {
89         const float32x2x2_t vw = vld2_f32(w);
90         w += 4;
91 
92         const float32x2_t valphah = vw.val[0];
93         const float32x2_t valphav = vw.val[1];
94 
95         const float* itl0 = (const float*) ((uintptr_t) i[0] + input_offset);
96         const float* ibl0 = (const float*) ((uintptr_t) i[1] + input_offset);
97         const float* itl1 = (const float*) ((uintptr_t) i[2] + input_offset);
98         const float* ibl1 = (const float*) ((uintptr_t) i[3] + input_offset);
99         i += 4;
100 
101         const float32x2_t vtltr0 = vld1_f32(itl0);
102         const float32x2_t vblbr0 = vld1_f32(ibl0);
103         const float32x2_t vtltr1 = vld1_f32(itl1);
104         const float32x2_t vblbr1 = vld1_f32(ibl1);
105 
106         const float32x2_t vldrd0 = vsub_f32(vblbr0, vtltr0);
107         const float32x2_t vldrd1 = vsub_f32(vblbr1, vtltr1);
108 
109         const float32x2x2_t vld_t = vuzp_f32(vldrd0, vldrd1);
110         const float32x2_t vld = vld_t.val[0];
111         const float32x2_t vrd = vld_t.val[1];
112 
113         const float32x2x2_t vtl_t = vuzp_f32(vtltr0, vtltr1);
114         const float32x2_t vtl = vtl_t.val[0];
115         const float32x2_t vtr = vtl_t.val[1];
116 
117         const float32x2_t vl = vmla_f32(vtl, vld, valphav);
118         const float32x2_t vr = vmla_f32(vtr, vrd, valphav);
119 
120         const float32x2_t vd = vsub_f32(vr, vl);
121         const float32x2_t vo = vmla_f32(vl, vd, valphah);
122 
123         vst1_f32(output, vo);
124         output += 2;
125       }
126 
127       if (p & 1) {
128         // We are computing the following formula:
129         //   result = (1 - alpha_h) * (1 - alpha_v) * top_left +
130         //                 alpha_h  * (1 - alpha_v) * top_right +
131         //            (1 - alpha_h) *      alpha_v  * bottom_left +
132         //                 alpha_h  *      alpha_v  * bottom_right.
133         //
134         // Rearranging gives
135         //   result =    left + alpha_h * (right        - left),
136         // where
137         //   left =  top_left + alpha_v * (bottom_left  - top_left),
138         //  right = top_right + alpha_v * (bottom_right - top_right).
139 
140         const float alphah = *w;
141         const float32x2_t valphav = vld1_dup_f32(w + 1);
142         w += 2;
143 
144         const float* itl = (const float*) ((uintptr_t) i[0] + input_offset);
145         const float* ibl = (const float*) ((uintptr_t) i[1] + input_offset);
146         i += 2;
147 
148         const float32x2_t vtltr = vld1_f32(itl);
149         const float32x2_t vblbr = vld1_f32(ibl);
150 
151         // Compute at once
152         //    left_diff = bottom_left  - top_left
153         //   right_diff = bottom_right - top_right
154         const float32x2_t vldrd = vsub_f32(vblbr, vtltr);
155         const float32x2_t vlr = vmla_f32(vtltr, vldrd, valphav);
156 
157         // Extract them and compute the result.
158         const float l = vget_lane_f32(vlr, 0);
159         const float r = vget_lane_f32(vlr, 1);
160 
161         *output++ = l + alphah * (r - l);
162       }
163     }
164 
165     input_offset += input_increment;
166   } while (--channels != 0);
167 }
168