1 // Auto-generated file. Do not edit! 2 // Template: src/f32-velu/scalar-rr2-lut16-p3.c.in 3 // Generator: tools/xngen 4 // 5 // Copyright 2020 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 extern XNN_INTERNAL const uint32_t xnn_table_exp2minus_k_over_16[16]; 20 xnn_f32_velu_ukernel__scalar_rr2_lut16_p3_x2(size_t n,const float * x,float * y,const union xnn_f32_elu_params params[restrict XNN_MIN_ELEMENTS (1)])21void xnn_f32_velu_ukernel__scalar_rr2_lut16_p3_x2( 22 size_t n, 23 const float* x, 24 float* y, 25 const union xnn_f32_elu_params params[restrict XNN_MIN_ELEMENTS(1)]) 26 { 27 assert(n % sizeof(float) == 0); 28 29 const float vprescale = params->scalar_rr2_lut16_p3.prescale; 30 const float valpha = params->scalar_rr2_lut16_p3.alpha; 31 const float vbeta = params->scalar_rr2_lut16_p3.beta; 32 const float vmagic_bias = params->scalar_rr2_lut16_p3.magic_bias; 33 const float vlog2e = params->scalar_rr2_lut16_p3.log2e; 34 const uint32_t vindex_mask = UINT32_C(0xF); 35 const float vsat_cutoff = params->scalar_rr2_lut16_p3.sat_cutoff; 36 const float vminus_ln2_hi = params->scalar_rr2_lut16_p3.minus_ln2_hi; 37 const float vminus_ln2_lo = params->scalar_rr2_lut16_p3.minus_ln2_lo; 38 const float vc3 = params->scalar_rr2_lut16_p3.c3; 39 const float vc2 = params->scalar_rr2_lut16_p3.c2; 40 const float vone = params->scalar_rr2_lut16_p3.one; 41 42 for (; n >= 2 * sizeof(float); n -= 2 * sizeof(float)) { 43 float vx0 = x[0]; 44 float vx1 = x[1]; 45 x += 2; 46 47 const float vz0 = vx0 * vprescale; 48 const float vz1 = vx1 * vprescale; 49 50 float vn0 = vz0 * vlog2e + vmagic_bias; 51 float vn1 = vz1 * vlog2e + vmagic_bias; 52 53 const uint32_t ven0 = fp32_to_bits(vn0) << 19; 54 const uint32_t vidx0 = fp32_to_bits(vn0) & vindex_mask; 55 vn0 -= vmagic_bias; 56 const uint32_t ven1 = fp32_to_bits(vn1) << 19; 57 const uint32_t vidx1 = fp32_to_bits(vn1) & vindex_mask; 58 vn1 -= vmagic_bias; 59 60 float vt0 = vn0 * vminus_ln2_hi + vz0; 61 float vs0 = fp32_from_bits(xnn_table_exp2minus_k_over_16[vidx0] + ven0); 62 float vt1 = vn1 * vminus_ln2_hi + vz1; 63 float vs1 = fp32_from_bits(xnn_table_exp2minus_k_over_16[vidx1] + ven1); 64 65 vt0 = vn0 * vminus_ln2_lo + vt0; 66 if XNN_UNPREDICTABLE(vz0 <= vsat_cutoff) { 67 vs0 = 0.0f; 68 vt0 = 0.0f; 69 } 70 vt1 = vn1 * vminus_ln2_lo + vt1; 71 if XNN_UNPREDICTABLE(vz1 <= vsat_cutoff) { 72 vs1 = 0.0f; 73 vt1 = 0.0f; 74 } 75 76 float vp0 = vc3 * vt0 + vc2; 77 float vp1 = vc3 * vt1 + vc2; 78 79 vp0 *= vt0; 80 vp1 *= vt1; 81 82 vt0 *= vs0; 83 vs0 -= vone; 84 vt1 *= vs1; 85 vs1 -= vone; 86 87 vp0 = vp0 * vt0 + vt0; 88 vp1 = vp1 * vt1 + vt1; 89 90 const float ve0 = (vp0 + vs0) * valpha; 91 float vy0 = vx0 * vbeta; 92 const float ve1 = (vp1 + vs1) * valpha; 93 float vy1 = vx1 * vbeta; 94 95 if XNN_UNPREDICTABLE(vx0 < 0.0f) { 96 vy0 = ve0; 97 } 98 if XNN_UNPREDICTABLE(vx1 < 0.0f) { 99 vy1 = ve1; 100 } 101 102 y[0] = vy0; 103 y[1] = vy1; 104 y += 2; 105 } 106 if XNN_UNLIKELY(n != 0) { 107 float vx = *x; 108 109 const float vz = vx * vprescale; 110 111 float vn = vz * vlog2e + vmagic_bias; 112 const uint32_t ven = fp32_to_bits(vn) << 19; 113 const uint32_t vidx = fp32_to_bits(vn) & vindex_mask; 114 vn -= vmagic_bias; 115 116 float vt = vn * vminus_ln2_hi + vz; 117 float vs = fp32_from_bits(xnn_table_exp2minus_k_over_16[vidx] + ven); 118 119 vt = vn * vminus_ln2_lo + vt; 120 if XNN_UNPREDICTABLE(vz <= vsat_cutoff) { 121 vs = 0.0f; 122 vt = 0.0f; 123 } 124 125 float vp = vc3 * vt + vc2; 126 vp *= vt; 127 128 vt *= vs; 129 vs -= vone; 130 vp = vp * vt + vt; 131 const float ve = (vp + vs) * valpha; 132 133 float vy = vx * vbeta; 134 if XNN_UNPREDICTABLE(vx < 0.0f) { 135 vy = ve; 136 } 137 138 *y = vy; 139 } 140 } 141