| 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 |
extern XNN_INTERNAL const uint32_t xnn_table_exp2minus_k_over_16[16]; |
| 19 |
|
| 20 |
void xnn_f32_velu_ukernel__wasm_rr2_lut16_p3_u1( |
| 21 |
size_t batch, |
| 22 |
const float* input, |
| 23 |
float* output, |
| 24 |
const struct xnn_f32_elu_params params[restrict XNN_MIN_ELEMENTS(1)]) |
| 25 |
{ |
| 26 |
assert(batch != 0); |
| 27 |
assert(batch % sizeof(float) == 0); |
| 28 |
assert(input != NULL); |
| 29 |
assert(output != NULL); |
| 30 |
|
| 31 |
const float vsat_cutoff = -0x1.154246p+4f; |
| 32 |
const float vmagic_bias = 0x1.800000p19f; |
| 33 |
const float vlog2e = 0x1.715476p+0f; |
| 34 |
const float vminus_ln2_hi = -0x1.62E400p-1f; |
| 35 |
const float vminus_ln2_lo = -0x1.7F7D1Cp-20f; |
| 36 |
const uint32_t vindex_mask = UINT32_C(0xF); |
| 37 |
const float vc3 = 0x1.55561Cp-3f; |
| 38 |
const float vc2 = 0x1.0001ECp-1f; |
| 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 |
do { |
| 46 |
float vx = *input++; |
| 47 |
|
| 48 |
const float vz = __builtin_wasm_min_f32(__builtin_wasm_max_f32(vx * vprescale, vsat_cutoff), 0.0f); |
| 49 |
|
| 50 |
float vn = vz * vlog2e + vmagic_bias; |
| 51 |
const uint32_t ven = float_as_uint32(vn) << 19; |
| 52 |
const uint32_t vidx = float_as_uint32(vn) & vindex_mask; |
| 53 |
vn -= vmagic_bias; |
| 54 |
|
| 55 |
float vt = vn * vminus_ln2_hi + vz; |
| 56 |
float vs = uint32_as_float(xnn_table_exp2minus_k_over_16[vidx] + ven); |
| 57 |
|
| 58 |
vt = vn * vminus_ln2_lo + vt; |
| 59 |
|
| 60 |
float vp = vc3 * vt + vc2; |
| 61 |
vp *= vt; |
| 62 |
|
| 63 |
vt *= vs; |
| 64 |
vs -= vone; |
| 65 |
vp = vp * vt + vt; |
| 66 |
const float ve = (vp + vs) * valpha; |
| 67 |
|
| 68 |
float vy = __builtin_wasm_max_f32(vx * vbeta, 0.0f); |
| 69 |
vy += __builtin_wasm_min_f32(ve, 0.0f); |
| 70 |
|
| 71 |
*output++ = vy; |
| 72 |
|
| 73 |
batch -= sizeof(float); |
| 74 |
} while (batch != 0); |
| 75 |
} |