| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
#include <assert.h> |
| 11 |
|
| 12 |
#include <arm_neon.h> |
| 13 |
|
| 14 |
#include "xnnpack/vunary.h" |
| 15 |
#include "xnnpack/common.h" |
| 16 |
|
| 17 |
|
| 18 |
void xnn_f32_velu_ukernel__neon_rr2_p6_u12( |
| 19 |
size_t batch, |
| 20 |
const float* input, |
| 21 |
float* output, |
| 22 |
const struct xnn_f32_elu_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS |
| 23 |
{ |
| 24 |
assert(batch != 0); |
| 25 |
assert(batch % sizeof(float) == 0); |
| 26 |
assert(input != NULL); |
| 27 |
assert(output != NULL); |
| 28 |
|
| 29 |
const float32x4_t vsat_cutoff = vmovq_n_f32(-0x1.154246p+4f); |
| 30 |
const float32x4_t vmagic_bias = vmovq_n_f32(0x1.8000FEp23f); |
| 31 |
const float32x4_t vlog2e = vmovq_n_f32(0x1.715476p+0f); |
| 32 |
const float32x4_t vc6 = vmovq_n_f32(0x1.6b7338p-10f); |
| 33 |
const float32x4_t vc5 = vmovq_n_f32(0x1.12278Ep-7f); |
| 34 |
const float32x4_t vc4 = vmovq_n_f32(0x1.555716p-5f); |
| 35 |
const float32x4_t vc3 = vmovq_n_f32(0x1.5554B0p-3f); |
| 36 |
const float32x4_t vc2 = vmovq_n_f32(0x1.FFFFFEp-2f); |
| 37 |
const float32x4_t vone = vmovq_n_f32(1.0f); |
| 38 |
|
| 39 |
XNN_FORCE_REALIZATION(vsat_cutoff); |
| 40 |
XNN_FORCE_REALIZATION(vmagic_bias); |
| 41 |
XNN_FORCE_REALIZATION(vlog2e); |
| 42 |
XNN_FORCE_REALIZATION(vc6); |
| 43 |
XNN_FORCE_REALIZATION(vc5); |
| 44 |
XNN_FORCE_REALIZATION(vc4); |
| 45 |
XNN_FORCE_REALIZATION(vc3); |
| 46 |
XNN_FORCE_REALIZATION(vc2); |
| 47 |
XNN_FORCE_REALIZATION(vone); |
| 48 |
|
| 49 |
const float32x4_t vminus_ln2_hi = vmovq_n_f32(-0x1.62E440p-1f); |
| 50 |
const float32x4_t vminus_ln2_lo = vmovq_n_f32(0x1.0105C6p-21f); |
| 51 |
XNN_FORCE_REALIZATION(vminus_ln2_hi); |
| 52 |
XNN_FORCE_REALIZATION(vminus_ln2_lo); |
| 53 |
|
| 54 |
const float32x4_t vprescale = vld1q_dup_f32(¶ms->scalar.prescale); |
| 55 |
const float32x4_t valpha = vld1q_dup_f32(¶ms->scalar.alpha); |
| 56 |
const float32x4_t vbeta = vld1q_dup_f32(¶ms->scalar.beta); |
| 57 |
|
| 58 |
for (; batch >= 12 * sizeof(float); batch -= 12 * sizeof(float)) { |
| 59 |
float32x4_t vx0123 = vld1q_f32(input); input += 4; |
| 60 |
float32x4_t vx4567 = vld1q_f32(input); input += 4; |
| 61 |
float32x4_t vx89AB = vld1q_f32(input); input += 4; |
| 62 |
|
| 63 |
const float32x4_t vz0123 = vmaxq_f32(vmulq_f32(vx0123, vprescale), vsat_cutoff); |
| 64 |
const float32x4_t vz4567 = vmaxq_f32(vmulq_f32(vx4567, vprescale), vsat_cutoff); |
| 65 |
const float32x4_t vz89AB = vmaxq_f32(vmulq_f32(vx89AB, vprescale), vsat_cutoff); |
| 66 |
|
| 67 |
float32x4_t vn0123 = vmlaq_f32(vmagic_bias, vz0123, vlog2e); |
| 68 |
float32x4_t vn4567 = vmlaq_f32(vmagic_bias, vz4567, vlog2e); |
| 69 |
float32x4_t vn89AB = vmlaq_f32(vmagic_bias, vz89AB, vlog2e); |
| 70 |
|
| 71 |
float32x4_t vs0123 = vreinterpretq_f32_s32(vshlq_n_s32(vreinterpretq_s32_f32(vn0123), 23)); |
| 72 |
vn0123 = vsubq_f32(vn0123, vmagic_bias); |
| 73 |
float32x4_t vs4567 = vreinterpretq_f32_s32(vshlq_n_s32(vreinterpretq_s32_f32(vn4567), 23)); |
| 74 |
vn4567 = vsubq_f32(vn4567, vmagic_bias); |
| 75 |
float32x4_t vs89AB = vreinterpretq_f32_s32(vshlq_n_s32(vreinterpretq_s32_f32(vn89AB), 23)); |
| 76 |
vn89AB = vsubq_f32(vn89AB, vmagic_bias); |
| 77 |
|
| 78 |
float32x4_t vt0123 = vmlaq_f32(vz0123, vn0123, vminus_ln2_hi); |
| 79 |
float32x4_t vt4567 = vmlaq_f32(vz4567, vn4567, vminus_ln2_hi); |
| 80 |
float32x4_t vt89AB = vmlaq_f32(vz89AB, vn89AB, vminus_ln2_hi); |
| 81 |
|
| 82 |
vt0123 = vmlaq_f32(vt0123, vn0123, vminus_ln2_lo); |
| 83 |
vt4567 = vmlaq_f32(vt4567, vn4567, vminus_ln2_lo); |
| 84 |
vt89AB = vmlaq_f32(vt89AB, vn89AB, vminus_ln2_lo); |
| 85 |
|
| 86 |
float32x4_t vp0123 = vmlaq_f32(vc5, vc6, vt0123); |
| 87 |
float32x4_t vp4567 = vmlaq_f32(vc5, vc6, vt4567); |
| 88 |
float32x4_t vp89AB = vmlaq_f32(vc5, vc6, vt89AB); |
| 89 |
|
| 90 |
vp0123 = vmlaq_f32(vc4, vp0123, vt0123); |
| 91 |
vp4567 = vmlaq_f32(vc4, vp4567, vt4567); |
| 92 |
vp89AB = vmlaq_f32(vc4, vp89AB, vt89AB); |
| 93 |
|
| 94 |
vp0123 = vmlaq_f32(vc3, vp0123, vt0123); |
| 95 |
vp4567 = vmlaq_f32(vc3, vp4567, vt4567); |
| 96 |
vp89AB = vmlaq_f32(vc3, vp89AB, vt89AB); |
| 97 |
|
| 98 |
vp0123 = vmlaq_f32(vc2, vp0123, vt0123); |
| 99 |
vp4567 = vmlaq_f32(vc2, vp4567, vt4567); |
| 100 |
vp89AB = vmlaq_f32(vc2, vp89AB, vt89AB); |
| 101 |
|
| 102 |
vp0123 = vmulq_f32(vp0123, vt0123); |
| 103 |
vp4567 = vmulq_f32(vp4567, vt4567); |
| 104 |
vp89AB = vmulq_f32(vp89AB, vt89AB); |
| 105 |
|
| 106 |
vt0123 = vmulq_f32(vt0123, vs0123); |
| 107 |
vs0123 = vsubq_f32(vs0123, vone); |
| 108 |
vt4567 = vmulq_f32(vt4567, vs4567); |
| 109 |
vs4567 = vsubq_f32(vs4567, vone); |
| 110 |
vt89AB = vmulq_f32(vt89AB, vs89AB); |
| 111 |
vs89AB = vsubq_f32(vs89AB, vone); |
| 112 |
|
| 113 |
vp0123 = vmlaq_f32(vt0123, vp0123, vt0123); |
| 114 |
vp4567 = vmlaq_f32(vt4567, vp4567, vt4567); |
| 115 |
vp89AB = vmlaq_f32(vt89AB, vp89AB, vt89AB); |
| 116 |
|
| 117 |
const float32x4_t ve0123 = vmulq_f32(vaddq_f32(vp0123, vs0123), valpha); |
| 118 |
const float32x4_t ve4567 = vmulq_f32(vaddq_f32(vp4567, vs4567), valpha); |
| 119 |
const float32x4_t ve89AB = vmulq_f32(vaddq_f32(vp89AB, vs89AB), valpha); |
| 120 |
|
| 121 |
const uint32x4_t vm0123 = vcltq_f32(vx0123, vmovq_n_f32(0.0f)); |
| 122 |
vx0123 = vmulq_f32(vx0123, vbeta); |
| 123 |
const uint32x4_t vm4567 = vcltq_f32(vx4567, vmovq_n_f32(0.0f)); |
| 124 |
vx4567 = vmulq_f32(vx4567, vbeta); |
| 125 |
const uint32x4_t vm89AB = vcltq_f32(vx89AB, vmovq_n_f32(0.0f)); |
| 126 |
vx89AB = vmulq_f32(vx89AB, vbeta); |
| 127 |
|
| 128 |
const float32x4_t vy0123 = vbslq_f32(vm0123, ve0123, vx0123); |
| 129 |
const float32x4_t vy4567 = vbslq_f32(vm4567, ve4567, vx4567); |
| 130 |
const float32x4_t vy89AB = vbslq_f32(vm89AB, ve89AB, vx89AB); |
| 131 |
|
| 132 |
vst1q_f32(output, vy0123); output += 4; |
| 133 |
vst1q_f32(output, vy4567); output += 4; |
| 134 |
vst1q_f32(output, vy89AB); output += 4; |
| 135 |
} |
| 136 |
for (; batch >= 4 * sizeof(float); batch -= 4 * sizeof(float)) { |
| 137 |
float32x4_t vx = vld1q_f32(input); input += 4; |
| 138 |
|
| 139 |
const float32x4_t vz = vmaxq_f32(vmulq_f32(vx, vprescale), vsat_cutoff); |
| 140 |
|
| 141 |
float32x4_t vn = vmlaq_f32(vmagic_bias, vz, vlog2e); |
| 142 |
float32x4_t vs = vreinterpretq_f32_s32(vshlq_n_s32(vreinterpretq_s32_f32(vn), 23)); |
| 143 |
vn = vsubq_f32(vn, vmagic_bias); |
| 144 |
|
| 145 |
float32x4_t vt = vmlaq_f32(vz, vn, vminus_ln2_hi); |
| 146 |
vt = vmlaq_f32(vt, vn, vminus_ln2_lo); |
| 147 |
|
| 148 |
float32x4_t vp = vmlaq_f32(vc5, vc6, vt); |
| 149 |
vp = vmlaq_f32(vc4, vp, vt); |
| 150 |
vp = vmlaq_f32(vc3, vp, vt); |
| 151 |
vp = vmlaq_f32(vc2, vp, vt); |
| 152 |
vp = vmulq_f32(vp, vt); |
| 153 |
|
| 154 |
vt = vmulq_f32(vt, vs); |
| 155 |
vs = vsubq_f32(vs, vone); |
| 156 |
vp = vmlaq_f32(vt, vp, vt); |
| 157 |
const float32x4_t ve = vmulq_f32(vaddq_f32(vp, vs), valpha); |
| 158 |
|
| 159 |
const uint32x4_t vm = vcltq_f32(vx, vmovq_n_f32(0.0f)); |
| 160 |
vx = vmulq_f32(vx, vbeta); |
| 161 |
const float32x4_t vy = vbslq_f32(vm, ve, vx); |
| 162 |
|
| 163 |
vst1q_f32(output, vy); output += 4; |
| 164 |
} |
| 165 |
if XNN_UNLIKELY(batch != 0) { |
| 166 |
float32x4_t vx = vld1q_f32(input); |
| 167 |
|
| 168 |
const float32x4_t vz = vmaxq_f32(vmulq_f32(vx, vprescale), vsat_cutoff); |
| 169 |
|
| 170 |
float32x4_t vn = vmlaq_f32(vmagic_bias, vz, vlog2e); |
| 171 |
float32x4_t vs = vreinterpretq_f32_s32(vshlq_n_s32(vreinterpretq_s32_f32(vn), 23)); |
| 172 |
vn = vsubq_f32(vn, vmagic_bias); |
| 173 |
|
| 174 |
float32x4_t vt = vmlaq_f32(vz, vn, vminus_ln2_hi); |
| 175 |
vt = vmlaq_f32(vt, vn, vminus_ln2_lo); |
| 176 |
|
| 177 |
float32x4_t vp = vmlaq_f32(vc5, vc6, vt); |
| 178 |
vp = vmlaq_f32(vc4, vp, vt); |
| 179 |
vp = vmlaq_f32(vc3, vp, vt); |
| 180 |
vp = vmlaq_f32(vc2, vp, vt); |
| 181 |
vp = vmulq_f32(vp, vt); |
| 182 |
|
| 183 |
vt = vmulq_f32(vt, vs); |
| 184 |
vs = vsubq_f32(vs, vone); |
| 185 |
vp = vmlaq_f32(vt, vp, vt); |
| 186 |
const float32x4_t ve = vmulq_f32(vaddq_f32(vp, vs), valpha); |
| 187 |
|
| 188 |
const uint32x4_t vm = vcltq_f32(vx, vmovq_n_f32(0.0f)); |
| 189 |
vx = vmulq_f32(vx, vbeta); |
| 190 |
const float32x4_t vy = vbslq_f32(vm, ve, vx); |
| 191 |
|
| 192 |
float32x2_t vy_lo = vget_low_f32(vy); |
| 193 |
if (batch & (2 * sizeof(float))) { |
| 194 |
vst1_f32(output, vy_lo); output += 2; |
| 195 |
vy_lo = vget_high_f32(vy); |
| 196 |
} |
| 197 |
if (batch & (1 * sizeof(float))) { |
| 198 |
vst1_lane_f32(output, vy_lo, 0); |
| 199 |
} |
| 200 |
} |
| 201 |
} |