Debian Codegraph @

src/f32-velu/gen/f32-velu-wasm-rr2-p6-u6.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__wasm_rr2_p6_u6(
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 >= 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 = __builtin_wasm_min_f32(__builtin_wasm_max_f32(vx0 * vprescale, vsat_cutoff), 0.0f);
55 const float vz1 = __builtin_wasm_min_f32(__builtin_wasm_max_f32(vx1 * vprescale, vsat_cutoff), 0.0f);
56 const float vz2 = __builtin_wasm_min_f32(__builtin_wasm_max_f32(vx2 * vprescale, vsat_cutoff), 0.0f);
57 const float vz3 = __builtin_wasm_min_f32(__builtin_wasm_max_f32(vx3 * vprescale, vsat_cutoff), 0.0f);
58 const float vz4 = __builtin_wasm_min_f32(__builtin_wasm_max_f32(vx4 * vprescale, vsat_cutoff), 0.0f);
59 const float vz5 = __builtin_wasm_min_f32(__builtin_wasm_max_f32(vx5 * vprescale, vsat_cutoff), 0.0f);
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 float vs0 = uint32_as_float(float_as_uint32(vn0) << 23);
69 vn0 -= vmagic_bias;
70 float vs1 = uint32_as_float(float_as_uint32(vn1) << 23);
71 vn1 -= vmagic_bias;
72 float vs2 = uint32_as_float(float_as_uint32(vn2) << 23);
73 vn2 -= vmagic_bias;
74 float vs3 = uint32_as_float(float_as_uint32(vn3) << 23);
75 vn3 -= vmagic_bias;
76 float vs4 = uint32_as_float(float_as_uint32(vn4) << 23);
77 vn4 -= vmagic_bias;
78 float vs5 = uint32_as_float(float_as_uint32(vn5) << 23);
79 vn5 -= vmagic_bias;
80
81 float vt0 = vn0 * vminus_ln2_hi + vz0;
82 float vt1 = vn1 * vminus_ln2_hi + vz1;
83 float vt2 = vn2 * vminus_ln2_hi + vz2;
84 float vt3 = vn3 * vminus_ln2_hi + vz3;
85 float vt4 = vn4 * vminus_ln2_hi + vz4;
86 float vt5 = vn5 * vminus_ln2_hi + vz5;
87
88 vt0 = vn0 * vminus_ln2_lo + vt0;
89 vt1 = vn1 * vminus_ln2_lo + vt1;
90 vt2 = vn2 * vminus_ln2_lo + vt2;
91 vt3 = vn3 * vminus_ln2_lo + vt3;
92 vt4 = vn4 * vminus_ln2_lo + vt4;
93 vt5 = vn5 * vminus_ln2_lo + vt5;
94
95
96 float vp0 = vc6 * vt0 + vc5;
97 float vp1 = vc6 * vt1 + vc5;
98 float vp2 = vc6 * vt2 + vc5;
99 float vp3 = vc6 * vt3 + vc5;
100 float vp4 = vc6 * vt4 + vc5;
101 float vp5 = vc6 * vt5 + vc5;
102
103 vp0 = vp0 * vt0 + vc4;
104 vp1 = vp1 * vt1 + vc4;
105 vp2 = vp2 * vt2 + vc4;
106 vp3 = vp3 * vt3 + vc4;
107 vp4 = vp4 * vt4 + vc4;
108 vp5 = vp5 * vt5 + vc4;
109
110 vp0 = vp0 * vt0 + vc3;
111 vp1 = vp1 * vt1 + vc3;
112 vp2 = vp2 * vt2 + vc3;
113 vp3 = vp3 * vt3 + vc3;
114 vp4 = vp4 * vt4 + vc3;
115 vp5 = vp5 * vt5 + vc3;
116
117 vp0 = vp0 * vt0 + vc2;
118 vp1 = vp1 * vt1 + vc2;
119 vp2 = vp2 * vt2 + vc2;
120 vp3 = vp3 * vt3 + vc2;
121 vp4 = vp4 * vt4 + vc2;
122 vp5 = vp5 * vt5 + vc2;
123
124 vp0 *= vt0;
125 vp1 *= vt1;
126 vp2 *= vt2;
127 vp3 *= vt3;
128 vp4 *= vt4;
129 vp5 *= vt5;
130
131 vt0 *= vs0;
132 vs0 -= vone;
133 vt1 *= vs1;
134 vs1 -= vone;
135 vt2 *= vs2;
136 vs2 -= vone;
137 vt3 *= vs3;
138 vs3 -= vone;
139 vt4 *= vs4;
140 vs4 -= vone;
141 vt5 *= vs5;
142 vs5 -= vone;
143
144 vp0 = vp0 * vt0 + vt0;
145 vp1 = vp1 * vt1 + vt1;
146 vp2 = vp2 * vt2 + vt2;
147 vp3 = vp3 * vt3 + vt3;
148 vp4 = vp4 * vt4 + vt4;
149 vp5 = vp5 * vt5 + vt5;
150
151 const float ve0 = (vp0 + vs0) * valpha;
152 float vy0 = __builtin_wasm_max_f32(vx0 * vbeta, 0.0f);
153 const float ve1 = (vp1 + vs1) * valpha;
154 float vy1 = __builtin_wasm_max_f32(vx1 * vbeta, 0.0f);
155 const float ve2 = (vp2 + vs2) * valpha;
156 float vy2 = __builtin_wasm_max_f32(vx2 * vbeta, 0.0f);
157 const float ve3 = (vp3 + vs3) * valpha;
158 float vy3 = __builtin_wasm_max_f32(vx3 * vbeta, 0.0f);
159 const float ve4 = (vp4 + vs4) * valpha;
160 float vy4 = __builtin_wasm_max_f32(vx4 * vbeta, 0.0f);
161 const float ve5 = (vp5 + vs5) * valpha;
162 float vy5 = __builtin_wasm_max_f32(vx5 * vbeta, 0.0f);
163
164 vy0 += __builtin_wasm_min_f32(ve0, 0.0f);
165 vy1 += __builtin_wasm_min_f32(ve1, 0.0f);
166 vy2 += __builtin_wasm_min_f32(ve2, 0.0f);
167 vy3 += __builtin_wasm_min_f32(ve3, 0.0f);
168 vy4 += __builtin_wasm_min_f32(ve4, 0.0f);
169 vy5 += __builtin_wasm_min_f32(ve5, 0.0f);
170
171 output[0] = vy0;
172 output[1] = vy1;
173 output[2] = vy2;
174 output[3] = vy3;
175 output[4] = vy4;
176 output[5] = vy5;
177 output += 6;
178 }
179 if XNN_UNLIKELY(batch != 0) {
180 do {
181 float vx = *input++;
182
183 const float vz = __builtin_wasm_min_f32(__builtin_wasm_max_f32(vx * vprescale, vsat_cutoff), 0.0f);
184
185 float vn = vz * vlog2e + vmagic_bias;
186 float vs = uint32_as_float(float_as_uint32(vn) << 23);
187 vn -= vmagic_bias;
188
189 float vt = vn * vminus_ln2_hi + vz;
190 vt = vn * vminus_ln2_lo + vt;
191
192
193 float vp = vc6 * vt + vc5;
194 vp = vp * vt + vc4;
195 vp = vp * vt + vc3;
196 vp = vp * vt + vc2;
197 vp *= vt;
198
199 vt *= vs;
200 vs -= vone;
201 vp = vp * vt + vt;
202 const float ve = (vp + vs) * valpha;
203
204 float vy = __builtin_wasm_max_f32(vx * vbeta, 0.0f);
205 vy += __builtin_wasm_min_f32(ve, 0.0f);
206
207 *output++ = vy;
208
209 batch -= sizeof(float);
210 } while (batch != 0);
211 }
212 }