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_x3(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_x3( 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 >= 3 * sizeof(float); n -= 3 * sizeof(float)) { 42 float vx0 = x[0]; 43 float vx1 = x[1]; 44 float vx2 = x[2]; 45 x += 3; 46 47 const float vz0 = vx0 * vprescale; 48 const float vz1 = vx1 * vprescale; 49 const float vz2 = vx2 * vprescale; 50 51 float vn0 = vz0 * vlog2e + vmagic_bias; 52 float vn1 = vz1 * vlog2e + vmagic_bias; 53 float vn2 = vz2 * vlog2e + vmagic_bias; 54 55 const uint32_t ven0 = float_as_uint32(vn0) << 19; 56 const uint32_t vidx0 = float_as_uint32(vn0) & vindex_mask; 57 vn0 -= vmagic_bias; 58 const uint32_t ven1 = float_as_uint32(vn1) << 19; 59 const uint32_t vidx1 = float_as_uint32(vn1) & vindex_mask; 60 vn1 -= vmagic_bias; 61 const uint32_t ven2 = float_as_uint32(vn2) << 19; 62 const uint32_t vidx2 = float_as_uint32(vn2) & vindex_mask; 63 vn2 -= vmagic_bias; 64 65 float vt0 = vn0 * vminus_ln2_hi + vz0; 66 float vs0 = uint32_as_float(xnn_table_exp2minus_k_over_16[vidx0] + ven0); 67 float vt1 = vn1 * vminus_ln2_hi + vz1; 68 float vs1 = uint32_as_float(xnn_table_exp2minus_k_over_16[vidx1] + ven1); 69 float vt2 = vn2 * vminus_ln2_hi + vz2; 70 float vs2 = uint32_as_float(xnn_table_exp2minus_k_over_16[vidx2] + ven2); 71 72 vt0 = vn0 * vminus_ln2_lo + vt0; 73 if XNN_UNPREDICTABLE(vz0 <= vsat_cutoff) { 74 vs0 = 0.0f; 75 vt0 = 0.0f; 76 } 77 vt1 = vn1 * vminus_ln2_lo + vt1; 78 if XNN_UNPREDICTABLE(vz1 <= vsat_cutoff) { 79 vs1 = 0.0f; 80 vt1 = 0.0f; 81 } 82 vt2 = vn2 * vminus_ln2_lo + vt2; 83 if XNN_UNPREDICTABLE(vz2 <= vsat_cutoff) { 84 vs2 = 0.0f; 85 vt2 = 0.0f; 86 } 87 88 float vp0 = vc3 * vt0 + vc2; 89 float vp1 = vc3 * vt1 + vc2; 90 float vp2 = vc3 * vt2 + vc2; 91 92 vp0 *= vt0; 93 vp1 *= vt1; 94 vp2 *= vt2; 95 96 vt0 *= vs0; 97 vs0 -= vone; 98 vt1 *= vs1; 99 vs1 -= vone; 100 vt2 *= vs2; 101 vs2 -= vone; 102 103 vp0 = vp0 * vt0 + vt0; 104 vp1 = vp1 * vt1 + vt1; 105 vp2 = vp2 * vt2 + vt2; 106 107 const float ve0 = (vp0 + vs0) * valpha; 108 float vy0 = vx0 * vbeta; 109 const float ve1 = (vp1 + vs1) * valpha; 110 float vy1 = vx1 * vbeta; 111 const float ve2 = (vp2 + vs2) * valpha; 112 float vy2 = vx2 * vbeta; 113 114 if XNN_UNPREDICTABLE(vx0 < 0.0f) { 115 vy0 = ve0; 116 } 117 if XNN_UNPREDICTABLE(vx1 < 0.0f) { 118 vy1 = ve1; 119 } 120 if XNN_UNPREDICTABLE(vx2 < 0.0f) { 121 vy2 = ve2; 122 } 123 124 y[0] = vy0; 125 y[1] = vy1; 126 y[2] = vy2; 127 y += 3; 128 } 129 if XNN_UNLIKELY(n != 0) { 130 do { 131 float vx = *x++; 132 133 const float vz = vx * vprescale; 134 135 float vn = vz * vlog2e + vmagic_bias; 136 const uint32_t ven = float_as_uint32(vn) << 19; 137 const uint32_t vidx = float_as_uint32(vn) & vindex_mask; 138 vn -= vmagic_bias; 139 140 float vt = vn * vminus_ln2_hi + vz; 141 float vs = uint32_as_float(xnn_table_exp2minus_k_over_16[vidx] + ven); 142 143 vt = vn * vminus_ln2_lo + vt; 144 if XNN_UNPREDICTABLE(vz <= vsat_cutoff) { 145 vs = 0.0f; 146 vt = 0.0f; 147 } 148 149 float vp = vc3 * vt + vc2; 150 vp *= vt; 151 152 vt *= vs; 153 vs -= vone; 154 vp = vp * vt + vt; 155 const float ve = (vp + vs) * valpha; 156 157 float vy = vx * vbeta; 158 if XNN_UNPREDICTABLE(vx < 0.0f) { 159 vy = ve; 160 } 161 162 *y++ = vy; 163 164 n -= sizeof(float); 165 } while (n != 0); 166 } 167 } 168