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_x4(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_x4( 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 >= 4 * sizeof(float); n -= 4 * sizeof(float)) { 40 const float vx0 = x[0]; 41 const float vx1 = x[1]; 42 const float vx2 = x[2]; 43 const float vx3 = x[3]; 44 x += 4; 45 46 const float vz0 = fabsf(vx0); 47 const float vz1 = fabsf(vx1); 48 const float vz2 = fabsf(vx2); 49 const float vz3 = fabsf(vx3); 50 51 float vn0 = vz0 * vminus_log2e + vmagic_bias; 52 float vn1 = vz1 * vminus_log2e + vmagic_bias; 53 float vn2 = vz2 * vminus_log2e + vmagic_bias; 54 float vn3 = vz3 * vminus_log2e + vmagic_bias; 55 56 const float vs0 = fp32_from_bits(fp32_to_bits(vn0) << 23); 57 const float vs1 = fp32_from_bits(fp32_to_bits(vn1) << 23); 58 const float vs2 = fp32_from_bits(fp32_to_bits(vn2) << 23); 59 const float vs3 = fp32_from_bits(fp32_to_bits(vn3) << 23); 60 61 vn0 -= vmagic_bias; 62 vn1 -= vmagic_bias; 63 vn2 -= vmagic_bias; 64 vn3 -= vmagic_bias; 65 66 float vt0 = vn0 * vln2_hi + vz0; 67 float vt1 = vn1 * vln2_hi + vz1; 68 float vt2 = vn2 * vln2_hi + vz2; 69 float vt3 = vn3 * vln2_hi + vz3; 70 71 vt0 = vn0 * vln2_lo + vt0; 72 vt1 = vn1 * vln2_lo + vt1; 73 vt2 = vn2 * vln2_lo + vt2; 74 vt3 = vn3 * vln2_lo + vt3; 75 76 float vp0 = vt0 * vc5 + vc4; 77 float vp1 = vt1 * vc5 + vc4; 78 float vp2 = vt2 * vc5 + vc4; 79 float vp3 = vt3 * vc5 + vc4; 80 81 vp0 = vt0 * vp0 + vc3; 82 vp1 = vt1 * vp1 + vc3; 83 vp2 = vt2 * vp2 + vc3; 84 vp3 = vt3 * vp3 + vc3; 85 86 vp0 = vt0 * vp0 + vc2; 87 vp1 = vt1 * vp1 + vc2; 88 vp2 = vt2 * vp2 + vc2; 89 vp3 = vt3 * vp3 + vc2; 90 91 vp0 = vt0 * vp0 + vc1; 92 vp1 = vt1 * vp1 + vc1; 93 vp2 = vt2 * vp2 + vc1; 94 vp3 = vt3 * vp3 + vc1; 95 96 vt0 *= vs0; 97 vt1 *= vs1; 98 vt2 *= vs2; 99 vt3 *= vs3; 100 101 const float ve0 = vt0 * vp0 + vs0; 102 const float ve1 = vt1 * vp1 + vs1; 103 const float ve2 = vt2 * vp2 + vs2; 104 const float ve3 = vt3 * vp3 + vs3; 105 106 const float vd0 = ve0 + vone; 107 const float vd1 = ve1 + vone; 108 const float vd2 = ve2 + vone; 109 const float vd3 = ve3 + vone; 110 111 float vf0 = ve0 / vd0; 112 float vf1 = ve1 / vd1; 113 float vf2 = ve2 / vd2; 114 float vf3 = ve3 / vd3; 115 116 if XNN_UNPREDICTABLE(vz0 > vdenorm_cutoff) { 117 vf0 = 0.0f; 118 } 119 if XNN_UNPREDICTABLE(vz1 > vdenorm_cutoff) { 120 vf1 = 0.0f; 121 } 122 if XNN_UNPREDICTABLE(vz2 > vdenorm_cutoff) { 123 vf2 = 0.0f; 124 } 125 if XNN_UNPREDICTABLE(vz3 > vdenorm_cutoff) { 126 vf3 = 0.0f; 127 } 128 129 if XNN_UNPREDICTABLE(vx0 > 0.0f) { 130 vf0 = vone - vf0; 131 } 132 if XNN_UNPREDICTABLE(vx1 > 0.0f) { 133 vf1 = vone - vf1; 134 } 135 if XNN_UNPREDICTABLE(vx2 > 0.0f) { 136 vf2 = vone - vf2; 137 } 138 if XNN_UNPREDICTABLE(vx3 > 0.0f) { 139 vf3 = vone - vf3; 140 } 141 142 y[0] = vf0; 143 y[1] = vf1; 144 y[2] = vf2; 145 y[3] = vf3; 146 y += 4; 147 } 148 if XNN_UNLIKELY(n != 0) { 149 do { 150 const float vx = *x++; 151 152 const float vz = fabsf(vx); 153 154 float vn = vz * vminus_log2e + vmagic_bias; 155 const float vs = fp32_from_bits(fp32_to_bits(vn) << 23); 156 vn -= vmagic_bias; 157 158 float vt = vn * vln2_hi + vz; 159 vt = vn * vln2_lo + vt; 160 161 float vp = vt * vc5 + vc4; 162 vp = vt * vp + vc3; 163 vp = vt * vp + vc2; 164 vp = vt * vp + vc1; 165 166 vt *= vs; 167 const float ve = vt * vp + vs; 168 const float vd = ve + vone; 169 170 float vf = ve / vd; 171 if XNN_UNPREDICTABLE(vz > vdenorm_cutoff) { 172 vf = 0.0f; 173 } 174 if XNN_UNPREDICTABLE(vx > 0.0f) { 175 vf = vone - vf; 176 } 177 178 *y++ = vf; 179 180 n -= sizeof(float); 181 } while (n != 0); 182 } 183 } 184