1 // Auto-generated file. Do not edit! 2 // Template: src/f32-sigmoid/scalar-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_sigmoid_ukernel__scalar_lut2048_p1_div_x1(size_t n,const float * x,float * y,const void * params)22void xnn_f32_sigmoid_ukernel__scalar_lut2048_p1_div_x1( 23 size_t n, 24 const float* x, 25 float* y, 26 const void* params) 27 { 28 assert(n % sizeof(float) == 0); 29 30 const float vmagic_bias = 0x1.800000p12f; 31 const float vminus_log2e = -0x1.715476p0f; 32 const uint32_t vindex_mask = UINT32_C(0x7FF); 33 const float vln2_hi = 0x1.600000p-1f; 34 const float vln2_lo = 0x1.7217F8p-8f; 35 const float vc1 = -0x1.FFFFFEp-1f; 36 const float vone = 1.0f; 37 const float vdenorm_cutoff = 0x1.5D589Ep+6f; 38 39 do { 40 const float vx = *x++; 41 42 const float vz = fabsf(vx); 43 44 float vn = vz * vminus_log2e + vmagic_bias; 45 const uint32_t ve = fp32_to_bits(vn) << 12; 46 const uint32_t vidx = fp32_to_bits(vn) & vindex_mask; 47 const float vs = fp32_from_bits(xnn_table_exp2minus_k_over_2048[vidx] + ve); 48 vn -= vmagic_bias; 49 50 float vt = vn * vln2_hi + vz; 51 vt = vn * vln2_lo + vt; 52 53 const float vp = vt * vc1; 54 const float vy = vp * vs + vs; 55 56 const float vd = vy + vone; 57 float vf = vy / vd; 58 if XNN_UNPREDICTABLE(vz > vdenorm_cutoff) { 59 vf = 0.0f; 60 } 61 if XNN_UNPREDICTABLE(vx > 0.0f) { 62 vf = vone - vf; 63 } 64 65 *y++ = vf; 66 67 n -= sizeof(float); 68 } while (n != 0); 69 } 70