Debian Codegraph @

src/f32-velu/gen/f32-velu-scalar-rr2-p6-u2.c

raw symbols SCIP
1 // Auto-generated file. Do not edit!
2 // Template: src/f32-velu/scalar-rr2-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 #include <math.h>
12
13 #include "xnnpack/common.h"
14 #include "xnnpack/math.h"
15 #include "xnnpack/vunary.h"
16
17
18 void xnn_f32_velu_ukernel__scalar_rr2_p6_u2(
19 size_t batch,
20 const float* input,
21 float* output,
22 const struct xnn_f32_elu_params params[restrict XNN_MIN_ELEMENTS(1)])
23 {
24 assert(batch != 0);
25 assert(batch % sizeof(float) == 0);
26 assert(input != NULL);
27 assert(output != NULL);
28
29 const float vsat_cutoff = -0x1.154246p+4f;
30 const float vmagic_bias = 0x1.8000FEp23f;
31 const float vlog2e = 0x1.715476p+0f;
32 const float vminus_ln2_hi = -0x1.62E440p-1f;
33 const float vminus_ln2_lo = 0x1.0105C6p-21f;
34 const float vc6 = 0x1.6b7338p-10f;
35 const float vc5 = 0x1.12278Ep-7f;
36 const float vc4 = 0x1.555716p-5f;
37 const float vc3 = 0x1.5554B0p-3f;
38 const float vc2 = 0x1.FFFFFEp-2f;
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 >= 2 * sizeof(float); batch -= 2 * sizeof(float)) {
46 float vx0 = input[0];
47 float vx1 = input[1];
48 input += 2;
49
50 const float vz0 = vx0 * vprescale;
51 const float vz1 = vx1 * vprescale;
52
53 float vn0 = vz0 * vlog2e + vmagic_bias;
54 float vn1 = vz1 * vlog2e + vmagic_bias;
55
56 float vs0 = uint32_as_float(float_as_uint32(vn0) << 23);
57 vn0 -= vmagic_bias;
58 float vs1 = uint32_as_float(float_as_uint32(vn1) << 23);
59 vn1 -= vmagic_bias;
60
61 float vt0 = vn0 * vminus_ln2_hi + vz0;
62 float vt1 = vn1 * vminus_ln2_hi + vz1;
63
64 vt0 = vn0 * vminus_ln2_lo + vt0;
65 vt1 = vn1 * vminus_ln2_lo + vt1;
66
67 if XNN_UNPREDICTABLE(vz0 <= vsat_cutoff) {
68 vs0 = 0.0f;
69 vt0 = 0.0f;
70 }
71 if XNN_UNPREDICTABLE(vz1 <= vsat_cutoff) {
72 vs1 = 0.0f;
73 vt1 = 0.0f;
74 }
75
76 float vp0 = vc6 * vt0 + vc5;
77 float vp1 = vc6 * vt1 + vc5;
78
79 vp0 = vp0 * vt0 + vc4;
80 vp1 = vp1 * vt1 + vc4;
81
82 vp0 = vp0 * vt0 + vc3;
83 vp1 = vp1 * vt1 + vc3;
84
85 vp0 = vp0 * vt0 + vc2;
86 vp1 = vp1 * vt1 + vc2;
87
88 vp0 *= vt0;
89 vp1 *= vt1;
90
91 vt0 *= vs0;
92 vs0 -= vone;
93 vt1 *= vs1;
94 vs1 -= vone;
95
96 vp0 = vp0 * vt0 + vt0;
97 vp1 = vp1 * vt1 + vt1;
98
99 const float ve0 = (vp0 + vs0) * valpha;
100 float vy0 = vx0 * vbeta;
101 const float ve1 = (vp1 + vs1) * valpha;
102 float vy1 = vx1 * vbeta;
103
104 if XNN_UNPREDICTABLE(vx0 < 0.0f) {
105 vy0 = ve0;
106 }
107 if XNN_UNPREDICTABLE(vx1 < 0.0f) {
108 vy1 = ve1;
109 }
110
111 output[0] = vy0;
112 output[1] = vy1;
113 output += 2;
114 }
115 if XNN_UNLIKELY(batch != 0) {
116 float vx = *input;
117
118 const float vz = vx * vprescale;
119
120 float vn = vz * vlog2e + vmagic_bias;
121 float vs = uint32_as_float(float_as_uint32(vn) << 23);
122 vn -= vmagic_bias;
123
124 float vt = vn * vminus_ln2_hi + vz;
125 vt = vn * vminus_ln2_lo + vt;
126
127 if XNN_UNPREDICTABLE(vz <= vsat_cutoff) {
128 vs = 0.0f;
129 vt = 0.0f;
130 }
131
132 float vp = vc6 * vt + vc5;
133 vp = vp * vt + vc4;
134 vp = vp * vt + vc3;
135 vp = vp * vt + vc2;
136 vp *= vt;
137
138 vt *= vs;
139 vs -= vone;
140 vp = vp * vt + vt;
141 const float ve = (vp + vs) * valpha;
142
143 float vy = vx * vbeta;
144 if XNN_UNPREDICTABLE(vx < 0.0f) {
145 vy = ve;
146 }
147
148 *output = vy;
149 }
150 }