Debian Codegraph @

src/f32-dwconv2d-chw/gen/f32-dwconv2d-chw-3x3p1-minmax-neon-1x4.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_1x4(
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
49 float* o0 = output;
50
51 size_t output_height = input_height;
52 do {
53 if XNN_UNPREDICTABLE(output_height < 2) {
54 i2 = zero;
55 }
56
57 float32x4_t vi0x0123 = vmovq_n_f32(0.0f);
58 float32x4_t vi1x0123 = vmovq_n_f32(0.0f);
59 float32x4_t vi2x0123 = vmovq_n_f32(0.0f);
60
61 float32x4_t vi0x4567 = vld1q_f32(i0); i0 += 4;
62 float32x4_t vi1x4567 = vld1q_f32(i1); i1 += 4;
63 float32x4_t vi2x4567 = vld1q_f32(i2); i2 += 4;
64
65 size_t w = input_width;
66 for (; w > 4 * sizeof(float); w -= 4 * sizeof(float)) {
67 float32x4_t vo0p0 = vdupq_lane_f32(vget_low_f32(vw0123), 0);
68
69 const float32x4_t vi0x89AB = vld1q_f32(i0); i0 += 4;
70 const float32x4_t vi1x89AB = vld1q_f32(i1); i1 += 4;
71 const float32x4_t vi2x89AB = vld1q_f32(i2); i2 += 4;
72
73 vo0p0 = vmlaq_lane_f32(vo0p0, vi0x4567, vget_high_f32(vw0123), 0);
74
75 vo0p0 = vmlaq_lane_f32(vo0p0, vi1x4567, vget_low_f32(vw4567), 1);
76
77 vo0p0 = vmlaq_lane_f32(vo0p0, vi2x4567, vw89, 0);
78
79 const float32x4_t vi0x3456 = vextq_f32(vi0x0123, vi0x4567, 3);
80 const float32x4_t vi1x3456 = vextq_f32(vi1x0123, vi1x4567, 3);
81 const float32x4_t vi2x3456 = vextq_f32(vi2x0123, vi2x4567, 3);
82
83 vo0p0 = vmlaq_lane_f32(vo0p0, vi0x3456, vget_low_f32(vw0123), 1);
84
85 vo0p0 = vmlaq_lane_f32(vo0p0, vi1x3456, vget_low_f32(vw4567), 0);
86
87 vo0p0 = vmlaq_lane_f32(vo0p0, vi2x3456, vget_high_f32(vw4567), 1);
88
89 vi0x0123 = vi0x4567;
90 vi1x0123 = vi1x4567;
91 vi2x0123 = vi2x4567;
92
93 const float32x4_t vi0x5678 = vextq_f32(vi0x4567, vi0x89AB, 1);
94 const float32x4_t vi1x5678 = vextq_f32(vi1x4567, vi1x89AB, 1);
95 const float32x4_t vi2x5678 = vextq_f32(vi2x4567, vi2x89AB, 1);
96
97 vo0p0 = vmlaq_lane_f32(vo0p0, vi0x5678, vget_high_f32(vw0123), 1);
98
99 vo0p0 = vmlaq_lane_f32(vo0p0, vi1x5678, vget_high_f32(vw4567), 0);
100
101 vo0p0 = vmlaq_lane_f32(vo0p0, vi2x5678, vw89, 1);
102
103 vi0x4567 = vi0x89AB;
104 vi1x4567 = vi1x89AB;
105 vi2x4567 = vi2x89AB;
106
107
108 float32x4_t vo0 = vmaxq_f32(vo0p0, vmin);
109
110 vo0 = vminq_f32(vo0, vmax);
111
112 vst1q_f32(o0, vo0); o0 += 4;
113 }
114 // Always process the last block of 1..4 pixels.
115 assert(w >= 1 * sizeof(float));
116 assert(w <= 4 * sizeof(float));
117 {
118 float32x4_t vo0p0 = vdupq_lane_f32(vget_low_f32(vw0123), 0);
119
120 vi0x4567 = vreinterpretq_f32_u32(vandq_u32(vmask, vreinterpretq_u32_f32(vi0x4567)));
121 vi1x4567 = vreinterpretq_f32_u32(vandq_u32(vmask, vreinterpretq_u32_f32(vi1x4567)));
122 vi2x4567 = vreinterpretq_f32_u32(vandq_u32(vmask, vreinterpretq_u32_f32(vi2x4567)));
123
124 vo0p0 = vmlaq_lane_f32(vo0p0, vi0x4567, vget_high_f32(vw0123), 0);
125
126 vo0p0 = vmlaq_lane_f32(vo0p0, vi1x4567, vget_low_f32(vw4567), 1);
127
128 vo0p0 = vmlaq_lane_f32(vo0p0, vi2x4567, vw89, 0);
129
130 const float32x4_t vi0x3456 = vextq_f32(vi0x0123, vi0x4567, 3);
131 const float32x4_t vi1x3456 = vextq_f32(vi1x0123, vi1x4567, 3);
132 const float32x4_t vi2x3456 = vextq_f32(vi2x0123, vi2x4567, 3);
133
134 vo0p0 = vmlaq_lane_f32(vo0p0, vi0x3456, vget_low_f32(vw0123), 1);
135
136 vo0p0 = vmlaq_lane_f32(vo0p0, vi1x3456, vget_low_f32(vw4567), 0);
137
138 vo0p0 = vmlaq_lane_f32(vo0p0, vi2x3456, vget_high_f32(vw4567), 1);
139
140 const float32x4_t vzero = vmovq_n_f32(0.0f);
141 const float32x4_t vi0x5678 = vextq_f32(vi0x4567, vzero, 1);
142 const float32x4_t vi1x5678 = vextq_f32(vi1x4567, vzero, 1);
143 const float32x4_t vi2x5678 = vextq_f32(vi2x4567, vzero, 1);
144
145 vo0p0 = vmlaq_lane_f32(vo0p0, vi0x5678, vget_high_f32(vw0123), 1);
146
147 vo0p0 = vmlaq_lane_f32(vo0p0, vi1x5678, vget_high_f32(vw4567), 0);
148
149 vo0p0 = vmlaq_lane_f32(vo0p0, vi2x5678, vw89, 1);
150
151
152 float32x4_t vo0 = vmaxq_f32(vo0p0, vmin);
153
154 vo0 = vminq_f32(vo0, vmax);
155
156 if XNN_LIKELY(w == 4 * sizeof(float)) {
157 vst1q_f32(o0, vo0); o0 += 4;
158 } else {
159 float32x2_t vo0_lo = vget_low_f32(vo0);
160 if (w & (2 * sizeof(float))) {
161 vst1_f32(o0, vo0_lo); o0 += 2;
162
163 vo0_lo = vget_high_f32(vo0);
164 }
165 if (w & (1 * sizeof(float))) {
166 vst1_lane_f32(o0, vo0_lo, 0); o0 += 1;
167 }
168 }
169 }
170
171 i0 = (const float*) ((uintptr_t) i1 - input_decrement);
172 i1 = (const float*) ((uintptr_t) i2 - input_decrement);
173 i2 = (const float*) ((uintptr_t) i1 + input_width);
174
175
176 } while (--output_height != 0);
177 }