• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Auto-generated file. Do not edit!
2 //   Template: src/f32-dwconv2d-chw/3x3p1-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_3x3p1__neonfma_3x4(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_3x3p1__neonfma_3x4(
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)]) XNN_OOB_READS
27 {
28   assert(input_height != 0);
29   assert(input_width != 0);
30   assert(input_width % sizeof(float) == 0);
31   assert(padding_top == 1);
32 
33   const uint32x4_t vmask = vld1q_u32(params->neon.mask);
34   const float32x4_t vmax = vld1q_dup_f32(&params->neon.max);
35   const float32x4_t vmin = vld1q_dup_f32(&params->neon.min);
36 
37   const float32x4_t vw0123 = vld1q_f32(weights);
38   const float32x4_t vw4567 = vld1q_f32(weights + 4);
39   const float32x2_t vw89 = vld1_f32(weights + 8);
40 
41   const size_t input_decrement = round_up_po2(input_width, 4 * sizeof(float));
42 
43   const float* i0 = zero;
44   const float* i1 = input;
45   const float* i2 = (const float*) ((uintptr_t) i1 + input_width);
46   const float* i3 = (const float*) ((uintptr_t) i2 + input_width);
47   const float* i4 = (const float*) ((uintptr_t) i3 + input_width);
48 
49   float* o0 = output;
50   float* o1 = (float*) ((uintptr_t) o0 + input_width);
51   float* o2 = (float*) ((uintptr_t) o1 + input_width);
52 
53   size_t output_height = input_height;
54   do {
55     if XNN_UNPREDICTABLE(output_height < 2) {
56       i2 = zero;
57       o1 = o0;
58     }
59     if XNN_UNPREDICTABLE(output_height < 3) {
60       i3 = zero;
61       o2 = o1;
62     }
63     if XNN_UNPREDICTABLE(output_height < 4) {
64       i4 = zero;
65     }
66 
67     float32x4_t vi0x0123 = vmovq_n_f32(0.0f);
68     float32x4_t vi1x0123 = vmovq_n_f32(0.0f);
69     float32x4_t vi2x0123 = vmovq_n_f32(0.0f);
70     float32x4_t vi3x0123 = vmovq_n_f32(0.0f);
71     float32x4_t vi4x0123 = vmovq_n_f32(0.0f);
72 
73     float32x4_t vi0x4567 = vld1q_f32(i0); i0 += 4;
74     float32x4_t vi1x4567 = vld1q_f32(i1); i1 += 4;
75     float32x4_t vi2x4567 = vld1q_f32(i2); i2 += 4;
76     float32x4_t vi3x4567 = vld1q_f32(i3); i3 += 4;
77     float32x4_t vi4x4567 = vld1q_f32(i4); i4 += 4;
78 
79     size_t w = input_width;
80     for (; w > 4 * sizeof(float); w -= 4 * sizeof(float)) {
81       float32x4_t vo0p0 = vdupq_lane_f32(vget_low_f32(vw0123), 0);
82       float32x4_t vo1p0 = vdupq_lane_f32(vget_low_f32(vw0123), 0);
83       float32x4_t vo2p0 = vdupq_lane_f32(vget_low_f32(vw0123), 0);
84 
85       const float32x4_t vi0x89AB = vld1q_f32(i0); i0 += 4;
86       const float32x4_t vi1x89AB = vld1q_f32(i1); i1 += 4;
87       const float32x4_t vi2x89AB = vld1q_f32(i2); i2 += 4;
88       const float32x4_t vi3x89AB = vld1q_f32(i3); i3 += 4;
89       const float32x4_t vi4x89AB = vld1q_f32(i4); i4 += 4;
90 
91       vo0p0 = vfmaq_lane_f32(vo0p0, vi0x4567, vget_high_f32(vw0123), 0);
92       vo1p0 = vfmaq_lane_f32(vo1p0, vi1x4567, vget_high_f32(vw0123), 0);
93       vo2p0 = vfmaq_lane_f32(vo2p0, vi2x4567, vget_high_f32(vw0123), 0);
94 
95       vo0p0 = vfmaq_lane_f32(vo0p0, vi1x4567, vget_low_f32(vw4567), 1);
96       vo1p0 = vfmaq_lane_f32(vo1p0, vi2x4567, vget_low_f32(vw4567), 1);
97       vo2p0 = vfmaq_lane_f32(vo2p0, vi3x4567, vget_low_f32(vw4567), 1);
98 
99       vo0p0 = vfmaq_lane_f32(vo0p0, vi2x4567, vw89, 0);
100       vo1p0 = vfmaq_lane_f32(vo1p0, vi3x4567, vw89, 0);
101       vo2p0 = vfmaq_lane_f32(vo2p0, vi4x4567, vw89, 0);
102 
103       const float32x4_t vi0x3456 = vextq_f32(vi0x0123, vi0x4567, 3);
104       const float32x4_t vi1x3456 = vextq_f32(vi1x0123, vi1x4567, 3);
105       const float32x4_t vi2x3456 = vextq_f32(vi2x0123, vi2x4567, 3);
106       const float32x4_t vi3x3456 = vextq_f32(vi3x0123, vi3x4567, 3);
107       const float32x4_t vi4x3456 = vextq_f32(vi4x0123, vi4x4567, 3);
108 
109       vo0p0 = vfmaq_lane_f32(vo0p0, vi0x3456, vget_low_f32(vw0123), 1);
110       vo1p0 = vfmaq_lane_f32(vo1p0, vi1x3456, vget_low_f32(vw0123), 1);
111       vo2p0 = vfmaq_lane_f32(vo2p0, vi2x3456, vget_low_f32(vw0123), 1);
112 
113       vo0p0 = vfmaq_lane_f32(vo0p0, vi1x3456, vget_low_f32(vw4567), 0);
114       vo1p0 = vfmaq_lane_f32(vo1p0, vi2x3456, vget_low_f32(vw4567), 0);
115       vo2p0 = vfmaq_lane_f32(vo2p0, vi3x3456, vget_low_f32(vw4567), 0);
116 
117       vo0p0 = vfmaq_lane_f32(vo0p0, vi2x3456, vget_high_f32(vw4567), 1);
118       vo1p0 = vfmaq_lane_f32(vo1p0, vi3x3456, vget_high_f32(vw4567), 1);
119       vo2p0 = vfmaq_lane_f32(vo2p0, vi4x3456, vget_high_f32(vw4567), 1);
120 
121       vi0x0123 = vi0x4567;
122       vi1x0123 = vi1x4567;
123       vi2x0123 = vi2x4567;
124       vi3x0123 = vi3x4567;
125       vi4x0123 = vi4x4567;
126 
127       const float32x4_t vi0x5678 = vextq_f32(vi0x4567, vi0x89AB, 1);
128       const float32x4_t vi1x5678 = vextq_f32(vi1x4567, vi1x89AB, 1);
129       const float32x4_t vi2x5678 = vextq_f32(vi2x4567, vi2x89AB, 1);
130       const float32x4_t vi3x5678 = vextq_f32(vi3x4567, vi3x89AB, 1);
131       const float32x4_t vi4x5678 = vextq_f32(vi4x4567, vi4x89AB, 1);
132 
133       vo0p0 = vfmaq_lane_f32(vo0p0, vi0x5678, vget_high_f32(vw0123), 1);
134       vo1p0 = vfmaq_lane_f32(vo1p0, vi1x5678, vget_high_f32(vw0123), 1);
135       vo2p0 = vfmaq_lane_f32(vo2p0, vi2x5678, vget_high_f32(vw0123), 1);
136 
137       vo0p0 = vfmaq_lane_f32(vo0p0, vi1x5678, vget_high_f32(vw4567), 0);
138       vo1p0 = vfmaq_lane_f32(vo1p0, vi2x5678, vget_high_f32(vw4567), 0);
139       vo2p0 = vfmaq_lane_f32(vo2p0, vi3x5678, vget_high_f32(vw4567), 0);
140 
141       vo0p0 = vfmaq_lane_f32(vo0p0, vi2x5678, vw89, 1);
142       vo1p0 = vfmaq_lane_f32(vo1p0, vi3x5678, vw89, 1);
143       vo2p0 = vfmaq_lane_f32(vo2p0, vi4x5678, vw89, 1);
144 
145       vi0x4567 = vi0x89AB;
146       vi1x4567 = vi1x89AB;
147       vi2x4567 = vi2x89AB;
148       vi3x4567 = vi3x89AB;
149       vi4x4567 = vi4x89AB;
150 
151 
152       float32x4_t vo0 = vmaxq_f32(vo0p0, vmin);
153       float32x4_t vo1 = vmaxq_f32(vo1p0, vmin);
154       float32x4_t vo2 = vmaxq_f32(vo2p0, vmin);
155 
156       vo0 = vminq_f32(vo0, vmax);
157       vo1 = vminq_f32(vo1, vmax);
158       vo2 = vminq_f32(vo2, vmax);
159 
160       vst1q_f32(o2, vo2); o2 += 4;
161       vst1q_f32(o1, vo1); o1 += 4;
162       vst1q_f32(o0, vo0); o0 += 4;
163     }
164     // Always process the last block of 1..4 pixels.
165     assert(w >= 1 * sizeof(float));
166     assert(w <= 4 * sizeof(float));
167     {
168       float32x4_t vo0p0 = vdupq_lane_f32(vget_low_f32(vw0123), 0);
169       float32x4_t vo1p0 = vdupq_lane_f32(vget_low_f32(vw0123), 0);
170       float32x4_t vo2p0 = vdupq_lane_f32(vget_low_f32(vw0123), 0);
171 
172       vi0x4567 = vreinterpretq_f32_u32(vandq_u32(vmask, vreinterpretq_u32_f32(vi0x4567)));
173       vi1x4567 = vreinterpretq_f32_u32(vandq_u32(vmask, vreinterpretq_u32_f32(vi1x4567)));
174       vi2x4567 = vreinterpretq_f32_u32(vandq_u32(vmask, vreinterpretq_u32_f32(vi2x4567)));
175       vi3x4567 = vreinterpretq_f32_u32(vandq_u32(vmask, vreinterpretq_u32_f32(vi3x4567)));
176       vi4x4567 = vreinterpretq_f32_u32(vandq_u32(vmask, vreinterpretq_u32_f32(vi4x4567)));
177 
178       vo0p0 = vfmaq_lane_f32(vo0p0, vi0x4567, vget_high_f32(vw0123), 0);
179       vo1p0 = vfmaq_lane_f32(vo1p0, vi1x4567, vget_high_f32(vw0123), 0);
180       vo2p0 = vfmaq_lane_f32(vo2p0, vi2x4567, vget_high_f32(vw0123), 0);
181 
182       vo0p0 = vfmaq_lane_f32(vo0p0, vi1x4567, vget_low_f32(vw4567), 1);
183       vo1p0 = vfmaq_lane_f32(vo1p0, vi2x4567, vget_low_f32(vw4567), 1);
184       vo2p0 = vfmaq_lane_f32(vo2p0, vi3x4567, vget_low_f32(vw4567), 1);
185 
186       vo0p0 = vfmaq_lane_f32(vo0p0, vi2x4567, vw89, 0);
187       vo1p0 = vfmaq_lane_f32(vo1p0, vi3x4567, vw89, 0);
188       vo2p0 = vfmaq_lane_f32(vo2p0, vi4x4567, vw89, 0);
189 
190       const float32x4_t vi0x3456 = vextq_f32(vi0x0123, vi0x4567, 3);
191       const float32x4_t vi1x3456 = vextq_f32(vi1x0123, vi1x4567, 3);
192       const float32x4_t vi2x3456 = vextq_f32(vi2x0123, vi2x4567, 3);
193       const float32x4_t vi3x3456 = vextq_f32(vi3x0123, vi3x4567, 3);
194       const float32x4_t vi4x3456 = vextq_f32(vi4x0123, vi4x4567, 3);
195 
196       vo0p0 = vfmaq_lane_f32(vo0p0, vi0x3456, vget_low_f32(vw0123), 1);
197       vo1p0 = vfmaq_lane_f32(vo1p0, vi1x3456, vget_low_f32(vw0123), 1);
198       vo2p0 = vfmaq_lane_f32(vo2p0, vi2x3456, vget_low_f32(vw0123), 1);
199 
200       vo0p0 = vfmaq_lane_f32(vo0p0, vi1x3456, vget_low_f32(vw4567), 0);
201       vo1p0 = vfmaq_lane_f32(vo1p0, vi2x3456, vget_low_f32(vw4567), 0);
202       vo2p0 = vfmaq_lane_f32(vo2p0, vi3x3456, vget_low_f32(vw4567), 0);
203 
204       vo0p0 = vfmaq_lane_f32(vo0p0, vi2x3456, vget_high_f32(vw4567), 1);
205       vo1p0 = vfmaq_lane_f32(vo1p0, vi3x3456, vget_high_f32(vw4567), 1);
206       vo2p0 = vfmaq_lane_f32(vo2p0, vi4x3456, vget_high_f32(vw4567), 1);
207 
208       const float32x4_t vzero = vmovq_n_f32(0.0f);
209       const float32x4_t vi0x5678 = vextq_f32(vi0x4567, vzero, 1);
210       const float32x4_t vi1x5678 = vextq_f32(vi1x4567, vzero, 1);
211       const float32x4_t vi2x5678 = vextq_f32(vi2x4567, vzero, 1);
212       const float32x4_t vi3x5678 = vextq_f32(vi3x4567, vzero, 1);
213       const float32x4_t vi4x5678 = vextq_f32(vi4x4567, vzero, 1);
214 
215       vo0p0 = vfmaq_lane_f32(vo0p0, vi0x5678, vget_high_f32(vw0123), 1);
216       vo1p0 = vfmaq_lane_f32(vo1p0, vi1x5678, vget_high_f32(vw0123), 1);
217       vo2p0 = vfmaq_lane_f32(vo2p0, vi2x5678, vget_high_f32(vw0123), 1);
218 
219       vo0p0 = vfmaq_lane_f32(vo0p0, vi1x5678, vget_high_f32(vw4567), 0);
220       vo1p0 = vfmaq_lane_f32(vo1p0, vi2x5678, vget_high_f32(vw4567), 0);
221       vo2p0 = vfmaq_lane_f32(vo2p0, vi3x5678, vget_high_f32(vw4567), 0);
222 
223       vo0p0 = vfmaq_lane_f32(vo0p0, vi2x5678, vw89, 1);
224       vo1p0 = vfmaq_lane_f32(vo1p0, vi3x5678, vw89, 1);
225       vo2p0 = vfmaq_lane_f32(vo2p0, vi4x5678, vw89, 1);
226 
227 
228       float32x4_t vo0 = vmaxq_f32(vo0p0, vmin);
229       float32x4_t vo1 = vmaxq_f32(vo1p0, vmin);
230       float32x4_t vo2 = vmaxq_f32(vo2p0, vmin);
231 
232       vo0 = vminq_f32(vo0, vmax);
233       vo1 = vminq_f32(vo1, vmax);
234       vo2 = vminq_f32(vo2, vmax);
235 
236       if XNN_LIKELY(w == 4 * sizeof(float)) {
237         vst1q_f32(o2, vo2); o2 += 4;
238         vst1q_f32(o1, vo1); o1 += 4;
239         vst1q_f32(o0, vo0); o0 += 4;
240       } else {
241         float32x2_t vo0_lo = vget_low_f32(vo0);
242         float32x2_t vo1_lo = vget_low_f32(vo1);
243         float32x2_t vo2_lo = vget_low_f32(vo2);
244         if (w & (2 * sizeof(float))) {
245           vst1_f32(o2, vo2_lo); o2 += 2;
246           vst1_f32(o1, vo1_lo); o1 += 2;
247           vst1_f32(o0, vo0_lo); o0 += 2;
248 
249           vo0_lo = vget_high_f32(vo0);
250           vo1_lo = vget_high_f32(vo1);
251           vo2_lo = vget_high_f32(vo2);
252         }
253         if (w & (1 * sizeof(float))) {
254           vst1_lane_f32(o2, vo2_lo, 0); o2 += 1;
255           vst1_lane_f32(o1, vo1_lo, 0); o1 += 1;
256           vst1_lane_f32(o0, vo0_lo, 0); o0 += 1;
257         }
258       }
259     }
260 
261     i0 = (const float*) ((uintptr_t) i3 - input_decrement);
262     i1 = (const float*) ((uintptr_t) i4 - input_decrement);
263     i2 = (const float*) ((uintptr_t) i1 + input_width);
264     i3 = (const float*) ((uintptr_t) i2 + input_width);
265     i4 = (const float*) ((uintptr_t) i3 + input_width);
266 
267     o0 = o2;
268     o1 = (float*) ((uintptr_t) o0 + input_width);
269     o2 = (float*) ((uintptr_t) o1 + input_width);
270 
271     output_height = doz(output_height, 3);
272   } while (output_height != 0);
273 }
274