1 // Auto-generated file. Do not edit!
2 // Template: src/f32-prelu/neon.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2019 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/math.h>
15 #include <xnnpack/prelu.h>
16
17
xnn_f32_prelu_ukernel__neon_4x16(size_t rows,size_t channels,const float * restrict input,size_t input_stride,const float * restrict weights,float * restrict output,size_t output_stride)18 void xnn_f32_prelu_ukernel__neon_4x16(
19 size_t rows,
20 size_t channels,
21 const float*restrict input,
22 size_t input_stride,
23 const float*restrict weights,
24 float*restrict output,
25 size_t output_stride) XNN_DISABLE_TSAN
26 {
27 assert(rows != 0);
28 assert(channels != 0);
29 assert(channels % sizeof(float) == 0);
30
31 const float* i0 = input;
32 float* o0 = output;
33 const float* i1 = (const float*) ((uintptr_t) i0 + input_stride);
34 float* o1 = (float*) ((uintptr_t) o0 + output_stride);
35 if XNN_UNPREDICTABLE(rows < 2) {
36 i1 = i0;
37 o1 = o0;
38 }
39 const float* i2 = (const float*) ((uintptr_t) i1 + input_stride);
40 float* o2 = (float*) ((uintptr_t) o1 + output_stride);
41 if XNN_UNPREDICTABLE(rows <= 2) {
42 i2 = i1;
43 o2 = o1;
44 }
45 const float* i3 = (const float*) ((uintptr_t) i2 + input_stride);
46 float* o3 = (float*) ((uintptr_t) o2 + output_stride);
47 if XNN_UNPREDICTABLE(rows < 4) {
48 i3 = i2;
49 o3 = o2;
50 }
51
52 const size_t input_increment = input_stride * 4 - channels;
53 const size_t output_increment = output_stride * 4 - channels;
54
55 do {
56 const float* w = weights;
57 size_t c = channels;
58 for (; c >= 16 * sizeof(float); c -= 16 * sizeof(float)) {
59 const float32x4_t vw0123 = vld1q_f32(w); w += 4;
60 const float32x4_t vw4567 = vld1q_f32(w); w += 4;
61 const float32x4_t vw89AB = vld1q_f32(w); w += 4;
62 const float32x4_t vwCDEF = vld1q_f32(w); w += 4;
63
64 const float32x4_t vi0x0123 = vld1q_f32(i0); i0 += 4;
65 const float32x4_t vi0x4567 = vld1q_f32(i0); i0 += 4;
66 const float32x4_t vi0x89AB = vld1q_f32(i0); i0 += 4;
67 const float32x4_t vi0xCDEF = vld1q_f32(i0); i0 += 4;
68 const float32x4_t vi1x0123 = vld1q_f32(i1); i1 += 4;
69 const float32x4_t vi1x4567 = vld1q_f32(i1); i1 += 4;
70 const float32x4_t vi1x89AB = vld1q_f32(i1); i1 += 4;
71 const float32x4_t vi1xCDEF = vld1q_f32(i1); i1 += 4;
72 const float32x4_t vi2x0123 = vld1q_f32(i2); i2 += 4;
73 const float32x4_t vi2x4567 = vld1q_f32(i2); i2 += 4;
74 const float32x4_t vi2x89AB = vld1q_f32(i2); i2 += 4;
75 const float32x4_t vi2xCDEF = vld1q_f32(i2); i2 += 4;
76 const float32x4_t vi3x0123 = vld1q_f32(i3); i3 += 4;
77 const float32x4_t vi3x4567 = vld1q_f32(i3); i3 += 4;
78 const float32x4_t vi3x89AB = vld1q_f32(i3); i3 += 4;
79 const float32x4_t vi3xCDEF = vld1q_f32(i3); i3 += 4;
80
81 float32x4_t vacc0x0123 = vmulq_f32(vi0x0123, vw0123);
82 const uint32x4_t vm0x0123 = vcltq_s32(vreinterpretq_s32_f32(vi0x0123), vmovq_n_s32(0));
83 float32x4_t vacc0x4567 = vmulq_f32(vi0x4567, vw4567);
84 const uint32x4_t vm0x4567 = vcltq_s32(vreinterpretq_s32_f32(vi0x4567), vmovq_n_s32(0));
85 float32x4_t vacc0x89AB = vmulq_f32(vi0x89AB, vw89AB);
86 const uint32x4_t vm0x89AB = vcltq_s32(vreinterpretq_s32_f32(vi0x89AB), vmovq_n_s32(0));
87 float32x4_t vacc0xCDEF = vmulq_f32(vi0xCDEF, vwCDEF);
88 const uint32x4_t vm0xCDEF = vcltq_s32(vreinterpretq_s32_f32(vi0xCDEF), vmovq_n_s32(0));
89 float32x4_t vacc1x0123 = vmulq_f32(vi1x0123, vw0123);
90 const uint32x4_t vm1x0123 = vcltq_s32(vreinterpretq_s32_f32(vi1x0123), vmovq_n_s32(0));
91 float32x4_t vacc1x4567 = vmulq_f32(vi1x4567, vw4567);
92 const uint32x4_t vm1x4567 = vcltq_s32(vreinterpretq_s32_f32(vi1x4567), vmovq_n_s32(0));
93 float32x4_t vacc1x89AB = vmulq_f32(vi1x89AB, vw89AB);
94 const uint32x4_t vm1x89AB = vcltq_s32(vreinterpretq_s32_f32(vi1x89AB), vmovq_n_s32(0));
95 float32x4_t vacc1xCDEF = vmulq_f32(vi1xCDEF, vwCDEF);
96 const uint32x4_t vm1xCDEF = vcltq_s32(vreinterpretq_s32_f32(vi1xCDEF), vmovq_n_s32(0));
97 float32x4_t vacc2x0123 = vmulq_f32(vi2x0123, vw0123);
98 const uint32x4_t vm2x0123 = vcltq_s32(vreinterpretq_s32_f32(vi2x0123), vmovq_n_s32(0));
99 float32x4_t vacc2x4567 = vmulq_f32(vi2x4567, vw4567);
100 const uint32x4_t vm2x4567 = vcltq_s32(vreinterpretq_s32_f32(vi2x4567), vmovq_n_s32(0));
101 float32x4_t vacc2x89AB = vmulq_f32(vi2x89AB, vw89AB);
102 const uint32x4_t vm2x89AB = vcltq_s32(vreinterpretq_s32_f32(vi2x89AB), vmovq_n_s32(0));
103 float32x4_t vacc2xCDEF = vmulq_f32(vi2xCDEF, vwCDEF);
104 const uint32x4_t vm2xCDEF = vcltq_s32(vreinterpretq_s32_f32(vi2xCDEF), vmovq_n_s32(0));
105 float32x4_t vacc3x0123 = vmulq_f32(vi3x0123, vw0123);
106 const uint32x4_t vm3x0123 = vcltq_s32(vreinterpretq_s32_f32(vi3x0123), vmovq_n_s32(0));
107 float32x4_t vacc3x4567 = vmulq_f32(vi3x4567, vw4567);
108 const uint32x4_t vm3x4567 = vcltq_s32(vreinterpretq_s32_f32(vi3x4567), vmovq_n_s32(0));
109 float32x4_t vacc3x89AB = vmulq_f32(vi3x89AB, vw89AB);
110 const uint32x4_t vm3x89AB = vcltq_s32(vreinterpretq_s32_f32(vi3x89AB), vmovq_n_s32(0));
111 float32x4_t vacc3xCDEF = vmulq_f32(vi3xCDEF, vwCDEF);
112 const uint32x4_t vm3xCDEF = vcltq_s32(vreinterpretq_s32_f32(vi3xCDEF), vmovq_n_s32(0));
113
114 vacc0x0123 = vbslq_f32(vm0x0123, vacc0x0123, vi0x0123);
115 vacc0x4567 = vbslq_f32(vm0x4567, vacc0x4567, vi0x4567);
116 vacc0x89AB = vbslq_f32(vm0x89AB, vacc0x89AB, vi0x89AB);
117 vacc0xCDEF = vbslq_f32(vm0xCDEF, vacc0xCDEF, vi0xCDEF);
118 vacc1x0123 = vbslq_f32(vm1x0123, vacc1x0123, vi1x0123);
119 vacc1x4567 = vbslq_f32(vm1x4567, vacc1x4567, vi1x4567);
120 vacc1x89AB = vbslq_f32(vm1x89AB, vacc1x89AB, vi1x89AB);
121 vacc1xCDEF = vbslq_f32(vm1xCDEF, vacc1xCDEF, vi1xCDEF);
122 vacc2x0123 = vbslq_f32(vm2x0123, vacc2x0123, vi2x0123);
123 vacc2x4567 = vbslq_f32(vm2x4567, vacc2x4567, vi2x4567);
124 vacc2x89AB = vbslq_f32(vm2x89AB, vacc2x89AB, vi2x89AB);
125 vacc2xCDEF = vbslq_f32(vm2xCDEF, vacc2xCDEF, vi2xCDEF);
126 vacc3x0123 = vbslq_f32(vm3x0123, vacc3x0123, vi3x0123);
127 vacc3x4567 = vbslq_f32(vm3x4567, vacc3x4567, vi3x4567);
128 vacc3x89AB = vbslq_f32(vm3x89AB, vacc3x89AB, vi3x89AB);
129 vacc3xCDEF = vbslq_f32(vm3xCDEF, vacc3xCDEF, vi3xCDEF);
130
131 vst1q_f32(o0, vacc0x0123); o0 += 4;
132 vst1q_f32(o0, vacc0x4567); o0 += 4;
133 vst1q_f32(o0, vacc0x89AB); o0 += 4;
134 vst1q_f32(o0, vacc0xCDEF); o0 += 4;
135 vst1q_f32(o1, vacc1x0123); o1 += 4;
136 vst1q_f32(o1, vacc1x4567); o1 += 4;
137 vst1q_f32(o1, vacc1x89AB); o1 += 4;
138 vst1q_f32(o1, vacc1xCDEF); o1 += 4;
139 vst1q_f32(o2, vacc2x0123); o2 += 4;
140 vst1q_f32(o2, vacc2x4567); o2 += 4;
141 vst1q_f32(o2, vacc2x89AB); o2 += 4;
142 vst1q_f32(o2, vacc2xCDEF); o2 += 4;
143 vst1q_f32(o3, vacc3x0123); o3 += 4;
144 vst1q_f32(o3, vacc3x4567); o3 += 4;
145 vst1q_f32(o3, vacc3x89AB); o3 += 4;
146 vst1q_f32(o3, vacc3xCDEF); o3 += 4;
147 }
148 for (; c >= 4 * sizeof(float); c -= 4 * sizeof(float)) {
149 const float32x4_t vw0123 = vld1q_f32(w); w += 4;
150
151 const float32x4_t vi0x0123 = vld1q_f32(i0);
152 i0 += 4;
153 const float32x4_t vi1x0123 = vld1q_f32(i1);
154 i1 += 4;
155 const float32x4_t vi2x0123 = vld1q_f32(i2);
156 i2 += 4;
157 const float32x4_t vi3x0123 = vld1q_f32(i3);
158 i3 += 4;
159
160 float32x4_t vacc0x0123 = vmulq_f32(vi0x0123, vw0123);
161 const uint32x4_t vm0x0123 = vcltq_s32(vreinterpretq_s32_f32(vi0x0123), vmovq_n_s32(0));
162 float32x4_t vacc1x0123 = vmulq_f32(vi1x0123, vw0123);
163 const uint32x4_t vm1x0123 = vcltq_s32(vreinterpretq_s32_f32(vi1x0123), vmovq_n_s32(0));
164 float32x4_t vacc2x0123 = vmulq_f32(vi2x0123, vw0123);
165 const uint32x4_t vm2x0123 = vcltq_s32(vreinterpretq_s32_f32(vi2x0123), vmovq_n_s32(0));
166 float32x4_t vacc3x0123 = vmulq_f32(vi3x0123, vw0123);
167 const uint32x4_t vm3x0123 = vcltq_s32(vreinterpretq_s32_f32(vi3x0123), vmovq_n_s32(0));
168
169 vacc0x0123 = vbslq_f32(vm0x0123, vacc0x0123, vi0x0123);
170 vacc1x0123 = vbslq_f32(vm1x0123, vacc1x0123, vi1x0123);
171 vacc2x0123 = vbslq_f32(vm2x0123, vacc2x0123, vi2x0123);
172 vacc3x0123 = vbslq_f32(vm3x0123, vacc3x0123, vi3x0123);
173
174 vst1q_f32(o0, vacc0x0123); o0 += 4;
175 vst1q_f32(o1, vacc1x0123); o1 += 4;
176 vst1q_f32(o2, vacc2x0123); o2 += 4;
177 vst1q_f32(o3, vacc3x0123); o3 += 4;
178 }
179 if XNN_UNLIKELY(c != 0) {
180 const float32x4_t vw0123 = vld1q_f32(w); w += 4;
181
182 const float32x4_t vi0x0123 = vld1q_f32(i0);
183 i0 = (const float*) ((uintptr_t) i0 + c);
184 const float32x4_t vi1x0123 = vld1q_f32(i1);
185 i1 = (const float*) ((uintptr_t) i1 + c);
186 const float32x4_t vi2x0123 = vld1q_f32(i2);
187 i2 = (const float*) ((uintptr_t) i2 + c);
188 const float32x4_t vi3x0123 = vld1q_f32(i3);
189 i3 = (const float*) ((uintptr_t) i3 + c);
190
191 float32x4_t vacc0x0123 = vmulq_f32(vi0x0123, vw0123);
192 const uint32x4_t vm0x0123 = vcltq_s32(vreinterpretq_s32_f32(vi0x0123), vmovq_n_s32(0));
193 float32x4_t vacc1x0123 = vmulq_f32(vi1x0123, vw0123);
194 const uint32x4_t vm1x0123 = vcltq_s32(vreinterpretq_s32_f32(vi1x0123), vmovq_n_s32(0));
195 float32x4_t vacc2x0123 = vmulq_f32(vi2x0123, vw0123);
196 const uint32x4_t vm2x0123 = vcltq_s32(vreinterpretq_s32_f32(vi2x0123), vmovq_n_s32(0));
197 float32x4_t vacc3x0123 = vmulq_f32(vi3x0123, vw0123);
198 const uint32x4_t vm3x0123 = vcltq_s32(vreinterpretq_s32_f32(vi3x0123), vmovq_n_s32(0));
199
200 vacc0x0123 = vbslq_f32(vm0x0123, vacc0x0123, vi0x0123);
201 vacc1x0123 = vbslq_f32(vm1x0123, vacc1x0123, vi1x0123);
202 vacc2x0123 = vbslq_f32(vm2x0123, vacc2x0123, vi2x0123);
203 vacc3x0123 = vbslq_f32(vm3x0123, vacc3x0123, vi3x0123);
204
205 float32x2_t vacc0x01 = vget_low_f32(vacc0x0123);
206 float32x2_t vacc1x01 = vget_low_f32(vacc1x0123);
207 float32x2_t vacc2x01 = vget_low_f32(vacc2x0123);
208 float32x2_t vacc3x01 = vget_low_f32(vacc3x0123);
209 if (c & (2 * sizeof(float))) {
210 vst1_f32(o0, vacc0x01); o0 += 2;
211 vst1_f32(o1, vacc1x01); o1 += 2;
212 vst1_f32(o2, vacc2x01); o2 += 2;
213 vst1_f32(o3, vacc3x01); o3 += 2;
214
215 vacc0x01 = vget_high_f32(vacc0x0123);
216 vacc1x01 = vget_high_f32(vacc1x0123);
217 vacc2x01 = vget_high_f32(vacc2x0123);
218 vacc3x01 = vget_high_f32(vacc3x0123);
219 }
220 if (c & (1 * sizeof(float))) {
221 vst1_lane_f32(o0, vacc0x01, 0); o0 += 1;
222 vst1_lane_f32(o1, vacc1x01, 0); o1 += 1;
223 vst1_lane_f32(o2, vacc2x01, 0); o2 += 1;
224 vst1_lane_f32(o3, vacc3x01, 0); o3 += 1;
225 }
226 }
227 i0 = (const float*) ((uintptr_t) i0 + input_increment);
228 o0 = (float*) ((uintptr_t) o0 + output_increment);
229 i1 = (const float*) ((uintptr_t) i1 + input_increment);
230 o1 = (float*) ((uintptr_t) o1 + output_increment);
231 if XNN_UNPREDICTABLE(rows < 6) {
232 i1 = i0;
233 o1 = o0;
234 }
235 i2 = (const float*) ((uintptr_t) i2 + input_increment);
236 o2 = (float*) ((uintptr_t) o2 + output_increment);
237 if XNN_UNPREDICTABLE(rows <= 6) {
238 i2 = i1;
239 o2 = o1;
240 }
241 i3 = (const float*) ((uintptr_t) i3 + input_increment);
242 o3 = (float*) ((uintptr_t) o3 + output_increment);
243 if XNN_UNPREDICTABLE(rows < 8) {
244 i3 = i2;
245 o3 = o2;
246 }
247 rows = doz(rows, 4);
248 } while (rows != 0);
249 }
250