| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
#include <assert.h> |
| 11 |
|
| 12 |
#include <arm_neon.h> |
| 13 |
|
| 14 |
#include "xnnpack/common.h" |
| 15 |
#include "xnnpack/vunary.h" |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
void xnn_f16_vrsqrt_ukernel__neonfp16arith_rsqrt_u16( |
| 40 |
size_t batch, |
| 41 |
const xnn_float16* input, |
| 42 |
xnn_float16* output, |
| 43 |
const struct xnn_f16_default_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS |
| 44 |
{ |
| 45 |
assert(batch != 0); |
| 46 |
assert(batch % sizeof(uint16_t) == 0); |
| 47 |
assert(input != NULL); |
| 48 |
assert(output != NULL); |
| 49 |
|
| 50 |
const uint16_t* i = (const uint16_t*) input; |
| 51 |
uint16_t* o = (uint16_t*) output; |
| 52 |
|
| 53 |
for (; batch >= 16 * sizeof(uint16_t); batch -= 16 * sizeof(uint16_t)) { |
| 54 |
const float16x8_t vx0 = vreinterpretq_f16_u16(vld1q_u16(i)); i += 8; |
| 55 |
const float16x8_t vx1 = vreinterpretq_f16_u16(vld1q_u16(i)); i += 8; |
| 56 |
|
| 57 |
const float16x8_t vt0_0 = vrsqrteq_f16(vx0); |
| 58 |
const float16x8_t vt0_1 = vrsqrteq_f16(vx1); |
| 59 |
const float16x8_t vt1_0 = vmulq_f16(vt0_0, vt0_0); |
| 60 |
const float16x8_t vt1_1 = vmulq_f16(vt0_1, vt0_1); |
| 61 |
const float16x8_t vt2_0 = vrsqrtsq_f16(vx0, vt1_0); |
| 62 |
const float16x8_t vt2_1 = vrsqrtsq_f16(vx1, vt1_1); |
| 63 |
const float16x8_t vy0 = vmulq_f16(vt0_0, vt2_0); |
| 64 |
const float16x8_t vy1 = vmulq_f16(vt0_1, vt2_1); |
| 65 |
|
| 66 |
vst1q_u16(o, vreinterpretq_u16_f16(vy0)); o += 8; |
| 67 |
vst1q_u16(o, vreinterpretq_u16_f16(vy1)); o += 8; |
| 68 |
} |
| 69 |
for (; batch >= 8 * sizeof(uint16_t); batch -= 8 * sizeof(uint16_t)) { |
| 70 |
const float16x8_t vx = vreinterpretq_f16_u16(vld1q_u16(i)); i += 8; |
| 71 |
|
| 72 |
const float16x8_t vt0 = vrsqrteq_f16(vx); |
| 73 |
const float16x8_t vt1 = vmulq_f16(vt0, vt0); |
| 74 |
const float16x8_t vt2 = vrsqrtsq_f16(vx, vt1); |
| 75 |
const float16x8_t vy = vmulq_f16(vt0, vt2); |
| 76 |
|
| 77 |
vst1q_u16(o, vreinterpretq_u16_f16(vy)); o += 8; |
| 78 |
} |
| 79 |
if XNN_UNLIKELY(batch != 0) { |
| 80 |
const float16x8_t vx = vreinterpretq_f16_u16(vld1q_u16(i)); |
| 81 |
const float16x4_t vx_lo = vget_low_f16(vx); |
| 82 |
const float16x4_t vx_hi = vget_high_f16(vx); |
| 83 |
|
| 84 |
const float16x4_t vt0 = vrsqrte_f16(vx_lo); |
| 85 |
const float16x4_t vt1 = vmul_f16(vt0, vt0); |
| 86 |
const float16x4_t vt2 = vrsqrts_f16(vx_lo, vt1); |
| 87 |
float16x4_t vy_lo = vmul_f16(vt0, vt2); |
| 88 |
|
| 89 |
if (batch & (4 * sizeof(uint16_t))) { |
| 90 |
vst1_u16(o, vreinterpret_u16_f16(vy_lo)); o += 4; |
| 91 |
|
| 92 |
const float16x4_t vt0 = vrsqrte_f16(vx_hi); |
| 93 |
const float16x4_t vt1 = vmul_f16(vt0, vt0); |
| 94 |
const float16x4_t vt2 = vrsqrts_f16(vx_hi, vt1); |
| 95 |
vy_lo = vmul_f16(vt0, vt2); |
| 96 |
} |
| 97 |
|
| 98 |
if (batch & (2 * sizeof(uint16_t))) { |
| 99 |
vst1_lane_u32((void*) o, vreinterpret_u32_f16(vy_lo), 0); o += 2; |
| 100 |
vy_lo = vext_f16(vy_lo, vy_lo, 2); |
| 101 |
} |
| 102 |
|
| 103 |
if (batch & (1 * sizeof(uint16_t))) { |
| 104 |
vst1_lane_u16(o, vreinterpret_u16_f16(vy_lo), 0); |
| 105 |
} |
| 106 |
} |
| 107 |
} |