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