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
xnn_f32_velu_ukernel__wasm_rr2_p6_x1(size_t n,const float * x,float * y,const union xnn_f32_elu_params params[restrict XNN_MIN_ELEMENTS (1)])18 void xnn_f32_velu_ukernel__wasm_rr2_p6_x1(
19 size_t n,
20 const float* x,
21 float* y,
22 const union xnn_f32_elu_params params[restrict XNN_MIN_ELEMENTS(1)])
23 {
24 assert(n % sizeof(float) == 0);
25
26 const float vprescale = params->scalar_rr2_p6.prescale;
27 const float valpha = params->scalar_rr2_p6.alpha;
28 const float vbeta = params->scalar_rr2_p6.beta;
29 const float vmagic_bias = params->scalar_rr2_p6.magic_bias;
30 const float vlog2e = params->scalar_rr2_p6.log2e;
31 const float vsat_cutoff = params->scalar_rr2_p6.sat_cutoff;
32 const float vminus_ln2_hi = params->scalar_rr2_p6.minus_ln2_hi;
33 const float vminus_ln2_lo = params->scalar_rr2_p6.minus_ln2_lo;
34 const float vc6 = params->scalar_rr2_p6.c6;
35 const float vc5 = params->scalar_rr2_p6.c5;
36 const float vc4 = params->scalar_rr2_p6.c4;
37 const float vc3 = params->scalar_rr2_p6.c3;
38 const float vc2 = params->scalar_rr2_p6.c2;
39 const float vone = params->scalar_rr2_p6.one;
40
41 do {
42 float vx = *x++;
43
44 const float vz = __builtin_wasm_min_f32(__builtin_wasm_max_f32(vx * vprescale, vsat_cutoff), 0.0f);
45
46 float vn = vz * vlog2e + vmagic_bias;
47 float vs = uint32_as_float(float_as_uint32(vn) << 23);
48 vn -= vmagic_bias;
49
50 float vt = vn * vminus_ln2_hi + vz;
51 vt = vn * vminus_ln2_lo + vt;
52
53
54 float vp = vc6 * vt + vc5;
55 vp = vp * vt + vc4;
56 vp = vp * vt + vc3;
57 vp = vp * vt + vc2;
58 vp *= vt;
59
60 vt *= vs;
61 vs -= vone;
62 vp = vp * vt + vt;
63 const float ve = (vp + vs) * valpha;
64
65 float vy = __builtin_wasm_max_f32(vx * vbeta, 0.0f);
66 vy += __builtin_wasm_min_f32(ve, 0.0f);
67
68 *y++ = vy;
69
70 n -= sizeof(float);
71 } while (n != 0);
72 }
73