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_x1(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_x1( 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 do { 43 float vx = *x++; 44 45 const float vz = vx * vprescale; 46 47 float vn = vz * vlog2e + vmagic_bias; 48 const uint32_t ven = fp32_to_bits(vn) << 19; 49 const uint32_t vidx = fp32_to_bits(vn) & vindex_mask; 50 vn -= vmagic_bias; 51 52 float vt = vn * vminus_ln2_hi + vz; 53 float vs = fp32_from_bits(xnn_table_exp2minus_k_over_16[vidx] + ven); 54 55 vt = vn * vminus_ln2_lo + vt; 56 if XNN_UNPREDICTABLE(vz <= vsat_cutoff) { 57 vs = 0.0f; 58 vt = 0.0f; 59 } 60 61 float vp = vc3 * vt + vc2; 62 vp *= vt; 63 64 vt *= vs; 65 vs -= vone; 66 vp = vp * vt + vt; 67 const float ve = (vp + vs) * valpha; 68 69 float vy = vx * vbeta; 70 if XNN_UNPREDICTABLE(vx < 0.0f) { 71 vy = ve; 72 } 73 74 *y++ = vy; 75 76 n -= sizeof(float); 77 } while (n != 0); 78 } 79