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/vunary.h> 15 16 #include <fp16/bitcasts.h> 17 18 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)])19void xnn_f32_vsigmoid_ukernel__scalar_rr2_p5_div_x2( 20 size_t n, 21 const float* x, 22 float* y, 23 const union xnn_f32_sigmoid_params params[restrict XNN_MIN_ELEMENTS(1)]) 24 { 25 assert(n % sizeof(float) == 0); 26 27 const float vmagic_bias = params->scalar_rr2_p5.magic_bias; 28 const float vminus_log2e = params->scalar_rr2_p5.minus_log2e; 29 const float vln2_hi = params->scalar_rr2_p5.ln2_hi; 30 const float vln2_lo = params->scalar_rr2_p5.ln2_lo; 31 const float vc5 = params->scalar_rr2_p5.c5; 32 const float vc4 = params->scalar_rr2_p5.c4; 33 const float vc3 = params->scalar_rr2_p5.c3; 34 const float vc2 = params->scalar_rr2_p5.c2; 35 const float vc1 = params->scalar_rr2_p5.c1; 36 const float vone = params->scalar_rr2_p5.one; 37 const float vdenorm_cutoff = params->scalar_rr2_p5.denorm_cutoff; 38 39 for (; n >= 2 * sizeof(float); n -= 2 * sizeof(float)) { 40 const float vx0 = x[0]; 41 const float vx1 = x[1]; 42 x += 2; 43 44 const float vz0 = fabsf(vx0); 45 const float vz1 = fabsf(vx1); 46 47 float vn0 = vz0 * vminus_log2e + vmagic_bias; 48 float vn1 = vz1 * vminus_log2e + vmagic_bias; 49 50 const float vs0 = fp32_from_bits(fp32_to_bits(vn0) << 23); 51 const float vs1 = fp32_from_bits(fp32_to_bits(vn1) << 23); 52 53 vn0 -= vmagic_bias; 54 vn1 -= vmagic_bias; 55 56 float vt0 = vn0 * vln2_hi + vz0; 57 float vt1 = vn1 * vln2_hi + vz1; 58 59 vt0 = vn0 * vln2_lo + vt0; 60 vt1 = vn1 * vln2_lo + vt1; 61 62 float vp0 = vt0 * vc5 + vc4; 63 float vp1 = vt1 * vc5 + vc4; 64 65 vp0 = vt0 * vp0 + vc3; 66 vp1 = vt1 * vp1 + vc3; 67 68 vp0 = vt0 * vp0 + vc2; 69 vp1 = vt1 * vp1 + vc2; 70 71 vp0 = vt0 * vp0 + vc1; 72 vp1 = vt1 * vp1 + vc1; 73 74 vt0 *= vs0; 75 vt1 *= vs1; 76 77 const float ve0 = vt0 * vp0 + vs0; 78 const float ve1 = vt1 * vp1 + vs1; 79 80 const float vd0 = ve0 + vone; 81 const float vd1 = ve1 + vone; 82 83 float vf0 = ve0 / vd0; 84 float vf1 = ve1 / vd1; 85 86 if XNN_UNPREDICTABLE(vz0 > vdenorm_cutoff) { 87 vf0 = 0.0f; 88 } 89 if XNN_UNPREDICTABLE(vz1 > vdenorm_cutoff) { 90 vf1 = 0.0f; 91 } 92 93 if XNN_UNPREDICTABLE(vx0 > 0.0f) { 94 vf0 = vone - vf0; 95 } 96 if XNN_UNPREDICTABLE(vx1 > 0.0f) { 97 vf1 = vone - vf1; 98 } 99 100 y[0] = vf0; 101 y[1] = vf1; 102 y += 2; 103 } 104 if XNN_UNLIKELY(n != 0) { 105 const float vx = *x; 106 107 const float vz = fabsf(vx); 108 109 float vn = vz * vminus_log2e + vmagic_bias; 110 const float vs = fp32_from_bits(fp32_to_bits(vn) << 23); 111 vn -= vmagic_bias; 112 113 float vt = vn * vln2_hi + vz; 114 vt = vn * vln2_lo + vt; 115 116 float vp = vt * vc5 + vc4; 117 vp = vt * vp + vc3; 118 vp = vt * vp + vc2; 119 vp = vt * vp + vc1; 120 121 vt *= vs; 122 const float ve = vt * vp + vs; 123 const float vd = ve + vone; 124 125 float vf = ve / vd; 126 if XNN_UNPREDICTABLE(vz > vdenorm_cutoff) { 127 vf = 0.0f; 128 } 129 if XNN_UNPREDICTABLE(vx > 0.0f) { 130 vf = vone - vf; 131 } 132 133 *y = vf; 134 } 135 } 136