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