Debian Codegraph @

src/f32-velu/gen/f32-velu-neonfma-rr1-p6-u16.c

raw symbols SCIP
1 // Auto-generated file. Do not edit!
2 // Template: src/f32-velu/neon-p6.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/vunary.h"
15 #include "xnnpack/common.h"
16
17
18 void xnn_f32_velu_ukernel__neonfma_rr1_p6_u16(
19 size_t batch,
20 const float* input,
21 float* output,
22 const struct xnn_f32_elu_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
23 {
24 assert(batch != 0);
25 assert(batch % sizeof(float) == 0);
26 assert(input != NULL);
27 assert(output != NULL);
28
29 const float32x4_t vsat_cutoff = vmovq_n_f32(-0x1.154246p+4f);
30 const float32x4_t vmagic_bias = vmovq_n_f32(0x1.8000FEp23f);
31 const float32x4_t vlog2e = vmovq_n_f32(0x1.715476p+0f);
32 const float32x4_t vc6 = vmovq_n_f32(0x1.6b7338p-10f);
33 const float32x4_t vc5 = vmovq_n_f32(0x1.12278Ep-7f);
34 const float32x4_t vc4 = vmovq_n_f32(0x1.555716p-5f);
35 const float32x4_t vc3 = vmovq_n_f32(0x1.5554B0p-3f);
36 const float32x4_t vc2 = vmovq_n_f32(0x1.FFFFFEp-2f);
37 const float32x4_t vone = vmovq_n_f32(1.0f);
38
39 XNN_FORCE_REALIZATION(vsat_cutoff);
40 XNN_FORCE_REALIZATION(vmagic_bias);
41 XNN_FORCE_REALIZATION(vlog2e);
42 XNN_FORCE_REALIZATION(vc6);
43 XNN_FORCE_REALIZATION(vc5);
44 XNN_FORCE_REALIZATION(vc4);
45 XNN_FORCE_REALIZATION(vc3);
46 XNN_FORCE_REALIZATION(vc2);
47 XNN_FORCE_REALIZATION(vone);
48
49 const float32x4_t vminus_ln2 = vmovq_n_f32(-0x1.62E430p-1f);
50 XNN_FORCE_REALIZATION(vminus_ln2);
51
52 const float32x4_t vprescale = vld1q_dup_f32(&params->scalar.prescale);
53 const float32x4_t valpha = vld1q_dup_f32(&params->scalar.alpha);
54 const float32x4_t vbeta = vld1q_dup_f32(&params->scalar.beta);
55
56 for (; batch >= 16 * sizeof(float); batch -= 16 * sizeof(float)) {
57 float32x4_t vx0123 = vld1q_f32(input); input += 4;
58 float32x4_t vx4567 = vld1q_f32(input); input += 4;
59 float32x4_t vx89AB = vld1q_f32(input); input += 4;
60 float32x4_t vxCDEF = vld1q_f32(input); input += 4;
61
62 const float32x4_t vz0123 = vmaxq_f32(vmulq_f32(vx0123, vprescale), vsat_cutoff);
63 const float32x4_t vz4567 = vmaxq_f32(vmulq_f32(vx4567, vprescale), vsat_cutoff);
64 const float32x4_t vz89AB = vmaxq_f32(vmulq_f32(vx89AB, vprescale), vsat_cutoff);
65 const float32x4_t vzCDEF = vmaxq_f32(vmulq_f32(vxCDEF, vprescale), vsat_cutoff);
66
67 float32x4_t vn0123 = vfmaq_f32(vmagic_bias, vz0123, vlog2e);
68 float32x4_t vn4567 = vfmaq_f32(vmagic_bias, vz4567, vlog2e);
69 float32x4_t vn89AB = vfmaq_f32(vmagic_bias, vz89AB, vlog2e);
70 float32x4_t vnCDEF = vfmaq_f32(vmagic_bias, vzCDEF, vlog2e);
71
72 float32x4_t vs0123 = vreinterpretq_f32_s32(vshlq_n_s32(vreinterpretq_s32_f32(vn0123), 23));
73 vn0123 = vsubq_f32(vn0123, vmagic_bias);
74 float32x4_t vs4567 = vreinterpretq_f32_s32(vshlq_n_s32(vreinterpretq_s32_f32(vn4567), 23));
75 vn4567 = vsubq_f32(vn4567, vmagic_bias);
76 float32x4_t vs89AB = vreinterpretq_f32_s32(vshlq_n_s32(vreinterpretq_s32_f32(vn89AB), 23));
77 vn89AB = vsubq_f32(vn89AB, vmagic_bias);
78 float32x4_t vsCDEF = vreinterpretq_f32_s32(vshlq_n_s32(vreinterpretq_s32_f32(vnCDEF), 23));
79 vnCDEF = vsubq_f32(vnCDEF, vmagic_bias);
80
81 float32x4_t vt0123 = vfmaq_f32(vz0123, vn0123, vminus_ln2);
82 float32x4_t vt4567 = vfmaq_f32(vz4567, vn4567, vminus_ln2);
83 float32x4_t vt89AB = vfmaq_f32(vz89AB, vn89AB, vminus_ln2);
84 float32x4_t vtCDEF = vfmaq_f32(vzCDEF, vnCDEF, vminus_ln2);
85
86 float32x4_t vp0123 = vfmaq_f32(vc5, vc6, vt0123);
87 float32x4_t vp4567 = vfmaq_f32(vc5, vc6, vt4567);
88 float32x4_t vp89AB = vfmaq_f32(vc5, vc6, vt89AB);
89 float32x4_t vpCDEF = vfmaq_f32(vc5, vc6, vtCDEF);
90
91 vp0123 = vfmaq_f32(vc4, vp0123, vt0123);
92 vp4567 = vfmaq_f32(vc4, vp4567, vt4567);
93 vp89AB = vfmaq_f32(vc4, vp89AB, vt89AB);
94 vpCDEF = vfmaq_f32(vc4, vpCDEF, vtCDEF);
95
96 vp0123 = vfmaq_f32(vc3, vp0123, vt0123);
97 vp4567 = vfmaq_f32(vc3, vp4567, vt4567);
98 vp89AB = vfmaq_f32(vc3, vp89AB, vt89AB);
99 vpCDEF = vfmaq_f32(vc3, vpCDEF, vtCDEF);
100
101 vp0123 = vfmaq_f32(vc2, vp0123, vt0123);
102 vp4567 = vfmaq_f32(vc2, vp4567, vt4567);
103 vp89AB = vfmaq_f32(vc2, vp89AB, vt89AB);
104 vpCDEF = vfmaq_f32(vc2, vpCDEF, vtCDEF);
105
106 vp0123 = vmulq_f32(vp0123, vt0123);
107 vp4567 = vmulq_f32(vp4567, vt4567);
108 vp89AB = vmulq_f32(vp89AB, vt89AB);
109 vpCDEF = vmulq_f32(vpCDEF, vtCDEF);
110
111 vt0123 = vmulq_f32(vt0123, vs0123);
112 vs0123 = vsubq_f32(vs0123, vone);
113 vt4567 = vmulq_f32(vt4567, vs4567);
114 vs4567 = vsubq_f32(vs4567, vone);
115 vt89AB = vmulq_f32(vt89AB, vs89AB);
116 vs89AB = vsubq_f32(vs89AB, vone);
117 vtCDEF = vmulq_f32(vtCDEF, vsCDEF);
118 vsCDEF = vsubq_f32(vsCDEF, vone);
119
120 vp0123 = vfmaq_f32(vt0123, vp0123, vt0123);
121 vp4567 = vfmaq_f32(vt4567, vp4567, vt4567);
122 vp89AB = vfmaq_f32(vt89AB, vp89AB, vt89AB);
123 vpCDEF = vfmaq_f32(vtCDEF, vpCDEF, vtCDEF);
124
125 const float32x4_t ve0123 = vmulq_f32(vaddq_f32(vp0123, vs0123), valpha);
126 const float32x4_t ve4567 = vmulq_f32(vaddq_f32(vp4567, vs4567), valpha);
127 const float32x4_t ve89AB = vmulq_f32(vaddq_f32(vp89AB, vs89AB), valpha);
128 const float32x4_t veCDEF = vmulq_f32(vaddq_f32(vpCDEF, vsCDEF), valpha);
129
130 const uint32x4_t vm0123 = vcltq_f32(vx0123, vmovq_n_f32(0.0f));
131 vx0123 = vmulq_f32(vx0123, vbeta);
132 const uint32x4_t vm4567 = vcltq_f32(vx4567, vmovq_n_f32(0.0f));
133 vx4567 = vmulq_f32(vx4567, vbeta);
134 const uint32x4_t vm89AB = vcltq_f32(vx89AB, vmovq_n_f32(0.0f));
135 vx89AB = vmulq_f32(vx89AB, vbeta);
136 const uint32x4_t vmCDEF = vcltq_f32(vxCDEF, vmovq_n_f32(0.0f));
137 vxCDEF = vmulq_f32(vxCDEF, vbeta);
138
139 const float32x4_t vy0123 = vbslq_f32(vm0123, ve0123, vx0123);
140 const float32x4_t vy4567 = vbslq_f32(vm4567, ve4567, vx4567);
141 const float32x4_t vy89AB = vbslq_f32(vm89AB, ve89AB, vx89AB);
142 const float32x4_t vyCDEF = vbslq_f32(vmCDEF, veCDEF, vxCDEF);
143
144 vst1q_f32(output, vy0123); output += 4;
145 vst1q_f32(output, vy4567); output += 4;
146 vst1q_f32(output, vy89AB); output += 4;
147 vst1q_f32(output, vyCDEF); output += 4;
148 }
149 for (; batch >= 4 * sizeof(float); batch -= 4 * sizeof(float)) {
150 float32x4_t vx = vld1q_f32(input); input += 4;
151
152 const float32x4_t vz = vmaxq_f32(vmulq_f32(vx, vprescale), vsat_cutoff);
153
154 float32x4_t vn = vfmaq_f32(vmagic_bias, vz, vlog2e);
155 float32x4_t vs = vreinterpretq_f32_s32(vshlq_n_s32(vreinterpretq_s32_f32(vn), 23));
156 vn = vsubq_f32(vn, vmagic_bias);
157
158 float32x4_t vt = vfmaq_f32(vz, vn, vminus_ln2);
159
160 float32x4_t vp = vfmaq_f32(vc5, vc6, vt);
161 vp = vfmaq_f32(vc4, vp, vt);
162 vp = vfmaq_f32(vc3, vp, vt);
163 vp = vfmaq_f32(vc2, vp, vt);
164 vp = vmulq_f32(vp, vt);
165
166 vt = vmulq_f32(vt, vs);
167 vs = vsubq_f32(vs, vone);
168 vp = vfmaq_f32(vt, vp, vt);
169 const float32x4_t ve = vmulq_f32(vaddq_f32(vp, vs), valpha);
170
171 const uint32x4_t vm = vcltq_f32(vx, vmovq_n_f32(0.0f));
172 vx = vmulq_f32(vx, vbeta);
173 const float32x4_t vy = vbslq_f32(vm, ve, vx);
174
175 vst1q_f32(output, vy); output += 4;
176 }
177 if XNN_UNLIKELY(batch != 0) {
178 float32x4_t vx = vld1q_f32(input);
179
180 const float32x4_t vz = vmaxq_f32(vmulq_f32(vx, vprescale), vsat_cutoff);
181
182 float32x4_t vn = vfmaq_f32(vmagic_bias, vz, vlog2e);
183 float32x4_t vs = vreinterpretq_f32_s32(vshlq_n_s32(vreinterpretq_s32_f32(vn), 23));
184 vn = vsubq_f32(vn, vmagic_bias);
185
186 float32x4_t vt = vfmaq_f32(vz, vn, vminus_ln2);
187
188 float32x4_t vp = vfmaq_f32(vc5, vc6, vt);
189 vp = vfmaq_f32(vc4, vp, vt);
190 vp = vfmaq_f32(vc3, vp, vt);
191 vp = vfmaq_f32(vc2, vp, vt);
192 vp = vmulq_f32(vp, vt);
193
194 vt = vmulq_f32(vt, vs);
195 vs = vsubq_f32(vs, vone);
196 vp = vfmaq_f32(vt, vp, vt);
197 const float32x4_t ve = vmulq_f32(vaddq_f32(vp, vs), valpha);
198
199 const uint32x4_t vm = vcltq_f32(vx, vmovq_n_f32(0.0f));
200 vx = vmulq_f32(vx, vbeta);
201 const float32x4_t vy = vbslq_f32(vm, ve, vx);
202
203 float32x2_t vy_lo = vget_low_f32(vy);
204 if (batch & (2 * sizeof(float))) {
205 vst1_f32(output, vy_lo); output += 2;
206 vy_lo = vget_high_f32(vy);
207 }
208 if (batch & (1 * sizeof(float))) {
209 vst1_lane_f32(output, vy_lo, 0);
210 }
211 }
212 }