Debian Codegraph @

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