• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/vunary.h>
15 
16 #include <fp16/bitcasts.h>
17 
18 
xnn_f32_velu_ukernel__scalar_rr2_p6_x1(size_t n,const float * x,float * y,const union xnn_f32_elu_params params[restrict XNN_MIN_ELEMENTS (1)])19 void xnn_f32_velu_ukernel__scalar_rr2_p6_x1(
20     size_t n,
21     const float* x,
22     float* y,
23     const union xnn_f32_elu_params params[restrict XNN_MIN_ELEMENTS(1)])
24 {
25   assert(n % sizeof(float) == 0);
26 
27   const float vprescale = params->scalar.prescale;
28   const float valpha = params->scalar.alpha;
29   const float vbeta = params->scalar.beta;
30 
31   const float vmagic_bias = 0x1.8000FEp23f;
32   const float vlog2e = 0x1.715476p+0f;
33   const float vsat_cutoff = -0x1.154246p+4f;
34   const float vminus_ln2_hi = -0x1.62E440p-1f;
35   const float vminus_ln2_lo = 0x1.0105C6p-21f;
36   const float vc6 = 0x1.6b7338p-10f;
37   const float vc5 = 0x1.12278Ep-7f;
38   const float vc4 = 0x1.555716p-5f;
39   const float vc3 = 0x1.5554B0p-3f;
40   const float vc2 = 0x1.FFFFFEp-2f;
41   const float vone = 1.0f;
42 
43   do {
44     float vx = *x++;
45 
46     const float vz = vx * vprescale;
47 
48     float vn = vz * vlog2e + vmagic_bias;
49     float vs = fp32_from_bits(fp32_to_bits(vn) << 23);
50     vn -= vmagic_bias;
51 
52     float vt = vn * vminus_ln2_hi + vz;
53     vt = vn * vminus_ln2_lo + vt;
54 
55     if XNN_UNPREDICTABLE(vz <= vsat_cutoff) {
56       vs = 0.0f;
57       vt = 0.0f;
58     }
59 
60     float vp = vc6 * vt + vc5;
61     vp = vp * vt + vc4;
62     vp = vp * vt + vc3;
63     vp = vp * vt + vc2;
64     vp *= vt;
65 
66     vt *= vs;
67     vs -= vone;
68     vp = vp * vt + vt;
69     const float ve = (vp + vs) * valpha;
70 
71     float vy = vx * vbeta;
72     if XNN_UNPREDICTABLE(vx < 0.0f) {
73       vy = ve;
74     }
75 
76     *y++ = vy;
77 
78     n -= sizeof(float);
79   } while (n != 0);
80 }
81