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_x2(size_t n,const float * x,float * y,const union xnn_f32_sigmoid_params params[restrict XNN_MIN_ELEMENTS (1)])18void xnn_f32_vsigmoid_ukernel__scalar_rr2_p5_div_x2( 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 for (; n >= 2 * sizeof(float); n -= 2 * sizeof(float)) { 39 const float vx0 = x[0]; 40 const float vx1 = x[1]; 41 x += 2; 42 43 const float vz0 = fabsf(vx0); 44 const float vz1 = fabsf(vx1); 45 46 float vn0 = vz0 * vminus_log2e + vmagic_bias; 47 float vn1 = vz1 * vminus_log2e + vmagic_bias; 48 49 const float vs0 = uint32_as_float(float_as_uint32(vn0) << 23); 50 const float vs1 = uint32_as_float(float_as_uint32(vn1) << 23); 51 52 vn0 -= vmagic_bias; 53 vn1 -= vmagic_bias; 54 55 float vt0 = vn0 * vln2_hi + vz0; 56 float vt1 = vn1 * vln2_hi + vz1; 57 58 vt0 = vn0 * vln2_lo + vt0; 59 vt1 = vn1 * vln2_lo + vt1; 60 61 float vp0 = vt0 * vc5 + vc4; 62 float vp1 = vt1 * vc5 + vc4; 63 64 vp0 = vt0 * vp0 + vc3; 65 vp1 = vt1 * vp1 + vc3; 66 67 vp0 = vt0 * vp0 + vc2; 68 vp1 = vt1 * vp1 + vc2; 69 70 vp0 = vt0 * vp0 + vc1; 71 vp1 = vt1 * vp1 + vc1; 72 73 vt0 *= vs0; 74 vt1 *= vs1; 75 76 const float ve0 = vt0 * vp0 + vs0; 77 const float ve1 = vt1 * vp1 + vs1; 78 79 const float vd0 = ve0 + vone; 80 const float vd1 = ve1 + vone; 81 82 float vf0 = ve0 / vd0; 83 float vf1 = ve1 / vd1; 84 85 if XNN_UNPREDICTABLE(vz0 > vdenorm_cutoff) { 86 vf0 = 0.0f; 87 } 88 if XNN_UNPREDICTABLE(vz1 > vdenorm_cutoff) { 89 vf1 = 0.0f; 90 } 91 92 if XNN_UNPREDICTABLE(vx0 > 0.0f) { 93 vf0 = vone - vf0; 94 } 95 if XNN_UNPREDICTABLE(vx1 > 0.0f) { 96 vf1 = vone - vf1; 97 } 98 99 y[0] = vf0; 100 y[1] = vf1; 101 y += 2; 102 } 103 if XNN_UNLIKELY(n != 0) { 104 const float vx = *x; 105 106 const float vz = fabsf(vx); 107 108 float vn = vz * vminus_log2e + vmagic_bias; 109 const float vs = uint32_as_float(float_as_uint32(vn) << 23); 110 vn -= vmagic_bias; 111 112 float vt = vn * vln2_hi + vz; 113 vt = vn * vln2_lo + vt; 114 115 float vp = vt * vc5 + vc4; 116 vp = vt * vp + vc3; 117 vp = vt * vp + vc2; 118 vp = vt * vp + vc1; 119 120 vt *= vs; 121 const float ve = vt * vp + vs; 122 const float vd = ve + vone; 123 124 float vf = ve / vd; 125 if XNN_UNPREDICTABLE(vz > vdenorm_cutoff) { 126 vf = 0.0f; 127 } 128 if XNN_UNPREDICTABLE(vx > 0.0f) { 129 vf = vone - vf; 130 } 131 132 *y = vf; 133 } 134 } 135