xref: /aosp_15_r20/external/XNNPACK/src/f32-vsigmoid/gen/vsigmoid-scalar-rr2-lut64-p2-div-x1.c (revision 4bdc94577ba0e567308109d787f7fec7b531ce36)
1 // Auto-generated file. Do not edit!
2 //   Template: src/f32-vsigmoid/scalar-rr2-lut64-p2-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 
18 // Note redefine as uint32[] to avoid redundant bitcasts.
19 extern XNN_INTERNAL const uint32_t xnn_table_exp2minus_k_over_64[64];
20 
xnn_f32_vsigmoid_ukernel__scalar_rr2_lut64_p2_div_x1(size_t n,const float * x,float * y,const union xnn_f32_sigmoid_params params[restrict XNN_MIN_ELEMENTS (1)])21 void xnn_f32_vsigmoid_ukernel__scalar_rr2_lut64_p2_div_x1(
22     size_t n,
23     const float* x,
24     float* y,
25     const union xnn_f32_sigmoid_params params[restrict XNN_MIN_ELEMENTS(1)])
26 {
27   assert(n % sizeof(float) == 0);
28 
29   const float vmagic_bias = params->scalar_rr2_lut64_p2.magic_bias;
30   const float vminus_log2e = params->scalar_rr2_lut64_p2.minus_log2e;
31   const uint32_t vindex_mask = UINT32_C(0x3F);
32   const float vln2_hi = params->scalar_rr2_lut64_p2.ln2_hi;
33   const float vln2_lo = params->scalar_rr2_lut64_p2.ln2_lo;
34   const float vc2 = params->scalar_rr2_lut64_p2.c2;
35   const float vone = params->scalar_rr2_lut64_p2.one;
36   const float vdenorm_cutoff = params->scalar_rr2_lut64_p2.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 uint32_t ve = float_as_uint32(vn) << 17;
45     const uint32_t vidx = float_as_uint32(vn) & vindex_mask;
46     const float vs = uint32_as_float(xnn_table_exp2minus_k_over_64[vidx] + ve);
47     vn -= vmagic_bias;
48 
49     float vt = vn * vln2_hi + vz;
50     vt = vn * vln2_lo + vt;
51 
52     float vp = vt * vc2;
53     vp = vt - vp * vt;
54 
55     const float vy = vs - vs * vp;
56     const float vd = vy + vone;
57 
58     float vf = vy / vd;
59     if XNN_UNPREDICTABLE(vz > vdenorm_cutoff) {
60       vf = 0.0f;
61     }
62     if XNN_UNPREDICTABLE(vx > 0.0f) {
63       vf = vone - vf;
64     }
65 
66     *y++ = vf;
67 
68     n -= sizeof(float);
69   } while (n != 0);
70 }
71