• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_4x8(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_4x8(
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 >= 8 * sizeof(float); c -= 8 * sizeof(float)) {
59       const float32x4_t vw0123 = vld1q_f32(w); w += 4;
60       const float32x4_t vw4567 = vld1q_f32(w); w += 4;
61 
62       const float32x4_t vi0x0123 = vld1q_f32(i0); i0 += 4;
63       const float32x4_t vi0x4567 = vld1q_f32(i0); i0 += 4;
64       const float32x4_t vi1x0123 = vld1q_f32(i1); i1 += 4;
65       const float32x4_t vi1x4567 = vld1q_f32(i1); i1 += 4;
66       const float32x4_t vi2x0123 = vld1q_f32(i2); i2 += 4;
67       const float32x4_t vi2x4567 = vld1q_f32(i2); i2 += 4;
68       const float32x4_t vi3x0123 = vld1q_f32(i3); i3 += 4;
69       const float32x4_t vi3x4567 = vld1q_f32(i3); i3 += 4;
70 
71       float32x4_t vacc0x0123 = vmulq_f32(vi0x0123, vw0123);
72       const uint32x4_t vm0x0123 = vcltq_s32(vreinterpretq_s32_f32(vi0x0123), vmovq_n_s32(0));
73       float32x4_t vacc0x4567 = vmulq_f32(vi0x4567, vw4567);
74       const uint32x4_t vm0x4567 = vcltq_s32(vreinterpretq_s32_f32(vi0x4567), vmovq_n_s32(0));
75       float32x4_t vacc1x0123 = vmulq_f32(vi1x0123, vw0123);
76       const uint32x4_t vm1x0123 = vcltq_s32(vreinterpretq_s32_f32(vi1x0123), vmovq_n_s32(0));
77       float32x4_t vacc1x4567 = vmulq_f32(vi1x4567, vw4567);
78       const uint32x4_t vm1x4567 = vcltq_s32(vreinterpretq_s32_f32(vi1x4567), vmovq_n_s32(0));
79       float32x4_t vacc2x0123 = vmulq_f32(vi2x0123, vw0123);
80       const uint32x4_t vm2x0123 = vcltq_s32(vreinterpretq_s32_f32(vi2x0123), vmovq_n_s32(0));
81       float32x4_t vacc2x4567 = vmulq_f32(vi2x4567, vw4567);
82       const uint32x4_t vm2x4567 = vcltq_s32(vreinterpretq_s32_f32(vi2x4567), vmovq_n_s32(0));
83       float32x4_t vacc3x0123 = vmulq_f32(vi3x0123, vw0123);
84       const uint32x4_t vm3x0123 = vcltq_s32(vreinterpretq_s32_f32(vi3x0123), vmovq_n_s32(0));
85       float32x4_t vacc3x4567 = vmulq_f32(vi3x4567, vw4567);
86       const uint32x4_t vm3x4567 = vcltq_s32(vreinterpretq_s32_f32(vi3x4567), vmovq_n_s32(0));
87 
88       vacc0x0123 = vbslq_f32(vm0x0123, vacc0x0123, vi0x0123);
89       vacc0x4567 = vbslq_f32(vm0x4567, vacc0x4567, vi0x4567);
90       vacc1x0123 = vbslq_f32(vm1x0123, vacc1x0123, vi1x0123);
91       vacc1x4567 = vbslq_f32(vm1x4567, vacc1x4567, vi1x4567);
92       vacc2x0123 = vbslq_f32(vm2x0123, vacc2x0123, vi2x0123);
93       vacc2x4567 = vbslq_f32(vm2x4567, vacc2x4567, vi2x4567);
94       vacc3x0123 = vbslq_f32(vm3x0123, vacc3x0123, vi3x0123);
95       vacc3x4567 = vbslq_f32(vm3x4567, vacc3x4567, vi3x4567);
96 
97       vst1q_f32(o0, vacc0x0123); o0 += 4;
98       vst1q_f32(o0, vacc0x4567); o0 += 4;
99       vst1q_f32(o1, vacc1x0123); o1 += 4;
100       vst1q_f32(o1, vacc1x4567); o1 += 4;
101       vst1q_f32(o2, vacc2x0123); o2 += 4;
102       vst1q_f32(o2, vacc2x4567); o2 += 4;
103       vst1q_f32(o3, vacc3x0123); o3 += 4;
104       vst1q_f32(o3, vacc3x4567); o3 += 4;
105     }
106     for (; c >= 4 * sizeof(float); c -= 4 * sizeof(float)) {
107       const float32x4_t vw0123 = vld1q_f32(w); w += 4;
108 
109       const float32x4_t vi0x0123 = vld1q_f32(i0);
110       i0 += 4;
111       const float32x4_t vi1x0123 = vld1q_f32(i1);
112       i1 += 4;
113       const float32x4_t vi2x0123 = vld1q_f32(i2);
114       i2 += 4;
115       const float32x4_t vi3x0123 = vld1q_f32(i3);
116       i3 += 4;
117 
118       float32x4_t vacc0x0123 = vmulq_f32(vi0x0123, vw0123);
119       const uint32x4_t vm0x0123 = vcltq_s32(vreinterpretq_s32_f32(vi0x0123), vmovq_n_s32(0));
120       float32x4_t vacc1x0123 = vmulq_f32(vi1x0123, vw0123);
121       const uint32x4_t vm1x0123 = vcltq_s32(vreinterpretq_s32_f32(vi1x0123), vmovq_n_s32(0));
122       float32x4_t vacc2x0123 = vmulq_f32(vi2x0123, vw0123);
123       const uint32x4_t vm2x0123 = vcltq_s32(vreinterpretq_s32_f32(vi2x0123), vmovq_n_s32(0));
124       float32x4_t vacc3x0123 = vmulq_f32(vi3x0123, vw0123);
125       const uint32x4_t vm3x0123 = vcltq_s32(vreinterpretq_s32_f32(vi3x0123), vmovq_n_s32(0));
126 
127       vacc0x0123 = vbslq_f32(vm0x0123, vacc0x0123, vi0x0123);
128       vacc1x0123 = vbslq_f32(vm1x0123, vacc1x0123, vi1x0123);
129       vacc2x0123 = vbslq_f32(vm2x0123, vacc2x0123, vi2x0123);
130       vacc3x0123 = vbslq_f32(vm3x0123, vacc3x0123, vi3x0123);
131 
132       vst1q_f32(o0, vacc0x0123); o0 += 4;
133       vst1q_f32(o1, vacc1x0123); o1 += 4;
134       vst1q_f32(o2, vacc2x0123); o2 += 4;
135       vst1q_f32(o3, vacc3x0123); o3 += 4;
136     }
137     if XNN_UNLIKELY(c != 0) {
138       const float32x4_t vw0123 = vld1q_f32(w); w += 4;
139 
140       const float32x4_t vi0x0123 = vld1q_f32(i0);
141       i0 = (const float*) ((uintptr_t) i0 + c);
142       const float32x4_t vi1x0123 = vld1q_f32(i1);
143       i1 = (const float*) ((uintptr_t) i1 + c);
144       const float32x4_t vi2x0123 = vld1q_f32(i2);
145       i2 = (const float*) ((uintptr_t) i2 + c);
146       const float32x4_t vi3x0123 = vld1q_f32(i3);
147       i3 = (const float*) ((uintptr_t) i3 + c);
148 
149       float32x4_t vacc0x0123 = vmulq_f32(vi0x0123, vw0123);
150       const uint32x4_t vm0x0123 = vcltq_s32(vreinterpretq_s32_f32(vi0x0123), vmovq_n_s32(0));
151       float32x4_t vacc1x0123 = vmulq_f32(vi1x0123, vw0123);
152       const uint32x4_t vm1x0123 = vcltq_s32(vreinterpretq_s32_f32(vi1x0123), vmovq_n_s32(0));
153       float32x4_t vacc2x0123 = vmulq_f32(vi2x0123, vw0123);
154       const uint32x4_t vm2x0123 = vcltq_s32(vreinterpretq_s32_f32(vi2x0123), vmovq_n_s32(0));
155       float32x4_t vacc3x0123 = vmulq_f32(vi3x0123, vw0123);
156       const uint32x4_t vm3x0123 = vcltq_s32(vreinterpretq_s32_f32(vi3x0123), vmovq_n_s32(0));
157 
158       vacc0x0123 = vbslq_f32(vm0x0123, vacc0x0123, vi0x0123);
159       vacc1x0123 = vbslq_f32(vm1x0123, vacc1x0123, vi1x0123);
160       vacc2x0123 = vbslq_f32(vm2x0123, vacc2x0123, vi2x0123);
161       vacc3x0123 = vbslq_f32(vm3x0123, vacc3x0123, vi3x0123);
162 
163       float32x2_t vacc0x01 = vget_low_f32(vacc0x0123);
164       float32x2_t vacc1x01 = vget_low_f32(vacc1x0123);
165       float32x2_t vacc2x01 = vget_low_f32(vacc2x0123);
166       float32x2_t vacc3x01 = vget_low_f32(vacc3x0123);
167       if (c & (2 * sizeof(float))) {
168         vst1_f32(o0, vacc0x01); o0 += 2;
169         vst1_f32(o1, vacc1x01); o1 += 2;
170         vst1_f32(o2, vacc2x01); o2 += 2;
171         vst1_f32(o3, vacc3x01); o3 += 2;
172 
173         vacc0x01 = vget_high_f32(vacc0x0123);
174         vacc1x01 = vget_high_f32(vacc1x0123);
175         vacc2x01 = vget_high_f32(vacc2x0123);
176         vacc3x01 = vget_high_f32(vacc3x0123);
177       }
178       if (c & (1 * sizeof(float))) {
179         vst1_lane_f32(o0, vacc0x01, 0); o0 += 1;
180         vst1_lane_f32(o1, vacc1x01, 0); o1 += 1;
181         vst1_lane_f32(o2, vacc2x01, 0); o2 += 1;
182         vst1_lane_f32(o3, vacc3x01, 0); o3 += 1;
183       }
184     }
185     i0 = (const float*) ((uintptr_t) i0 + input_increment);
186     o0 = (float*) ((uintptr_t) o0 + output_increment);
187     i1 = (const float*) ((uintptr_t) i1 + input_increment);
188     o1 = (float*) ((uintptr_t) o1 + output_increment);
189     if XNN_UNPREDICTABLE(rows < 6) {
190       i1 = i0;
191       o1 = o0;
192     }
193     i2 = (const float*) ((uintptr_t) i2 + input_increment);
194     o2 = (float*) ((uintptr_t) o2 + output_increment);
195     if XNN_UNPREDICTABLE(rows <= 6) {
196       i2 = i1;
197       o2 = o1;
198     }
199     i3 = (const float*) ((uintptr_t) i3 + input_increment);
200     o3 = (float*) ((uintptr_t) o3 + output_increment);
201     if XNN_UNPREDICTABLE(rows < 8) {
202       i3 = i2;
203       o3 = o2;
204     }
205     rows = doz(rows, 4);
206   } while (rows != 0);
207 }
208