| 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/intrinsics-polyfill.h" |
| 16 |
#include "xnnpack/vcvt.h" |
| 17 |
|
| 18 |
|
| 19 |
void xnn_qs8_f16_vcvt_ukernel__neonfp16arith_u24( |
| 20 |
size_t batch, |
| 21 |
const int8_t* input, |
| 22 |
xnn_float16* output, |
| 23 |
const struct xnn_qs8_f16_cvt_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS |
| 24 |
{ |
| 25 |
assert(batch != 0); |
| 26 |
assert(batch % sizeof(int8_t) == 0); |
| 27 |
assert(input != NULL); |
| 28 |
assert(output != NULL); |
| 29 |
|
| 30 |
uint16_t* o = (uint16_t*) output; |
| 31 |
const int16x8_t vminus_zero_point = vdupq_n_s16(-params->scalar.zero_point); |
| 32 |
#ifdef XNN_COMPILER_MSVC |
| 33 |
const float16x8_t vscale = vreinterpretq_f16_u16(vdupq_n_u16(*(const uint16_t*) ¶ms->scalar.scale)); |
| 34 |
#else |
| 35 |
const float16x8_t vscale = vreinterpretq_f16_u16(vld1q_dup_u16((const uint16_t*) ¶ms->scalar.scale)); |
| 36 |
#endif |
| 37 |
for (; batch >= 24 * sizeof(int8_t); batch -= 24 * sizeof(int8_t)) { |
| 38 |
const int8x8_t vx01234567 = vld1_s8(input); input += 8; |
| 39 |
const int8x8_t vx89ABCDEF = vld1_s8(input); input += 8; |
| 40 |
const int8x8_t vxGHIJKLMN = vld1_s8(input); input += 8; |
| 41 |
|
| 42 |
const int16x8_t vhx01234567 = vaddw_s8(vminus_zero_point, vx01234567); |
| 43 |
const int16x8_t vhx89ABCDEF = vaddw_s8(vminus_zero_point, vx89ABCDEF); |
| 44 |
const int16x8_t vhxGHIJKLMN = vaddw_s8(vminus_zero_point, vxGHIJKLMN); |
| 45 |
|
| 46 |
float16x8_t vy01234567 = vcvtq_f16_s16(vhx01234567); |
| 47 |
float16x8_t vy89ABCDEF = vcvtq_f16_s16(vhx89ABCDEF); |
| 48 |
float16x8_t vyGHIJKLMN = vcvtq_f16_s16(vhxGHIJKLMN); |
| 49 |
|
| 50 |
vy01234567 = vmulq_f16(vy01234567, vscale); |
| 51 |
vy89ABCDEF = vmulq_f16(vy89ABCDEF, vscale); |
| 52 |
vyGHIJKLMN = vmulq_f16(vyGHIJKLMN, vscale); |
| 53 |
|
| 54 |
vst1q_u16(o, vreinterpretq_u16_f16(vy01234567)); o += 8; |
| 55 |
vst1q_u16(o, vreinterpretq_u16_f16(vy89ABCDEF)); o += 8; |
| 56 |
vst1q_u16(o, vreinterpretq_u16_f16(vyGHIJKLMN)); o += 8; |
| 57 |
} |
| 58 |
for (; batch >= 8 * sizeof(int8_t); batch -= 8 * sizeof(int8_t)) { |
| 59 |
const int8x8_t vx = vld1_s8(input); input += 8; |
| 60 |
|
| 61 |
const int16x8_t vhx = vaddw_s8(vminus_zero_point, vx); |
| 62 |
|
| 63 |
float16x8_t vy = vcvtq_f16_s16(vhx); |
| 64 |
|
| 65 |
vy = vmulq_f16(vy, vscale); |
| 66 |
|
| 67 |
vst1q_u16(o, vreinterpretq_u16_f16(vy)); o += 8; |
| 68 |
} |
| 69 |
if XNN_UNLIKELY(batch != 0) { |
| 70 |
assert(batch >= 1 * sizeof(int8_t)); |
| 71 |
assert(batch <= 7 * sizeof(int8_t)); |
| 72 |
|
| 73 |
const int8x8_t vx = vld1_s8(input); |
| 74 |
|
| 75 |
const int16x8_t vhx = vaddw_s8(vminus_zero_point, vx); |
| 76 |
|
| 77 |
float16x8_t vy = vcvtq_f16_s16(vhx); |
| 78 |
vy = vmulq_f16(vy, vscale); |
| 79 |
|
| 80 |
float16x4_t vy_lo = vget_low_f16(vy); |
| 81 |
if (batch & (4 * sizeof(int8_t))) { |
| 82 |
vst1_u16(o, vreinterpret_u16_f16(vy_lo)); o += 4; |
| 83 |
vy_lo = vget_high_f16(vy); |
| 84 |
} |
| 85 |
if (batch & (2 * sizeof(int8_t))) { |
| 86 |
vst1_lane_u32((void*) o, vreinterpret_u32_f16(vy_lo), 0); o += 2; |
| 87 |
|
| 88 |
vy_lo = vext_f16(vy_lo, vy_lo, 2); |
| 89 |
} |
| 90 |
if (batch & (1 * sizeof(int8_t))) { |
| 91 |
vst1_lane_u16(o, vreinterpret_u16_f16(vy_lo), 0); |
| 92 |
} |
| 93 |
} |
| 94 |
} |