Debian Codegraph @

src/f32-dwconv2d-chw/gen/f32-dwconv2d-chw-3x3p1-minmax-neon-2x4.c

raw symbols SCIP
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
18 void xnn_f32_dwconv2d_chw_ukernel_3x3p1__neon_2x4(
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_minmax_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 float32x4_t vmax = vld1q_dup_f32(&params->scalar.max);
34 const float32x4_t vmin = vld1q_dup_f32(&params->scalar.min);
35
36 static const int32_t mask_table[7] = {-1, -1, -1, -1, 0, 0, 0};
37 const uint32x4_t vmask = vld1q_u32((const uint32_t*) &mask_table[3 - (((input_width >> 2) - 1) & 3)]);
38
39 const float32x4_t vw0123 = vld1q_f32(weights);
40 const float32x4_t vw4567 = vld1q_f32(weights + 4);
41 const float32x2_t vw89 = vld1_f32(weights + 8);
42
43 const size_t input_decrement = round_up_po2(input_width, 4 * sizeof(float));
44
45 const float* i0 = zero;
46 const float* i1 = input;
47 const float* i2 = (const float*) ((uintptr_t) i1 + input_width);
48 const float* i3 = (const float*) ((uintptr_t) i2 + input_width);
49
50 float* o0 = output;
51 float* o1 = (float*) ((uintptr_t) o0 + 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 }
62
63 float32x4_t vi0x0123 = vmovq_n_f32(0.0f);
64 float32x4_t vi1x0123 = vmovq_n_f32(0.0f);
65 float32x4_t vi2x0123 = vmovq_n_f32(0.0f);
66 float32x4_t vi3x0123 = vmovq_n_f32(0.0f);
67
68 float32x4_t vi0x4567 = vld1q_f32(i0); i0 += 4;
69 float32x4_t vi1x4567 = vld1q_f32(i1); i1 += 4;
70 float32x4_t vi2x4567 = vld1q_f32(i2); i2 += 4;
71 float32x4_t vi3x4567 = vld1q_f32(i3); i3 += 4;
72
73 size_t w = input_width;
74 for (; w > 4 * sizeof(float); w -= 4 * sizeof(float)) {
75 float32x4_t vo0p0 = vdupq_lane_f32(vget_low_f32(vw0123), 0);
76 float32x4_t vo1p0 = vdupq_lane_f32(vget_low_f32(vw0123), 0);
77
78 const float32x4_t vi0x89AB = vld1q_f32(i0); i0 += 4;
79 const float32x4_t vi1x89AB = vld1q_f32(i1); i1 += 4;
80 const float32x4_t vi2x89AB = vld1q_f32(i2); i2 += 4;
81 const float32x4_t vi3x89AB = vld1q_f32(i3); i3 += 4;
82
83 vo0p0 = vmlaq_lane_f32(vo0p0, vi0x4567, vget_high_f32(vw0123), 0);
84 vo1p0 = vmlaq_lane_f32(vo1p0, vi1x4567, vget_high_f32(vw0123), 0);
85
86 vo0p0 = vmlaq_lane_f32(vo0p0, vi1x4567, vget_low_f32(vw4567), 1);
87 vo1p0 = vmlaq_lane_f32(vo1p0, vi2x4567, vget_low_f32(vw4567), 1);
88
89 vo0p0 = vmlaq_lane_f32(vo0p0, vi2x4567, vw89, 0);
90 vo1p0 = vmlaq_lane_f32(vo1p0, vi3x4567, vw89, 0);
91
92 const float32x4_t vi0x3456 = vextq_f32(vi0x0123, vi0x4567, 3);
93 const float32x4_t vi1x3456 = vextq_f32(vi1x0123, vi1x4567, 3);
94 const float32x4_t vi2x3456 = vextq_f32(vi2x0123, vi2x4567, 3);
95 const float32x4_t vi3x3456 = vextq_f32(vi3x0123, vi3x4567, 3);
96
97 vo0p0 = vmlaq_lane_f32(vo0p0, vi0x3456, vget_low_f32(vw0123), 1);
98 vo1p0 = vmlaq_lane_f32(vo1p0, vi1x3456, vget_low_f32(vw0123), 1);
99
100 vo0p0 = vmlaq_lane_f32(vo0p0, vi1x3456, vget_low_f32(vw4567), 0);
101 vo1p0 = vmlaq_lane_f32(vo1p0, vi2x3456, vget_low_f32(vw4567), 0);
102
103 vo0p0 = vmlaq_lane_f32(vo0p0, vi2x3456, vget_high_f32(vw4567), 1);
104 vo1p0 = vmlaq_lane_f32(vo1p0, vi3x3456, vget_high_f32(vw4567), 1);
105
106 vi0x0123 = vi0x4567;
107 vi1x0123 = vi1x4567;
108 vi2x0123 = vi2x4567;
109 vi3x0123 = vi3x4567;
110
111 const float32x4_t vi0x5678 = vextq_f32(vi0x4567, vi0x89AB, 1);
112 const float32x4_t vi1x5678 = vextq_f32(vi1x4567, vi1x89AB, 1);
113 const float32x4_t vi2x5678 = vextq_f32(vi2x4567, vi2x89AB, 1);
114 const float32x4_t vi3x5678 = vextq_f32(vi3x4567, vi3x89AB, 1);
115
116 vo0p0 = vmlaq_lane_f32(vo0p0, vi0x5678, vget_high_f32(vw0123), 1);
117 vo1p0 = vmlaq_lane_f32(vo1p0, vi1x5678, vget_high_f32(vw0123), 1);
118
119 vo0p0 = vmlaq_lane_f32(vo0p0, vi1x5678, vget_high_f32(vw4567), 0);
120 vo1p0 = vmlaq_lane_f32(vo1p0, vi2x5678, vget_high_f32(vw4567), 0);
121
122 vo0p0 = vmlaq_lane_f32(vo0p0, vi2x5678, vw89, 1);
123 vo1p0 = vmlaq_lane_f32(vo1p0, vi3x5678, vw89, 1);
124
125 vi0x4567 = vi0x89AB;
126 vi1x4567 = vi1x89AB;
127 vi2x4567 = vi2x89AB;
128 vi3x4567 = vi3x89AB;
129
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 vo0p0 = vmlaq_lane_f32(vo0p0, vi1x4567, vget_low_f32(vw4567), 1);
156 vo1p0 = vmlaq_lane_f32(vo1p0, 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 vo0p0 = vmlaq_lane_f32(vo0p0, vi0x3456, vget_low_f32(vw0123), 1);
167 vo1p0 = vmlaq_lane_f32(vo1p0, 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 vo0p0 = vmlaq_lane_f32(vo0p0, vi2x3456, vget_high_f32(vw4567), 1);
173 vo1p0 = vmlaq_lane_f32(vo1p0, 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 vo0p0 = vmlaq_lane_f32(vo0p0, vi1x5678, vget_high_f32(vw4567), 0);
185 vo1p0 = vmlaq_lane_f32(vo1p0, 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
191 float32x4_t vo0 = vmaxq_f32(vo0p0, vmin);
192 float32x4_t vo1 = vmaxq_f32(vo1p0, vmin);
193
194 vo0 = vminq_f32(vo0, vmax);
195 vo1 = vminq_f32(vo1, vmax);
196
197 if XNN_LIKELY(w == 4 * sizeof(float)) {
198 vst1q_f32(o1, vo1); o1 += 4;
199 vst1q_f32(o0, vo0); o0 += 4;
200 } else {
201 float32x2_t vo0_lo = vget_low_f32(vo0);
202 float32x2_t vo1_lo = vget_low_f32(vo1);
203 if (w & (2 * sizeof(float))) {
204 vst1_f32(o1, vo1_lo); o1 += 2;
205 vst1_f32(o0, vo0_lo); o0 += 2;
206
207 vo0_lo = vget_high_f32(vo0);
208 vo1_lo = vget_high_f32(vo1);
209 }
210 if (w & (1 * sizeof(float))) {
211 vst1_lane_f32(o1, vo1_lo, 0); o1 += 1;
212 vst1_lane_f32(o0, vo0_lo, 0); o0 += 1;
213 }
214 }
215 }
216
217 i0 = (const float*) ((uintptr_t) i2 - input_decrement);
218 i1 = (const float*) ((uintptr_t) i3 - input_decrement);
219 i2 = (const float*) ((uintptr_t) i1 + input_width);
220 i3 = (const float*) ((uintptr_t) i2 + input_width);
221
222 o0 = o1;
223 o1 = (float*) ((uintptr_t) o0 + input_width);
224
225 output_height = doz(output_height, 2);
226 } while (output_height != 0);
227 }