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__neon_2x4_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_3x3p1__neon_2x4_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
33 const uint32x4_t vmask = vld1q_u32(params->neon.mask);
34 const float32x4_t vmax = vld1q_dup_f32(¶ms->neon.max);
35 const float32x4_t vmin = vld1q_dup_f32(¶ms->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
48 float* o0 = output;
49 float* o1 = (float*) ((uintptr_t) o0 + input_width);
50
51 size_t output_height = input_height;
52 do {
53 if XNN_UNPREDICTABLE(output_height < 2) {
54 i2 = zero;
55 o1 = o0;
56 }
57 if XNN_UNPREDICTABLE(output_height < 3) {
58 i3 = zero;
59 }
60
61 float32x4_t vi0x0123 = vmovq_n_f32(0.0f);
62 float32x4_t vi1x0123 = vmovq_n_f32(0.0f);
63 float32x4_t vi2x0123 = vmovq_n_f32(0.0f);
64 float32x4_t vi3x0123 = vmovq_n_f32(0.0f);
65
66 float32x4_t vi0x4567 = vld1q_f32(i0); i0 += 4;
67 float32x4_t vi1x4567 = vld1q_f32(i1); i1 += 4;
68 float32x4_t vi2x4567 = vld1q_f32(i2); i2 += 4;
69 float32x4_t vi3x4567 = vld1q_f32(i3); i3 += 4;
70
71 size_t w = input_width;
72 for (; w > 4 * sizeof(float); w -= 4 * sizeof(float)) {
73 float32x4_t vo0p0 = vdupq_lane_f32(vget_low_f32(vw0123), 0);
74 float32x4_t vo1p0 = vdupq_lane_f32(vget_low_f32(vw0123), 0);
75
76 const float32x4_t vi0x89AB = vld1q_f32(i0); i0 += 4;
77 const float32x4_t vi1x89AB = vld1q_f32(i1); i1 += 4;
78 const float32x4_t vi2x89AB = vld1q_f32(i2); i2 += 4;
79 const float32x4_t vi3x89AB = vld1q_f32(i3); i3 += 4;
80
81 vo0p0 = vmlaq_lane_f32(vo0p0, vi0x4567, vget_high_f32(vw0123), 0);
82 vo1p0 = vmlaq_lane_f32(vo1p0, vi1x4567, vget_high_f32(vw0123), 0);
83
84 float32x4_t vo0p1 = vmulq_lane_f32(vi1x4567, vget_low_f32(vw4567), 1);
85 float32x4_t vo1p1 = vmulq_lane_f32(vi2x4567, vget_low_f32(vw4567), 1);
86
87 vo0p0 = vmlaq_lane_f32(vo0p0, vi2x4567, vw89, 0);
88 vo1p0 = vmlaq_lane_f32(vo1p0, vi3x4567, vw89, 0);
89
90 const float32x4_t vi0x3456 = vextq_f32(vi0x0123, vi0x4567, 3);
91 const float32x4_t vi1x3456 = vextq_f32(vi1x0123, vi1x4567, 3);
92 const float32x4_t vi2x3456 = vextq_f32(vi2x0123, vi2x4567, 3);
93 const float32x4_t vi3x3456 = vextq_f32(vi3x0123, vi3x4567, 3);
94
95 vo0p1 = vmlaq_lane_f32(vo0p1, vi0x3456, vget_low_f32(vw0123), 1);
96 vo1p1 = vmlaq_lane_f32(vo1p1, vi1x3456, vget_low_f32(vw0123), 1);
97
98 vo0p0 = vmlaq_lane_f32(vo0p0, vi1x3456, vget_low_f32(vw4567), 0);
99 vo1p0 = vmlaq_lane_f32(vo1p0, vi2x3456, vget_low_f32(vw4567), 0);
100
101 vo0p1 = vmlaq_lane_f32(vo0p1, vi2x3456, vget_high_f32(vw4567), 1);
102 vo1p1 = vmlaq_lane_f32(vo1p1, vi3x3456, vget_high_f32(vw4567), 1);
103
104 vi0x0123 = vi0x4567;
105 vi1x0123 = vi1x4567;
106 vi2x0123 = vi2x4567;
107 vi3x0123 = vi3x4567;
108
109 const float32x4_t vi0x5678 = vextq_f32(vi0x4567, vi0x89AB, 1);
110 const float32x4_t vi1x5678 = vextq_f32(vi1x4567, vi1x89AB, 1);
111 const float32x4_t vi2x5678 = vextq_f32(vi2x4567, vi2x89AB, 1);
112 const float32x4_t vi3x5678 = vextq_f32(vi3x4567, vi3x89AB, 1);
113
114 vo0p0 = vmlaq_lane_f32(vo0p0, vi0x5678, vget_high_f32(vw0123), 1);
115 vo1p0 = vmlaq_lane_f32(vo1p0, vi1x5678, vget_high_f32(vw0123), 1);
116
117 vo0p1 = vmlaq_lane_f32(vo0p1, vi1x5678, vget_high_f32(vw4567), 0);
118 vo1p1 = vmlaq_lane_f32(vo1p1, vi2x5678, vget_high_f32(vw4567), 0);
119
120 vo0p0 = vmlaq_lane_f32(vo0p0, vi2x5678, vw89, 1);
121 vo1p0 = vmlaq_lane_f32(vo1p0, vi3x5678, vw89, 1);
122
123 vi0x4567 = vi0x89AB;
124 vi1x4567 = vi1x89AB;
125 vi2x4567 = vi2x89AB;
126 vi3x4567 = vi3x89AB;
127
128 vo0p0 = vaddq_f32(vo0p0, vo0p1);
129 vo1p0 = vaddq_f32(vo1p0, vo1p1);
130
131 float32x4_t vo0 = vmaxq_f32(vo0p0, vmin);
132 float32x4_t vo1 = vmaxq_f32(vo1p0, vmin);
133
134 vo0 = vminq_f32(vo0, vmax);
135 vo1 = vminq_f32(vo1, vmax);
136
137 vst1q_f32(o1, vo1); o1 += 4;
138 vst1q_f32(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 float32x4_t vo0p0 = vdupq_lane_f32(vget_low_f32(vw0123), 0);
145 float32x4_t vo1p0 = vdupq_lane_f32(vget_low_f32(vw0123), 0);
146
147 vi0x4567 = vreinterpretq_f32_u32(vandq_u32(vmask, vreinterpretq_u32_f32(vi0x4567)));
148 vi1x4567 = vreinterpretq_f32_u32(vandq_u32(vmask, vreinterpretq_u32_f32(vi1x4567)));
149 vi2x4567 = vreinterpretq_f32_u32(vandq_u32(vmask, vreinterpretq_u32_f32(vi2x4567)));
150 vi3x4567 = vreinterpretq_f32_u32(vandq_u32(vmask, vreinterpretq_u32_f32(vi3x4567)));
151
152 vo0p0 = vmlaq_lane_f32(vo0p0, vi0x4567, vget_high_f32(vw0123), 0);
153 vo1p0 = vmlaq_lane_f32(vo1p0, vi1x4567, vget_high_f32(vw0123), 0);
154
155 float32x4_t vo0p1 = vmulq_lane_f32(vi1x4567, vget_low_f32(vw4567), 1);
156 float32x4_t vo1p1 = vmulq_lane_f32(vi2x4567, vget_low_f32(vw4567), 1);
157
158 vo0p0 = vmlaq_lane_f32(vo0p0, vi2x4567, vw89, 0);
159 vo1p0 = vmlaq_lane_f32(vo1p0, vi3x4567, vw89, 0);
160
161 const float32x4_t vi0x3456 = vextq_f32(vi0x0123, vi0x4567, 3);
162 const float32x4_t vi1x3456 = vextq_f32(vi1x0123, vi1x4567, 3);
163 const float32x4_t vi2x3456 = vextq_f32(vi2x0123, vi2x4567, 3);
164 const float32x4_t vi3x3456 = vextq_f32(vi3x0123, vi3x4567, 3);
165
166 vo0p1 = vmlaq_lane_f32(vo0p1, vi0x3456, vget_low_f32(vw0123), 1);
167 vo1p1 = vmlaq_lane_f32(vo1p1, vi1x3456, vget_low_f32(vw0123), 1);
168
169 vo0p0 = vmlaq_lane_f32(vo0p0, vi1x3456, vget_low_f32(vw4567), 0);
170 vo1p0 = vmlaq_lane_f32(vo1p0, vi2x3456, vget_low_f32(vw4567), 0);
171
172 vo0p1 = vmlaq_lane_f32(vo0p1, vi2x3456, vget_high_f32(vw4567), 1);
173 vo1p1 = vmlaq_lane_f32(vo1p1, vi3x3456, vget_high_f32(vw4567), 1);
174
175 const float32x4_t vzero = vmovq_n_f32(0.0f);
176 const float32x4_t vi0x5678 = vextq_f32(vi0x4567, vzero, 1);
177 const float32x4_t vi1x5678 = vextq_f32(vi1x4567, vzero, 1);
178 const float32x4_t vi2x5678 = vextq_f32(vi2x4567, vzero, 1);
179 const float32x4_t vi3x5678 = vextq_f32(vi3x4567, vzero, 1);
180
181 vo0p0 = vmlaq_lane_f32(vo0p0, vi0x5678, vget_high_f32(vw0123), 1);
182 vo1p0 = vmlaq_lane_f32(vo1p0, vi1x5678, vget_high_f32(vw0123), 1);
183
184 vo0p1 = vmlaq_lane_f32(vo0p1, vi1x5678, vget_high_f32(vw4567), 0);
185 vo1p1 = vmlaq_lane_f32(vo1p1, vi2x5678, vget_high_f32(vw4567), 0);
186
187 vo0p0 = vmlaq_lane_f32(vo0p0, vi2x5678, vw89, 1);
188 vo1p0 = vmlaq_lane_f32(vo1p0, vi3x5678, vw89, 1);
189
190 vo0p0 = vaddq_f32(vo0p0, vo0p1);
191 vo1p0 = vaddq_f32(vo1p0, vo1p1);
192
193 float32x4_t vo0 = vmaxq_f32(vo0p0, vmin);
194 float32x4_t vo1 = vmaxq_f32(vo1p0, vmin);
195
196 vo0 = vminq_f32(vo0, vmax);
197 vo1 = vminq_f32(vo1, vmax);
198
199 if XNN_LIKELY(w == 4 * sizeof(float)) {
200 vst1q_f32(o1, vo1); o1 += 4;
201 vst1q_f32(o0, vo0); o0 += 4;
202 } else {
203 float32x2_t vo0_lo = vget_low_f32(vo0);
204 float32x2_t vo1_lo = vget_low_f32(vo1);
205 if (w & (2 * sizeof(float))) {
206 vst1_f32(o1, vo1_lo); o1 += 2;
207 vst1_f32(o0, vo0_lo); o0 += 2;
208
209 vo0_lo = vget_high_f32(vo0);
210 vo1_lo = vget_high_f32(vo1);
211 }
212 if (w & (1 * sizeof(float))) {
213 vst1_lane_f32(o1, vo1_lo, 0); o1 += 1;
214 vst1_lane_f32(o0, vo0_lo, 0); o0 += 1;
215 }
216 }
217 }
218
219 i0 = (const float*) ((uintptr_t) i2 - input_decrement);
220 i1 = (const float*) ((uintptr_t) i3 - input_decrement);
221 i2 = (const float*) ((uintptr_t) i1 + input_width);
222 i3 = (const float*) ((uintptr_t) i2 + input_width);
223
224 o0 = o1;
225 o1 = (float*) ((uintptr_t) o0 + input_width);
226
227 output_height = doz(output_height, 2);
228 } while (output_height != 0);
229 }
230