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