Debian Codegraph @

src/f32-velu/gen/f32-velu-scalar-rr2-lut16-p3-u6.c

raw symbols SCIP
1 // Auto-generated file. Do not edit!
2 // Template: src/f32-velu/scalar-rr2-lut16-p3.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 #include <math.h>
12
13 #include "xnnpack/common.h"
14 #include "xnnpack/math.h"
15 #include "xnnpack/vunary.h"
16
17
18 extern XNN_INTERNAL const uint32_t xnn_table_exp2minus_k_over_16[16];
19
20 void xnn_f32_velu_ukernel__scalar_rr2_lut16_p3_u6(
21 size_t batch,
22 const float* input,
23 float* output,
24 const struct xnn_f32_elu_params params[restrict XNN_MIN_ELEMENTS(1)])
25 {
26 assert(batch != 0);
27 assert(batch % sizeof(float) == 0);
28 assert(input != NULL);
29 assert(output != NULL);
30
31 const float vsat_cutoff = -0x1.154246p+4f;
32 const float vmagic_bias = 0x1.800000p19f;
33 const float vlog2e = 0x1.715476p+0f;
34 const float vminus_ln2_hi = -0x1.62E400p-1f;
35 const float vminus_ln2_lo = -0x1.7F7D1Cp-20f;
36 const uint32_t vindex_mask = UINT32_C(0xF);
37 const float vc3 = 0x1.55561Cp-3f;
38 const float vc2 = 0x1.0001ECp-1f;
39 const float vone = 1.0f;
40
41 const float vprescale = params->scalar.prescale;
42 const float valpha = params->scalar.alpha;
43 const float vbeta = params->scalar.beta;
44
45 for (; batch >= 6 * sizeof(float); batch -= 6 * sizeof(float)) {
46 float vx0 = input[0];
47 float vx1 = input[1];
48 float vx2 = input[2];
49 float vx3 = input[3];
50 float vx4 = input[4];
51 float vx5 = input[5];
52 input += 6;
53
54 const float vz0 = vx0 * vprescale;
55 const float vz1 = vx1 * vprescale;
56 const float vz2 = vx2 * vprescale;
57 const float vz3 = vx3 * vprescale;
58 const float vz4 = vx4 * vprescale;
59 const float vz5 = vx5 * vprescale;
60
61 float vn0 = vz0 * vlog2e + vmagic_bias;
62 float vn1 = vz1 * vlog2e + vmagic_bias;
63 float vn2 = vz2 * vlog2e + vmagic_bias;
64 float vn3 = vz3 * vlog2e + vmagic_bias;
65 float vn4 = vz4 * vlog2e + vmagic_bias;
66 float vn5 = vz5 * vlog2e + vmagic_bias;
67
68 const uint32_t ven0 = float_as_uint32(vn0) << 19;
69 const uint32_t vidx0 = float_as_uint32(vn0) & vindex_mask;
70 vn0 -= vmagic_bias;
71 const uint32_t ven1 = float_as_uint32(vn1) << 19;
72 const uint32_t vidx1 = float_as_uint32(vn1) & vindex_mask;
73 vn1 -= vmagic_bias;
74 const uint32_t ven2 = float_as_uint32(vn2) << 19;
75 const uint32_t vidx2 = float_as_uint32(vn2) & vindex_mask;
76 vn2 -= vmagic_bias;
77 const uint32_t ven3 = float_as_uint32(vn3) << 19;
78 const uint32_t vidx3 = float_as_uint32(vn3) & vindex_mask;
79 vn3 -= vmagic_bias;
80 const uint32_t ven4 = float_as_uint32(vn4) << 19;
81 const uint32_t vidx4 = float_as_uint32(vn4) & vindex_mask;
82 vn4 -= vmagic_bias;
83 const uint32_t ven5 = float_as_uint32(vn5) << 19;
84 const uint32_t vidx5 = float_as_uint32(vn5) & vindex_mask;
85 vn5 -= vmagic_bias;
86
87 float vt0 = vn0 * vminus_ln2_hi + vz0;
88 float vs0 = uint32_as_float(xnn_table_exp2minus_k_over_16[vidx0] + ven0);
89 float vt1 = vn1 * vminus_ln2_hi + vz1;
90 float vs1 = uint32_as_float(xnn_table_exp2minus_k_over_16[vidx1] + ven1);
91 float vt2 = vn2 * vminus_ln2_hi + vz2;
92 float vs2 = uint32_as_float(xnn_table_exp2minus_k_over_16[vidx2] + ven2);
93 float vt3 = vn3 * vminus_ln2_hi + vz3;
94 float vs3 = uint32_as_float(xnn_table_exp2minus_k_over_16[vidx3] + ven3);
95 float vt4 = vn4 * vminus_ln2_hi + vz4;
96 float vs4 = uint32_as_float(xnn_table_exp2minus_k_over_16[vidx4] + ven4);
97 float vt5 = vn5 * vminus_ln2_hi + vz5;
98 float vs5 = uint32_as_float(xnn_table_exp2minus_k_over_16[vidx5] + ven5);
99
100 vt0 = vn0 * vminus_ln2_lo + vt0;
101 if XNN_UNPREDICTABLE(vz0 <= vsat_cutoff) {
102 vs0 = 0.0f;
103 vt0 = 0.0f;
104 }
105 vt1 = vn1 * vminus_ln2_lo + vt1;
106 if XNN_UNPREDICTABLE(vz1 <= vsat_cutoff) {
107 vs1 = 0.0f;
108 vt1 = 0.0f;
109 }
110 vt2 = vn2 * vminus_ln2_lo + vt2;
111 if XNN_UNPREDICTABLE(vz2 <= vsat_cutoff) {
112 vs2 = 0.0f;
113 vt2 = 0.0f;
114 }
115 vt3 = vn3 * vminus_ln2_lo + vt3;
116 if XNN_UNPREDICTABLE(vz3 <= vsat_cutoff) {
117 vs3 = 0.0f;
118 vt3 = 0.0f;
119 }
120 vt4 = vn4 * vminus_ln2_lo + vt4;
121 if XNN_UNPREDICTABLE(vz4 <= vsat_cutoff) {
122 vs4 = 0.0f;
123 vt4 = 0.0f;
124 }
125 vt5 = vn5 * vminus_ln2_lo + vt5;
126 if XNN_UNPREDICTABLE(vz5 <= vsat_cutoff) {
127 vs5 = 0.0f;
128 vt5 = 0.0f;
129 }
130
131 float vp0 = vc3 * vt0 + vc2;
132 float vp1 = vc3 * vt1 + vc2;
133 float vp2 = vc3 * vt2 + vc2;
134 float vp3 = vc3 * vt3 + vc2;
135 float vp4 = vc3 * vt4 + vc2;
136 float vp5 = vc3 * vt5 + vc2;
137
138 vp0 *= vt0;
139 vp1 *= vt1;
140 vp2 *= vt2;
141 vp3 *= vt3;
142 vp4 *= vt4;
143 vp5 *= vt5;
144
145 vt0 *= vs0;
146 vs0 -= vone;
147 vt1 *= vs1;
148 vs1 -= vone;
149 vt2 *= vs2;
150 vs2 -= vone;
151 vt3 *= vs3;
152 vs3 -= vone;
153 vt4 *= vs4;
154 vs4 -= vone;
155 vt5 *= vs5;
156 vs5 -= vone;
157
158 vp0 = vp0 * vt0 + vt0;
159 vp1 = vp1 * vt1 + vt1;
160 vp2 = vp2 * vt2 + vt2;
161 vp3 = vp3 * vt3 + vt3;
162 vp4 = vp4 * vt4 + vt4;
163 vp5 = vp5 * vt5 + vt5;
164
165 const float ve0 = (vp0 + vs0) * valpha;
166 float vy0 = vx0 * vbeta;
167 const float ve1 = (vp1 + vs1) * valpha;
168 float vy1 = vx1 * vbeta;
169 const float ve2 = (vp2 + vs2) * valpha;
170 float vy2 = vx2 * vbeta;
171 const float ve3 = (vp3 + vs3) * valpha;
172 float vy3 = vx3 * vbeta;
173 const float ve4 = (vp4 + vs4) * valpha;
174 float vy4 = vx4 * vbeta;
175 const float ve5 = (vp5 + vs5) * valpha;
176 float vy5 = vx5 * vbeta;
177
178 if XNN_UNPREDICTABLE(vx0 < 0.0f) {
179 vy0 = ve0;
180 }
181 if XNN_UNPREDICTABLE(vx1 < 0.0f) {
182 vy1 = ve1;
183 }
184 if XNN_UNPREDICTABLE(vx2 < 0.0f) {
185 vy2 = ve2;
186 }
187 if XNN_UNPREDICTABLE(vx3 < 0.0f) {
188 vy3 = ve3;
189 }
190 if XNN_UNPREDICTABLE(vx4 < 0.0f) {
191 vy4 = ve4;
192 }
193 if XNN_UNPREDICTABLE(vx5 < 0.0f) {
194 vy5 = ve5;
195 }
196
197 output[0] = vy0;
198 output[1] = vy1;
199 output[2] = vy2;
200 output[3] = vy3;
201 output[4] = vy4;
202 output[5] = vy5;
203 output += 6;
204 }
205 if XNN_UNLIKELY(batch != 0) {
206 do {
207 float vx = *input++;
208
209 const float vz = vx * vprescale;
210
211 float vn = vz * vlog2e + vmagic_bias;
212 const uint32_t ven = float_as_uint32(vn) << 19;
213 const uint32_t vidx = float_as_uint32(vn) & vindex_mask;
214 vn -= vmagic_bias;
215
216 float vt = vn * vminus_ln2_hi + vz;
217 float vs = uint32_as_float(xnn_table_exp2minus_k_over_16[vidx] + ven);
218
219 vt = vn * vminus_ln2_lo + vt;
220 if XNN_UNPREDICTABLE(vz <= vsat_cutoff) {
221 vs = 0.0f;
222 vt = 0.0f;
223 }
224
225 float vp = vc3 * vt + vc2;
226 vp *= vt;
227
228 vt *= vs;
229 vs -= vone;
230 vp = vp * vt + vt;
231 const float ve = (vp + vs) * valpha;
232
233 float vy = vx * vbeta;
234 if XNN_UNPREDICTABLE(vx < 0.0f) {
235 vy = ve;
236 }
237
238 *output++ = vy;
239
240 batch -= sizeof(float);
241 } while (batch != 0);
242 }
243 }