| 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/vbinary.h" |
| 16 |
|
| 17 |
|
| 18 |
void xnn_f16_vsqrdiffc_ukernel__neonfp16arith_u16( |
| 19 |
size_t batch, |
| 20 |
const xnn_float16* restrict input_a, |
| 21 |
const xnn_float16* restrict input_b, |
| 22 |
xnn_float16* restrict output, |
| 23 |
const struct xnn_f16_default_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS |
| 24 |
{ |
| 25 |
assert(batch != 0); |
| 26 |
assert(batch % sizeof(uint16_t) == 0); |
| 27 |
assert(input_a != NULL); |
| 28 |
assert(input_b != NULL); |
| 29 |
assert(output != NULL); |
| 30 |
|
| 31 |
const uint16_t* a = (const uint16_t*) input_a; |
| 32 |
const uint16_t* b = (const uint16_t*) input_b; |
| 33 |
uint16_t* o = (uint16_t*) output; |
| 34 |
|
| 35 |
const float16x8_t vb = vreinterpretq_f16_u16(vld1q_dup_u16(b)); |
| 36 |
for (; batch >= 16 * sizeof(uint16_t); batch -= 16 * sizeof(uint16_t)) { |
| 37 |
const float16x8_t va01234567 = vreinterpretq_f16_u16(vld1q_u16(a)); a += 8; |
| 38 |
const float16x8_t va456789AB = vreinterpretq_f16_u16(vld1q_u16(a)); a += 8; |
| 39 |
|
| 40 |
float16x8_t vy01234567 = vsubq_f16(va01234567, vb); |
| 41 |
float16x8_t vy456789AB = vsubq_f16(va456789AB, vb); |
| 42 |
|
| 43 |
vy01234567 = vmulq_f16(vy01234567, vy01234567); |
| 44 |
vy456789AB = vmulq_f16(vy456789AB, vy456789AB); |
| 45 |
|
| 46 |
vst1q_u16(o, vreinterpretq_u16_f16(vy01234567)); o += 8; |
| 47 |
vst1q_u16(o, vreinterpretq_u16_f16(vy456789AB)); o += 8; |
| 48 |
} |
| 49 |
for (; batch >= 8 * sizeof(uint16_t); batch -= 8 * sizeof(uint16_t)) { |
| 50 |
const float16x8_t va01234567 = vreinterpretq_f16_u16(vld1q_u16(a)); a += 8; |
| 51 |
|
| 52 |
float16x8_t vy01234567 = vsubq_f16(va01234567, vb); |
| 53 |
vy01234567 = vmulq_f16(vy01234567, vy01234567); |
| 54 |
vst1q_u16(o, vreinterpretq_u16_f16(vy01234567)); o += 8; |
| 55 |
} |
| 56 |
if XNN_UNLIKELY(batch != 0) { |
| 57 |
const float16x8_t va01234567 = vreinterpretq_f16_u16(vld1q_u16(a)); |
| 58 |
|
| 59 |
float16x8_t vy01234567 = vsubq_f16(va01234567, vb); |
| 60 |
vy01234567 = vmulq_f16(vy01234567, vy01234567); |
| 61 |
|
| 62 |
float16x4_t vy0123 = vget_low_f16(vy01234567); |
| 63 |
if (batch & (4 * sizeof(uint16_t))) { |
| 64 |
vst1_u16(o, vreinterpret_u16_f16(vy0123)); o += 4; |
| 65 |
vy0123 = vget_high_f16(vy01234567); |
| 66 |
} |
| 67 |
|
| 68 |
if (batch & (2 * sizeof(uint16_t))) { |
| 69 |
vst1_lane_u32((void*) o, vreinterpret_u32_f16(vy0123), 0); o += 2; |
| 70 |
vy0123 = vext_f16(vy0123, vy0123, 2); |
| 71 |
} |
| 72 |
|
| 73 |
if (batch & (1 * sizeof(uint16_t))) { |
| 74 |
vst1_lane_u16(o, vreinterpret_u16_f16(vy0123), 0); |
| 75 |
} |
| 76 |
} |
| 77 |
} |