1 // Auto-generated file. Do not edit! 2 // Template: src/f32-vsigmoid/scalar-rr2-lut2048-p1-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 19 // Note redefine as uint32[] to avoid redundant bitcasts. 20 extern XNN_INTERNAL const uint32_t xnn_table_exp2minus_k_over_2048[2048]; 21 xnn_f32_vsigmoid_ukernel__scalar_rr2_lut2048_p1_div_x2(size_t n,const float * x,float * y,const union xnn_f32_sigmoid_params params[restrict XNN_MIN_ELEMENTS (1)])22void xnn_f32_vsigmoid_ukernel__scalar_rr2_lut2048_p1_div_x2( 23 size_t n, 24 const float* x, 25 float* y, 26 const union xnn_f32_sigmoid_params params[restrict XNN_MIN_ELEMENTS(1)]) 27 { 28 assert(n % sizeof(float) == 0); 29 30 const float vmagic_bias = params->scalar_rr2_lut2048_p1.magic_bias; 31 const float vminus_log2e = params->scalar_rr2_lut2048_p1.minus_log2e; 32 const uint32_t vindex_mask = UINT32_C(0x7FF); 33 const float vln2_hi = params->scalar_rr2_lut2048_p1.ln2_hi; 34 const float vln2_lo = params->scalar_rr2_lut2048_p1.ln2_lo; 35 const float vc1 = params->scalar_rr2_lut2048_p1.c1; 36 const float vone = params->scalar_rr2_lut2048_p1.one; 37 const float vdenorm_cutoff = params->scalar_rr2_lut2048_p1.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 uint32_t ve0 = fp32_to_bits(vn0) << 12; 51 const uint32_t ve1 = fp32_to_bits(vn1) << 12; 52 53 const uint32_t vidx0 = fp32_to_bits(vn0) & vindex_mask; 54 const float vs0 = fp32_from_bits(xnn_table_exp2minus_k_over_2048[vidx0] + ve0); 55 const uint32_t vidx1 = fp32_to_bits(vn1) & vindex_mask; 56 const float vs1 = fp32_from_bits(xnn_table_exp2minus_k_over_2048[vidx1] + ve1); 57 58 vn0 -= vmagic_bias; 59 vn1 -= vmagic_bias; 60 61 float vt0 = vn0 * vln2_hi + vz0; 62 float vt1 = vn1 * vln2_hi + vz1; 63 64 vt0 = vn0 * vln2_lo + vt0; 65 vt1 = vn1 * vln2_lo + vt1; 66 67 const float vp0 = vt0 * vc1; 68 const float vp1 = vt1 * vc1; 69 70 const float vy0 = vp0 * vs0 + vs0; 71 const float vy1 = vp1 * vs1 + vs1; 72 73 const float vd0 = vy0 + vone; 74 const float vd1 = vy1 + vone; 75 76 float vf0 = vy0 / vd0; 77 float vf1 = vy1 / vd1; 78 79 if XNN_UNPREDICTABLE(vz0 > vdenorm_cutoff) { 80 vf0 = 0.0f; 81 } 82 if XNN_UNPREDICTABLE(vz1 > vdenorm_cutoff) { 83 vf1 = 0.0f; 84 } 85 86 if XNN_UNPREDICTABLE(vx0 > 0.0f) { 87 vf0 = vone - vf0; 88 } 89 if XNN_UNPREDICTABLE(vx1 > 0.0f) { 90 vf1 = vone - vf1; 91 } 92 93 y[0] = vf0; 94 y[1] = vf1; 95 y += 2; 96 } 97 if XNN_UNLIKELY(n != 0) { 98 const float vx = *x; 99 100 const float vz = fabsf(vx); 101 102 float vn = vz * vminus_log2e + vmagic_bias; 103 const uint32_t ve = fp32_to_bits(vn) << 12; 104 const uint32_t vidx = fp32_to_bits(vn) & vindex_mask; 105 const float vs = fp32_from_bits(xnn_table_exp2minus_k_over_2048[vidx] + ve); 106 vn -= vmagic_bias; 107 108 float vt = vn * vln2_hi + vz; 109 vt = vn * vln2_lo + vt; 110 111 const float vp = vt * vc1; 112 const float vy = vp * vs + vs; 113 114 const float vd = vy + vone; 115 float vf = vy / vd; 116 if XNN_UNPREDICTABLE(vz > vdenorm_cutoff) { 117 vf = 0.0f; 118 } 119 if XNN_UNPREDICTABLE(vx > 0.0f) { 120 vf = vone - vf; 121 } 122 123 *y = vf; 124 } 125 } 126