Debian Codegraph @

src/f32-velu/gen/f32-velu-scalar-rr2-p6-u3.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_u3(
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 >= 3 * sizeof(float); batch -= 3 * sizeof(float)) {
46 float vx0 = input[0];
47 float vx1 = input[1];
48 float vx2 = input[2];
49 input += 3;
50
51 const float vz0 = vx0 * vprescale;
52 const float vz1 = vx1 * vprescale;
53 const float vz2 = vx2 * vprescale;
54
55 float vn0 = vz0 * vlog2e + vmagic_bias;
56 float vn1 = vz1 * vlog2e + vmagic_bias;
57 float vn2 = vz2 * vlog2e + vmagic_bias;
58
59 float vs0 = uint32_as_float(float_as_uint32(vn0) << 23);
60 vn0 -= vmagic_bias;
61 float vs1 = uint32_as_float(float_as_uint32(vn1) << 23);
62 vn1 -= vmagic_bias;
63 float vs2 = uint32_as_float(float_as_uint32(vn2) << 23);
64 vn2 -= vmagic_bias;
65
66 float vt0 = vn0 * vminus_ln2_hi + vz0;
67 float vt1 = vn1 * vminus_ln2_hi + vz1;
68 float vt2 = vn2 * vminus_ln2_hi + vz2;
69
70 vt0 = vn0 * vminus_ln2_lo + vt0;
71 vt1 = vn1 * vminus_ln2_lo + vt1;
72 vt2 = vn2 * vminus_ln2_lo + vt2;
73
74 if XNN_UNPREDICTABLE(vz0 <= vsat_cutoff) {
75 vs0 = 0.0f;
76 vt0 = 0.0f;
77 }
78 if XNN_UNPREDICTABLE(vz1 <= vsat_cutoff) {
79 vs1 = 0.0f;
80 vt1 = 0.0f;
81 }
82 if XNN_UNPREDICTABLE(vz2 <= vsat_cutoff) {
83 vs2 = 0.0f;
84 vt2 = 0.0f;
85 }
86
87 float vp0 = vc6 * vt0 + vc5;
88 float vp1 = vc6 * vt1 + vc5;
89 float vp2 = vc6 * vt2 + vc5;
90
91 vp0 = vp0 * vt0 + vc4;
92 vp1 = vp1 * vt1 + vc4;
93 vp2 = vp2 * vt2 + vc4;
94
95 vp0 = vp0 * vt0 + vc3;
96 vp1 = vp1 * vt1 + vc3;
97 vp2 = vp2 * vt2 + vc3;
98
99 vp0 = vp0 * vt0 + vc2;
100 vp1 = vp1 * vt1 + vc2;
101 vp2 = vp2 * vt2 + vc2;
102
103 vp0 *= vt0;
104 vp1 *= vt1;
105 vp2 *= vt2;
106
107 vt0 *= vs0;
108 vs0 -= vone;
109 vt1 *= vs1;
110 vs1 -= vone;
111 vt2 *= vs2;
112 vs2 -= vone;
113
114 vp0 = vp0 * vt0 + vt0;
115 vp1 = vp1 * vt1 + vt1;
116 vp2 = vp2 * vt2 + vt2;
117
118 const float ve0 = (vp0 + vs0) * valpha;
119 float vy0 = vx0 * vbeta;
120 const float ve1 = (vp1 + vs1) * valpha;
121 float vy1 = vx1 * vbeta;
122 const float ve2 = (vp2 + vs2) * valpha;
123 float vy2 = vx2 * vbeta;
124
125 if XNN_UNPREDICTABLE(vx0 < 0.0f) {
126 vy0 = ve0;
127 }
128 if XNN_UNPREDICTABLE(vx1 < 0.0f) {
129 vy1 = ve1;
130 }
131 if XNN_UNPREDICTABLE(vx2 < 0.0f) {
132 vy2 = ve2;
133 }
134
135 output[0] = vy0;
136 output[1] = vy1;
137 output[2] = vy2;
138 output += 3;
139 }
140 if XNN_UNLIKELY(batch != 0) {
141 do {
142 float vx = *input++;
143
144 const float vz = vx * vprescale;
145
146 float vn = vz * vlog2e + vmagic_bias;
147 float vs = uint32_as_float(float_as_uint32(vn) << 23);
148 vn -= vmagic_bias;
149
150 float vt = vn * vminus_ln2_hi + vz;
151 vt = vn * vminus_ln2_lo + vt;
152
153 if XNN_UNPREDICTABLE(vz <= vsat_cutoff) {
154 vs = 0.0f;
155 vt = 0.0f;
156 }
157
158 float vp = vc6 * vt + vc5;
159 vp = vp * vt + vc4;
160 vp = vp * vt + vc3;
161 vp = vp * vt + vc2;
162 vp *= vt;
163
164 vt *= vs;
165 vs -= vone;
166 vp = vp * vt + vt;
167 const float ve = (vp + vs) * valpha;
168
169 float vy = vx * vbeta;
170 if XNN_UNPREDICTABLE(vx < 0.0f) {
171 vy = ve;
172 }
173
174 *output++ = vy;
175
176 batch -= sizeof(float);
177 } while (batch != 0);
178 }
179 }