| 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 |
extern XNN_INTERNAL const uint32_t xnn_table_exp2minus_k_over_16[16]; |
| 19 |
|
| 20 |
void xnn_f32_velu_ukernel__neonfma_rr1_lut16_p3_u24( |
| 21 |
size_t batch, |
| 22 |
const float* input, |
| 23 |
float* output, |
| 24 |
const struct xnn_f32_elu_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS |
| 25 |
{ |
| 26 |
assert(batch != 0); |
| 27 |
assert(batch % sizeof(float) == 0); |
| 28 |
assert(input != NULL); |
| 29 |
assert(output != NULL); |
| 30 |
|
| 31 |
const float32x4_t vsat_cutoff = vmovq_n_f32(-0x1.154246p+4f); |
| 32 |
const float32x4_t vmagic_bias = vmovq_n_f32(0x1.800000p19f); |
| 33 |
const float32x4_t vlog2e = vmovq_n_f32(0x1.715476p+0f); |
| 34 |
const int32x4_t vindex_mask = vmovq_n_s32(INT32_C(0xF)); |
| 35 |
const float32x4_t vc3 = vmovq_n_f32(0x1.55561Cp-3f); |
| 36 |
const float32x4_t vc2 = vmovq_n_f32(0x1.0001ECp-1f); |
| 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(vc3); |
| 43 |
XNN_FORCE_REALIZATION(vc2); |
| 44 |
XNN_FORCE_REALIZATION(vone); |
| 45 |
|
| 46 |
const float32x4_t vminus_ln2 = vmovq_n_f32(-0x1.62E430p-1f); |
| 47 |
XNN_FORCE_REALIZATION(vminus_ln2); |
| 48 |
|
| 49 |
const float32x4_t vprescale = vld1q_dup_f32(¶ms->scalar.prescale); |
| 50 |
const float32x4_t valpha = vld1q_dup_f32(¶ms->scalar.alpha); |
| 51 |
const float32x4_t vbeta = vld1q_dup_f32(¶ms->scalar.beta); |
| 52 |
|
| 53 |
for (; batch >= 24 * sizeof(float); batch -= 24 * sizeof(float)) { |
| 54 |
float32x4_t vx0123 = vld1q_f32(input); input += 4; |
| 55 |
float32x4_t vx4567 = vld1q_f32(input); input += 4; |
| 56 |
float32x4_t vx89AB = vld1q_f32(input); input += 4; |
| 57 |
float32x4_t vxCDEF = vld1q_f32(input); input += 4; |
| 58 |
float32x4_t vxGHIJ = vld1q_f32(input); input += 4; |
| 59 |
float32x4_t vxKLMN = vld1q_f32(input); input += 4; |
| 60 |
|
| 61 |
const float32x4_t vz0123 = vmaxq_f32(vmulq_f32(vx0123, vprescale), vsat_cutoff); |
| 62 |
const float32x4_t vz4567 = vmaxq_f32(vmulq_f32(vx4567, vprescale), vsat_cutoff); |
| 63 |
const float32x4_t vz89AB = vmaxq_f32(vmulq_f32(vx89AB, vprescale), vsat_cutoff); |
| 64 |
const float32x4_t vzCDEF = vmaxq_f32(vmulq_f32(vxCDEF, vprescale), vsat_cutoff); |
| 65 |
const float32x4_t vzGHIJ = vmaxq_f32(vmulq_f32(vxGHIJ, vprescale), vsat_cutoff); |
| 66 |
const float32x4_t vzKLMN = vmaxq_f32(vmulq_f32(vxKLMN, vprescale), vsat_cutoff); |
| 67 |
|
| 68 |
float32x4_t vn0123 = vfmaq_f32(vmagic_bias, vz0123, vlog2e); |
| 69 |
float32x4_t vn4567 = vfmaq_f32(vmagic_bias, vz4567, vlog2e); |
| 70 |
float32x4_t vn89AB = vfmaq_f32(vmagic_bias, vz89AB, vlog2e); |
| 71 |
float32x4_t vnCDEF = vfmaq_f32(vmagic_bias, vzCDEF, vlog2e); |
| 72 |
float32x4_t vnGHIJ = vfmaq_f32(vmagic_bias, vzGHIJ, vlog2e); |
| 73 |
float32x4_t vnKLMN = vfmaq_f32(vmagic_bias, vzKLMN, vlog2e); |
| 74 |
|
| 75 |
const uint64x2_t vidx0123 = vreinterpretq_u64_s32(vshlq_n_s32(vandq_s32(vreinterpretq_s32_f32(vn0123), vindex_mask), 2)); |
| 76 |
const int32x4_t ven0123 = vshlq_n_s32(vreinterpretq_s32_f32(vn0123), 19); |
| 77 |
const uint64x2_t vidx4567 = vreinterpretq_u64_s32(vshlq_n_s32(vandq_s32(vreinterpretq_s32_f32(vn4567), vindex_mask), 2)); |
| 78 |
const int32x4_t ven4567 = vshlq_n_s32(vreinterpretq_s32_f32(vn4567), 19); |
| 79 |
const uint64x2_t vidx89AB = vreinterpretq_u64_s32(vshlq_n_s32(vandq_s32(vreinterpretq_s32_f32(vn89AB), vindex_mask), 2)); |
| 80 |
const int32x4_t ven89AB = vshlq_n_s32(vreinterpretq_s32_f32(vn89AB), 19); |
| 81 |
const uint64x2_t vidxCDEF = vreinterpretq_u64_s32(vshlq_n_s32(vandq_s32(vreinterpretq_s32_f32(vnCDEF), vindex_mask), 2)); |
| 82 |
const int32x4_t venCDEF = vshlq_n_s32(vreinterpretq_s32_f32(vnCDEF), 19); |
| 83 |
const uint64x2_t vidxGHIJ = vreinterpretq_u64_s32(vshlq_n_s32(vandq_s32(vreinterpretq_s32_f32(vnGHIJ), vindex_mask), 2)); |
| 84 |
const int32x4_t venGHIJ = vshlq_n_s32(vreinterpretq_s32_f32(vnGHIJ), 19); |
| 85 |
const uint64x2_t vidxKLMN = vreinterpretq_u64_s32(vshlq_n_s32(vandq_s32(vreinterpretq_s32_f32(vnKLMN), vindex_mask), 2)); |
| 86 |
const int32x4_t venKLMN = vshlq_n_s32(vreinterpretq_s32_f32(vnKLMN), 19); |
| 87 |
|
| 88 |
const uint64_t vidx01 = vgetq_lane_u64(vidx0123, 0); |
| 89 |
const uint64_t vidx23 = vgetq_lane_u64(vidx0123, 1); |
| 90 |
int32x2_t vl01 = vld1_dup_s32((const int32_t*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidx01)); |
| 91 |
int32x2_t vl23 = vld1_dup_s32((const int32_t*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidx23)); |
| 92 |
vl01 = vld1_lane_s32((const int32_t*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) (vidx01 >> 32)), vl01, 1); |
| 93 |
vl23 = vld1_lane_s32((const int32_t*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) (vidx23 >> 32)), vl23, 1); |
| 94 |
const int32x4_t vl0123 = vcombine_s32(vl01, vl23); |
| 95 |
const uint64_t vidx45 = vgetq_lane_u64(vidx4567, 0); |
| 96 |
const uint64_t vidx67 = vgetq_lane_u64(vidx4567, 1); |
| 97 |
int32x2_t vl45 = vld1_dup_s32((const int32_t*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidx45)); |
| 98 |
int32x2_t vl67 = vld1_dup_s32((const int32_t*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidx67)); |
| 99 |
vl45 = vld1_lane_s32((const int32_t*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) (vidx45 >> 32)), vl45, 1); |
| 100 |
vl67 = vld1_lane_s32((const int32_t*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) (vidx67 >> 32)), vl67, 1); |
| 101 |
const int32x4_t vl4567 = vcombine_s32(vl45, vl67); |
| 102 |
const uint64_t vidx89 = vgetq_lane_u64(vidx89AB, 0); |
| 103 |
const uint64_t vidxAB = vgetq_lane_u64(vidx89AB, 1); |
| 104 |
int32x2_t vl89 = vld1_dup_s32((const int32_t*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidx89)); |
| 105 |
int32x2_t vlAB = vld1_dup_s32((const int32_t*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidxAB)); |
| 106 |
vl89 = vld1_lane_s32((const int32_t*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) (vidx89 >> 32)), vl89, 1); |
| 107 |
vlAB = vld1_lane_s32((const int32_t*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) (vidxAB >> 32)), vlAB, 1); |
| 108 |
const int32x4_t vl89AB = vcombine_s32(vl89, vlAB); |
| 109 |
const uint64_t vidxCD = vgetq_lane_u64(vidxCDEF, 0); |
| 110 |
const uint64_t vidxEF = vgetq_lane_u64(vidxCDEF, 1); |
| 111 |
int32x2_t vlCD = vld1_dup_s32((const int32_t*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidxCD)); |
| 112 |
int32x2_t vlEF = vld1_dup_s32((const int32_t*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidxEF)); |
| 113 |
vlCD = vld1_lane_s32((const int32_t*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) (vidxCD >> 32)), vlCD, 1); |
| 114 |
vlEF = vld1_lane_s32((const int32_t*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) (vidxEF >> 32)), vlEF, 1); |
| 115 |
const int32x4_t vlCDEF = vcombine_s32(vlCD, vlEF); |
| 116 |
const uint64_t vidxGH = vgetq_lane_u64(vidxGHIJ, 0); |
| 117 |
const uint64_t vidxIJ = vgetq_lane_u64(vidxGHIJ, 1); |
| 118 |
int32x2_t vlGH = vld1_dup_s32((const int32_t*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidxGH)); |
| 119 |
int32x2_t vlIJ = vld1_dup_s32((const int32_t*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidxIJ)); |
| 120 |
vlGH = vld1_lane_s32((const int32_t*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) (vidxGH >> 32)), vlGH, 1); |
| 121 |
vlIJ = vld1_lane_s32((const int32_t*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) (vidxIJ >> 32)), vlIJ, 1); |
| 122 |
const int32x4_t vlGHIJ = vcombine_s32(vlGH, vlIJ); |
| 123 |
const uint64_t vidxKL = vgetq_lane_u64(vidxKLMN, 0); |
| 124 |
const uint64_t vidxMN = vgetq_lane_u64(vidxKLMN, 1); |
| 125 |
int32x2_t vlKL = vld1_dup_s32((const int32_t*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidxKL)); |
| 126 |
int32x2_t vlMN = vld1_dup_s32((const int32_t*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidxMN)); |
| 127 |
vlKL = vld1_lane_s32((const int32_t*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) (vidxKL >> 32)), vlKL, 1); |
| 128 |
vlMN = vld1_lane_s32((const int32_t*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) (vidxMN >> 32)), vlMN, 1); |
| 129 |
const int32x4_t vlKLMN = vcombine_s32(vlKL, vlMN); |
| 130 |
|
| 131 |
vn0123 = vsubq_f32(vn0123, vmagic_bias); |
| 132 |
float32x4_t vs0123 = vreinterpretq_f32_s32(vaddq_s32(vl0123, ven0123)); |
| 133 |
vn4567 = vsubq_f32(vn4567, vmagic_bias); |
| 134 |
float32x4_t vs4567 = vreinterpretq_f32_s32(vaddq_s32(vl4567, ven4567)); |
| 135 |
vn89AB = vsubq_f32(vn89AB, vmagic_bias); |
| 136 |
float32x4_t vs89AB = vreinterpretq_f32_s32(vaddq_s32(vl89AB, ven89AB)); |
| 137 |
vnCDEF = vsubq_f32(vnCDEF, vmagic_bias); |
| 138 |
float32x4_t vsCDEF = vreinterpretq_f32_s32(vaddq_s32(vlCDEF, venCDEF)); |
| 139 |
vnGHIJ = vsubq_f32(vnGHIJ, vmagic_bias); |
| 140 |
float32x4_t vsGHIJ = vreinterpretq_f32_s32(vaddq_s32(vlGHIJ, venGHIJ)); |
| 141 |
vnKLMN = vsubq_f32(vnKLMN, vmagic_bias); |
| 142 |
float32x4_t vsKLMN = vreinterpretq_f32_s32(vaddq_s32(vlKLMN, venKLMN)); |
| 143 |
|
| 144 |
float32x4_t vt0123 = vfmaq_f32(vz0123, vn0123, vminus_ln2); |
| 145 |
float32x4_t vt4567 = vfmaq_f32(vz4567, vn4567, vminus_ln2); |
| 146 |
float32x4_t vt89AB = vfmaq_f32(vz89AB, vn89AB, vminus_ln2); |
| 147 |
float32x4_t vtCDEF = vfmaq_f32(vzCDEF, vnCDEF, vminus_ln2); |
| 148 |
float32x4_t vtGHIJ = vfmaq_f32(vzGHIJ, vnGHIJ, vminus_ln2); |
| 149 |
float32x4_t vtKLMN = vfmaq_f32(vzKLMN, vnKLMN, vminus_ln2); |
| 150 |
|
| 151 |
float32x4_t vp0123 = vfmaq_f32(vc2, vc3, vt0123); |
| 152 |
float32x4_t vp4567 = vfmaq_f32(vc2, vc3, vt4567); |
| 153 |
float32x4_t vp89AB = vfmaq_f32(vc2, vc3, vt89AB); |
| 154 |
float32x4_t vpCDEF = vfmaq_f32(vc2, vc3, vtCDEF); |
| 155 |
float32x4_t vpGHIJ = vfmaq_f32(vc2, vc3, vtGHIJ); |
| 156 |
float32x4_t vpKLMN = vfmaq_f32(vc2, vc3, vtKLMN); |
| 157 |
|
| 158 |
vp0123 = vmulq_f32(vp0123, vt0123); |
| 159 |
vp4567 = vmulq_f32(vp4567, vt4567); |
| 160 |
vp89AB = vmulq_f32(vp89AB, vt89AB); |
| 161 |
vpCDEF = vmulq_f32(vpCDEF, vtCDEF); |
| 162 |
vpGHIJ = vmulq_f32(vpGHIJ, vtGHIJ); |
| 163 |
vpKLMN = vmulq_f32(vpKLMN, vtKLMN); |
| 164 |
|
| 165 |
vt0123 = vmulq_f32(vt0123, vs0123); |
| 166 |
vs0123 = vsubq_f32(vs0123, vone); |
| 167 |
vt4567 = vmulq_f32(vt4567, vs4567); |
| 168 |
vs4567 = vsubq_f32(vs4567, vone); |
| 169 |
vt89AB = vmulq_f32(vt89AB, vs89AB); |
| 170 |
vs89AB = vsubq_f32(vs89AB, vone); |
| 171 |
vtCDEF = vmulq_f32(vtCDEF, vsCDEF); |
| 172 |
vsCDEF = vsubq_f32(vsCDEF, vone); |
| 173 |
vtGHIJ = vmulq_f32(vtGHIJ, vsGHIJ); |
| 174 |
vsGHIJ = vsubq_f32(vsGHIJ, vone); |
| 175 |
vtKLMN = vmulq_f32(vtKLMN, vsKLMN); |
| 176 |
vsKLMN = vsubq_f32(vsKLMN, vone); |
| 177 |
|
| 178 |
vp0123 = vfmaq_f32(vt0123, vp0123, vt0123); |
| 179 |
vp4567 = vfmaq_f32(vt4567, vp4567, vt4567); |
| 180 |
vp89AB = vfmaq_f32(vt89AB, vp89AB, vt89AB); |
| 181 |
vpCDEF = vfmaq_f32(vtCDEF, vpCDEF, vtCDEF); |
| 182 |
vpGHIJ = vfmaq_f32(vtGHIJ, vpGHIJ, vtGHIJ); |
| 183 |
vpKLMN = vfmaq_f32(vtKLMN, vpKLMN, vtKLMN); |
| 184 |
|
| 185 |
const float32x4_t ve0123 = vmulq_f32(vaddq_f32(vp0123, vs0123), valpha); |
| 186 |
const float32x4_t ve4567 = vmulq_f32(vaddq_f32(vp4567, vs4567), valpha); |
| 187 |
const float32x4_t ve89AB = vmulq_f32(vaddq_f32(vp89AB, vs89AB), valpha); |
| 188 |
const float32x4_t veCDEF = vmulq_f32(vaddq_f32(vpCDEF, vsCDEF), valpha); |
| 189 |
const float32x4_t veGHIJ = vmulq_f32(vaddq_f32(vpGHIJ, vsGHIJ), valpha); |
| 190 |
const float32x4_t veKLMN = vmulq_f32(vaddq_f32(vpKLMN, vsKLMN), valpha); |
| 191 |
|
| 192 |
const uint32x4_t vm0123 = vcltq_f32(vx0123, vmovq_n_f32(0.0f)); |
| 193 |
vx0123 = vmulq_f32(vx0123, vbeta); |
| 194 |
const uint32x4_t vm4567 = vcltq_f32(vx4567, vmovq_n_f32(0.0f)); |
| 195 |
vx4567 = vmulq_f32(vx4567, vbeta); |
| 196 |
const uint32x4_t vm89AB = vcltq_f32(vx89AB, vmovq_n_f32(0.0f)); |
| 197 |
vx89AB = vmulq_f32(vx89AB, vbeta); |
| 198 |
const uint32x4_t vmCDEF = vcltq_f32(vxCDEF, vmovq_n_f32(0.0f)); |
| 199 |
vxCDEF = vmulq_f32(vxCDEF, vbeta); |
| 200 |
const uint32x4_t vmGHIJ = vcltq_f32(vxGHIJ, vmovq_n_f32(0.0f)); |
| 201 |
vxGHIJ = vmulq_f32(vxGHIJ, vbeta); |
| 202 |
const uint32x4_t vmKLMN = vcltq_f32(vxKLMN, vmovq_n_f32(0.0f)); |
| 203 |
vxKLMN = vmulq_f32(vxKLMN, vbeta); |
| 204 |
|
| 205 |
const float32x4_t vy0123 = vbslq_f32(vm0123, ve0123, vx0123); |
| 206 |
const float32x4_t vy4567 = vbslq_f32(vm4567, ve4567, vx4567); |
| 207 |
const float32x4_t vy89AB = vbslq_f32(vm89AB, ve89AB, vx89AB); |
| 208 |
const float32x4_t vyCDEF = vbslq_f32(vmCDEF, veCDEF, vxCDEF); |
| 209 |
const float32x4_t vyGHIJ = vbslq_f32(vmGHIJ, veGHIJ, vxGHIJ); |
| 210 |
const float32x4_t vyKLMN = vbslq_f32(vmKLMN, veKLMN, vxKLMN); |
| 211 |
|
| 212 |
vst1q_f32(output, vy0123); output += 4; |
| 213 |
vst1q_f32(output, vy4567); output += 4; |
| 214 |
vst1q_f32(output, vy89AB); output += 4; |
| 215 |
vst1q_f32(output, vyCDEF); output += 4; |
| 216 |
vst1q_f32(output, vyGHIJ); output += 4; |
| 217 |
vst1q_f32(output, vyKLMN); output += 4; |
| 218 |
} |
| 219 |
for (; batch >= 4 * sizeof(float); batch -= 4 * sizeof(float)) { |
| 220 |
float32x4_t vx = vld1q_f32(input); input += 4; |
| 221 |
|
| 222 |
const float32x4_t vz = vmaxq_f32(vmulq_f32(vx, vprescale), vsat_cutoff); |
| 223 |
|
| 224 |
float32x4_t vn = vfmaq_f32(vmagic_bias, vz, vlog2e); |
| 225 |
const uint64x2_t vidx = vreinterpretq_u64_s32(vshlq_n_s32(vandq_s32(vreinterpretq_s32_f32(vn), vindex_mask), 2)); |
| 226 |
const int32x4_t ven = vshlq_n_s32(vreinterpretq_s32_f32(vn), 19); |
| 227 |
|
| 228 |
const uint64_t vidx_lo = vgetq_lane_u64(vidx, 0); |
| 229 |
const uint64_t vidx_hi = vgetq_lane_u64(vidx, 1); |
| 230 |
int32x2_t vl_lo = vld1_dup_s32((const int32_t*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidx_lo)); |
| 231 |
int32x2_t vl_hi = vld1_dup_s32((const int32_t*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidx_hi)); |
| 232 |
vl_lo = vld1_lane_s32((const int32_t*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) (vidx_lo >> 32)), vl_lo, 1); |
| 233 |
vl_hi = vld1_lane_s32((const int32_t*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) (vidx_hi >> 32)), vl_hi, 1); |
| 234 |
|
| 235 |
vn = vsubq_f32(vn, vmagic_bias); |
| 236 |
const int32x4_t vl = vcombine_s32(vl_lo, vl_hi); |
| 237 |
|
| 238 |
float32x4_t vt = vfmaq_f32(vz, vn, vminus_ln2); |
| 239 |
float32x4_t vs = vreinterpretq_f32_s32(vaddq_s32(vl, ven)); |
| 240 |
|
| 241 |
float32x4_t vp = vfmaq_f32(vc2, vc3, vt); |
| 242 |
vp = vmulq_f32(vp, vt); |
| 243 |
|
| 244 |
vt = vmulq_f32(vt, vs); |
| 245 |
vs = vsubq_f32(vs, vone); |
| 246 |
vp = vfmaq_f32(vt, vp, vt); |
| 247 |
const float32x4_t ve = vmulq_f32(vaddq_f32(vp, vs), valpha); |
| 248 |
|
| 249 |
const uint32x4_t vm = vcltq_f32(vx, vmovq_n_f32(0.0f)); |
| 250 |
vx = vmulq_f32(vx, vbeta); |
| 251 |
const float32x4_t vy = vbslq_f32(vm, ve, vx); |
| 252 |
|
| 253 |
vst1q_f32(output, vy); output += 4; |
| 254 |
} |
| 255 |
if XNN_UNLIKELY(batch != 0) { |
| 256 |
float32x4_t vx = vld1q_f32(input); |
| 257 |
|
| 258 |
const float32x4_t vz = vmaxq_f32(vmulq_f32(vx, vprescale), vsat_cutoff); |
| 259 |
|
| 260 |
float32x4_t vn = vfmaq_f32(vmagic_bias, vz, vlog2e); |
| 261 |
const uint64x2_t vidx = vreinterpretq_u64_s32(vshlq_n_s32(vandq_s32(vreinterpretq_s32_f32(vn), vindex_mask), 2)); |
| 262 |
const int32x4_t ven = vshlq_n_s32(vreinterpretq_s32_f32(vn), 19); |
| 263 |
|
| 264 |
const uint64_t vidx_lo = vgetq_lane_u64(vidx, 0); |
| 265 |
const uint64_t vidx_hi = vgetq_lane_u64(vidx, 1); |
| 266 |
int32x2_t vl_lo = vld1_dup_s32((const int32_t*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidx_lo)); |
| 267 |
int32x2_t vl_hi = vld1_dup_s32((const int32_t*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) vidx_hi)); |
| 268 |
vl_lo = vld1_lane_s32((const int32_t*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) (vidx_lo >> 32)), vl_lo, 1); |
| 269 |
vl_hi = vld1_lane_s32((const int32_t*) ((uintptr_t) xnn_table_exp2minus_k_over_16 + (uint32_t) (vidx_hi >> 32)), vl_hi, 1); |
| 270 |
|
| 271 |
vn = vsubq_f32(vn, vmagic_bias); |
| 272 |
const int32x4_t vl = vcombine_s32(vl_lo, vl_hi); |
| 273 |
|
| 274 |
float32x4_t vt = vfmaq_f32(vz, vn, vminus_ln2); |
| 275 |
float32x4_t vs = vreinterpretq_f32_s32(vaddq_s32(vl, ven)); |
| 276 |
|
| 277 |
float32x4_t vp = vfmaq_f32(vc2, vc3, vt); |
| 278 |
vp = vmulq_f32(vp, vt); |
| 279 |
|
| 280 |
vt = vmulq_f32(vt, vs); |
| 281 |
vs = vsubq_f32(vs, vone); |
| 282 |
vp = vfmaq_f32(vt, vp, vt); |
| 283 |
const float32x4_t ve = vmulq_f32(vaddq_f32(vp, vs), valpha); |
| 284 |
|
| 285 |
const uint32x4_t vm = vcltq_f32(vx, vmovq_n_f32(0.0f)); |
| 286 |
vx = vmulq_f32(vx, vbeta); |
| 287 |
const float32x4_t vy = vbslq_f32(vm, ve, vx); |
| 288 |
|
| 289 |
float32x2_t vy_lo = vget_low_f32(vy); |
| 290 |
if (batch & (2 * sizeof(float))) { |
| 291 |
vst1_f32(output, vy_lo); output += 2; |
| 292 |
vy_lo = vget_high_f32(vy); |
| 293 |
} |
| 294 |
if (batch & (1 * sizeof(float))) { |
| 295 |
vst1_lane_f32(output, vy_lo, 0); |
| 296 |
} |
| 297 |
} |
| 298 |
} |