xref: /aosp_15_r20/external/XNNPACK/src/f32-vsigmoid/gen/vsigmoid-scalar-rr2-p5-div-x1.c (revision 4bdc94577ba0e567308109d787f7fec7b531ce36)
1 // Auto-generated file. Do not edit!
2 //   Template: src/f32-vsigmoid/scalar-rr2-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/math.h>
15 #include <xnnpack/vunary.h>
16 
17 
xnn_f32_vsigmoid_ukernel__scalar_rr2_p5_div_x1(size_t n,const float * x,float * y,const union xnn_f32_sigmoid_params params[restrict XNN_MIN_ELEMENTS (1)])18 void xnn_f32_vsigmoid_ukernel__scalar_rr2_p5_div_x1(
19     size_t n,
20     const float* x,
21     float* y,
22     const union xnn_f32_sigmoid_params params[restrict XNN_MIN_ELEMENTS(1)])
23 {
24   assert(n % sizeof(float) == 0);
25 
26   const float vmagic_bias = params->scalar_rr2_p5.magic_bias;
27   const float vminus_log2e = params->scalar_rr2_p5.minus_log2e;
28   const float vln2_hi = params->scalar_rr2_p5.ln2_hi;
29   const float vln2_lo = params->scalar_rr2_p5.ln2_lo;
30   const float vc5 = params->scalar_rr2_p5.c5;
31   const float vc4 = params->scalar_rr2_p5.c4;
32   const float vc3 = params->scalar_rr2_p5.c3;
33   const float vc2 = params->scalar_rr2_p5.c2;
34   const float vc1 = params->scalar_rr2_p5.c1;
35   const float vone = params->scalar_rr2_p5.one;
36   const float vdenorm_cutoff = params->scalar_rr2_p5.denorm_cutoff;
37 
38   do {
39     const float vx = *x++;
40 
41     const float vz = fabsf(vx);
42 
43     float vn = vz * vminus_log2e + vmagic_bias;
44     const float vs = uint32_as_float(float_as_uint32(vn) << 23);
45     vn -= vmagic_bias;
46 
47     float vt = vn * vln2_hi + vz;
48     vt = vn * vln2_lo + vt;
49 
50     float vp = vt * vc5 + vc4;
51     vp = vt * vp + vc3;
52     vp = vt * vp + vc2;
53     vp = vt * vp + vc1;
54 
55     vt *= vs;
56     const float ve = vt * vp + vs;
57     const float vd = ve + vone;
58 
59     float vf = ve / vd;
60     if XNN_UNPREDICTABLE(vz > vdenorm_cutoff) {
61       vf = 0.0f;
62     }
63     if XNN_UNPREDICTABLE(vx > 0.0f) {
64       vf = vone - vf;
65     }
66 
67     *y++ = vf;
68 
69     n -= sizeof(float);
70   } while (n != 0);
71 }
72