• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Auto-generated file. Do not edit!
2 //   Template: src/f32-sigmoid/scalar-p5-div.c.in
3 //   Generator: tools/xngen
4 //
5 // Copyright 2019 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_sigmoid_ukernel__scalar_p5_div_x1(size_t n,const float * x,float * y,const void * params)19 void xnn_f32_sigmoid_ukernel__scalar_p5_div_x1(
20     size_t n,
21     const float* x,
22     float* y,
23     const void* params)
24 {
25   assert(n % sizeof(float) == 0);
26 
27   const float vmagic_bias = 0x1.8000FEp23f;
28   const float vminus_log2e = -0x1.715476p+0f;
29   const float vln2_hi = 0x1.62E400p-1f;
30   const float vln2_lo = 0x1.7F7D1Cp-20f;
31   const float vc5 = -0x1.0F9F9Cp-7f;
32   const float vc4 =  0x1.573A1Ap-5f;
33   const float vc3 = -0x1.555A80p-3f;
34   const float vc2 =  0x1.FFFDC6p-2f;
35   const float vc1 = -0x1.FFFFF6p-1f;
36   const float vone = 1.0f;
37   const float vdenorm_cutoff = 0x1.5D589Ep+6f;
38 
39   do {
40     const float vx = *x++;
41 
42     const float vz = fabsf(vx);
43 
44     float vn = vz * vminus_log2e + vmagic_bias;
45     const float vs = fp32_from_bits(fp32_to_bits(vn) << 23);
46     vn -= vmagic_bias;
47 
48     float vt = vn * vln2_hi + vz;
49     vt = vn * vln2_lo + vt;
50 
51     float vp = vt * vc5 + vc4;
52     vp = vt * vp + vc3;
53     vp = vt * vp + vc2;
54     vp = vt * vp + vc1;
55 
56     vt *= vs;
57     const float ve = vt * vp + vs;
58     const float vd = ve + vone;
59 
60     float vf = ve / vd;
61     if XNN_UNPREDICTABLE(vz > vdenorm_cutoff) {
62       vf = 0.0f;
63     }
64     if XNN_UNPREDICTABLE(vx > 0.0f) {
65       vf = vone - vf;
66     }
67 
68     *y++ = vf;
69 
70     n -= sizeof(float);
71   } while (n != 0);
72 }
73