1 // Auto-generated file. Do not edit! 2 // Template: src/f32-velu/scalar-rr2-p6.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 xnn_f32_velu_ukernel__scalar_rr2_p6_x6(size_t n,const float * x,float * y,const union xnn_f32_elu_params params[restrict XNN_MIN_ELEMENTS (1)])19void xnn_f32_velu_ukernel__scalar_rr2_p6_x6( 20 size_t n, 21 const float* x, 22 float* y, 23 const union xnn_f32_elu_params params[restrict XNN_MIN_ELEMENTS(1)]) 24 { 25 assert(n % sizeof(float) == 0); 26 27 const float vprescale = params->scalar.prescale; 28 const float valpha = params->scalar.alpha; 29 const float vbeta = params->scalar.beta; 30 31 const float vmagic_bias = 0x1.8000FEp23f; 32 const float vlog2e = 0x1.715476p+0f; 33 const float vsat_cutoff = -0x1.154246p+4f; 34 const float vminus_ln2_hi = -0x1.62E440p-1f; 35 const float vminus_ln2_lo = 0x1.0105C6p-21f; 36 const float vc6 = 0x1.6b7338p-10f; 37 const float vc5 = 0x1.12278Ep-7f; 38 const float vc4 = 0x1.555716p-5f; 39 const float vc3 = 0x1.5554B0p-3f; 40 const float vc2 = 0x1.FFFFFEp-2f; 41 const float vone = 1.0f; 42 43 for (; n >= 6 * sizeof(float); n -= 6 * sizeof(float)) { 44 float vx0 = x[0]; 45 float vx1 = x[1]; 46 float vx2 = x[2]; 47 float vx3 = x[3]; 48 float vx4 = x[4]; 49 float vx5 = x[5]; 50 x += 6; 51 52 const float vz0 = vx0 * vprescale; 53 const float vz1 = vx1 * vprescale; 54 const float vz2 = vx2 * vprescale; 55 const float vz3 = vx3 * vprescale; 56 const float vz4 = vx4 * vprescale; 57 const float vz5 = vx5 * vprescale; 58 59 float vn0 = vz0 * vlog2e + vmagic_bias; 60 float vn1 = vz1 * vlog2e + vmagic_bias; 61 float vn2 = vz2 * vlog2e + vmagic_bias; 62 float vn3 = vz3 * vlog2e + vmagic_bias; 63 float vn4 = vz4 * vlog2e + vmagic_bias; 64 float vn5 = vz5 * vlog2e + vmagic_bias; 65 66 float vs0 = fp32_from_bits(fp32_to_bits(vn0) << 23); 67 vn0 -= vmagic_bias; 68 float vs1 = fp32_from_bits(fp32_to_bits(vn1) << 23); 69 vn1 -= vmagic_bias; 70 float vs2 = fp32_from_bits(fp32_to_bits(vn2) << 23); 71 vn2 -= vmagic_bias; 72 float vs3 = fp32_from_bits(fp32_to_bits(vn3) << 23); 73 vn3 -= vmagic_bias; 74 float vs4 = fp32_from_bits(fp32_to_bits(vn4) << 23); 75 vn4 -= vmagic_bias; 76 float vs5 = fp32_from_bits(fp32_to_bits(vn5) << 23); 77 vn5 -= vmagic_bias; 78 79 float vt0 = vn0 * vminus_ln2_hi + vz0; 80 float vt1 = vn1 * vminus_ln2_hi + vz1; 81 float vt2 = vn2 * vminus_ln2_hi + vz2; 82 float vt3 = vn3 * vminus_ln2_hi + vz3; 83 float vt4 = vn4 * vminus_ln2_hi + vz4; 84 float vt5 = vn5 * vminus_ln2_hi + vz5; 85 86 vt0 = vn0 * vminus_ln2_lo + vt0; 87 vt1 = vn1 * vminus_ln2_lo + vt1; 88 vt2 = vn2 * vminus_ln2_lo + vt2; 89 vt3 = vn3 * vminus_ln2_lo + vt3; 90 vt4 = vn4 * vminus_ln2_lo + vt4; 91 vt5 = vn5 * vminus_ln2_lo + vt5; 92 93 if XNN_UNPREDICTABLE(vz0 <= vsat_cutoff) { 94 vs0 = 0.0f; 95 vt0 = 0.0f; 96 } 97 if XNN_UNPREDICTABLE(vz1 <= vsat_cutoff) { 98 vs1 = 0.0f; 99 vt1 = 0.0f; 100 } 101 if XNN_UNPREDICTABLE(vz2 <= vsat_cutoff) { 102 vs2 = 0.0f; 103 vt2 = 0.0f; 104 } 105 if XNN_UNPREDICTABLE(vz3 <= vsat_cutoff) { 106 vs3 = 0.0f; 107 vt3 = 0.0f; 108 } 109 if XNN_UNPREDICTABLE(vz4 <= vsat_cutoff) { 110 vs4 = 0.0f; 111 vt4 = 0.0f; 112 } 113 if XNN_UNPREDICTABLE(vz5 <= vsat_cutoff) { 114 vs5 = 0.0f; 115 vt5 = 0.0f; 116 } 117 118 float vp0 = vc6 * vt0 + vc5; 119 float vp1 = vc6 * vt1 + vc5; 120 float vp2 = vc6 * vt2 + vc5; 121 float vp3 = vc6 * vt3 + vc5; 122 float vp4 = vc6 * vt4 + vc5; 123 float vp5 = vc6 * vt5 + vc5; 124 125 vp0 = vp0 * vt0 + vc4; 126 vp1 = vp1 * vt1 + vc4; 127 vp2 = vp2 * vt2 + vc4; 128 vp3 = vp3 * vt3 + vc4; 129 vp4 = vp4 * vt4 + vc4; 130 vp5 = vp5 * vt5 + vc4; 131 132 vp0 = vp0 * vt0 + vc3; 133 vp1 = vp1 * vt1 + vc3; 134 vp2 = vp2 * vt2 + vc3; 135 vp3 = vp3 * vt3 + vc3; 136 vp4 = vp4 * vt4 + vc3; 137 vp5 = vp5 * vt5 + vc3; 138 139 vp0 = vp0 * vt0 + vc2; 140 vp1 = vp1 * vt1 + vc2; 141 vp2 = vp2 * vt2 + vc2; 142 vp3 = vp3 * vt3 + vc2; 143 vp4 = vp4 * vt4 + vc2; 144 vp5 = vp5 * vt5 + vc2; 145 146 vp0 *= vt0; 147 vp1 *= vt1; 148 vp2 *= vt2; 149 vp3 *= vt3; 150 vp4 *= vt4; 151 vp5 *= vt5; 152 153 vt0 *= vs0; 154 vs0 -= vone; 155 vt1 *= vs1; 156 vs1 -= vone; 157 vt2 *= vs2; 158 vs2 -= vone; 159 vt3 *= vs3; 160 vs3 -= vone; 161 vt4 *= vs4; 162 vs4 -= vone; 163 vt5 *= vs5; 164 vs5 -= vone; 165 166 vp0 = vp0 * vt0 + vt0; 167 vp1 = vp1 * vt1 + vt1; 168 vp2 = vp2 * vt2 + vt2; 169 vp3 = vp3 * vt3 + vt3; 170 vp4 = vp4 * vt4 + vt4; 171 vp5 = vp5 * vt5 + vt5; 172 173 const float ve0 = (vp0 + vs0) * valpha; 174 float vy0 = vx0 * vbeta; 175 const float ve1 = (vp1 + vs1) * valpha; 176 float vy1 = vx1 * vbeta; 177 const float ve2 = (vp2 + vs2) * valpha; 178 float vy2 = vx2 * vbeta; 179 const float ve3 = (vp3 + vs3) * valpha; 180 float vy3 = vx3 * vbeta; 181 const float ve4 = (vp4 + vs4) * valpha; 182 float vy4 = vx4 * vbeta; 183 const float ve5 = (vp5 + vs5) * valpha; 184 float vy5 = vx5 * vbeta; 185 186 if XNN_UNPREDICTABLE(vx0 < 0.0f) { 187 vy0 = ve0; 188 } 189 if XNN_UNPREDICTABLE(vx1 < 0.0f) { 190 vy1 = ve1; 191 } 192 if XNN_UNPREDICTABLE(vx2 < 0.0f) { 193 vy2 = ve2; 194 } 195 if XNN_UNPREDICTABLE(vx3 < 0.0f) { 196 vy3 = ve3; 197 } 198 if XNN_UNPREDICTABLE(vx4 < 0.0f) { 199 vy4 = ve4; 200 } 201 if XNN_UNPREDICTABLE(vx5 < 0.0f) { 202 vy5 = ve5; 203 } 204 205 y[0] = vy0; 206 y[1] = vy1; 207 y[2] = vy2; 208 y[3] = vy3; 209 y[4] = vy4; 210 y[5] = vy5; 211 y += 6; 212 } 213 if XNN_UNLIKELY(n != 0) { 214 do { 215 float vx = *x++; 216 217 const float vz = vx * vprescale; 218 219 float vn = vz * vlog2e + vmagic_bias; 220 float vs = fp32_from_bits(fp32_to_bits(vn) << 23); 221 vn -= vmagic_bias; 222 223 float vt = vn * vminus_ln2_hi + vz; 224 vt = vn * vminus_ln2_lo + vt; 225 226 if XNN_UNPREDICTABLE(vz <= vsat_cutoff) { 227 vs = 0.0f; 228 vt = 0.0f; 229 } 230 231 float vp = vc6 * vt + vc5; 232 vp = vp * vt + vc4; 233 vp = vp * vt + vc3; 234 vp = vp * vt + vc2; 235 vp *= vt; 236 237 vt *= vs; 238 vs -= vone; 239 vp = vp * vt + vt; 240 const float ve = (vp + vs) * valpha; 241 242 float vy = vx * vbeta; 243 if XNN_UNPREDICTABLE(vx < 0.0f) { 244 vy = ve; 245 } 246 247 *y++ = vy; 248 249 n -= sizeof(float); 250 } while (n != 0); 251 } 252 } 253