| 1 |
// Auto-generated file. Do not edit! |
| 2 |
// Template: src/qs8-f32-vcvt/neon.c.in |
| 3 |
// Generator: tools/xngen |
| 4 |
// |
| 5 |
// Copyright 2021 Google LLC |
| 6 |
// |
| 7 |
// This source code is licensed under the BSD-style license found in the |
| 8 |
// LICENSE file in the root directory of this source tree. |
| 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_qu8_f32_vcvt_ukernel__neon_u16( |
| 20 |
size_t batch, |
| 21 |
const uint8_t* input, |
| 22 |
float* output, |
| 23 |
const struct xnn_qu8_f32_cvt_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS |
| 24 |
{ |
| 25 |
assert(batch != 0); |
| 26 |
assert(batch % sizeof(uint8_t) == 0); |
| 27 |
assert(input != NULL); |
| 28 |
assert(output != NULL); |
| 29 |
|
| 30 |
const int16x8_t vminus_zero_point = vdupq_n_s16(-params->scalar.zero_point); |
| 31 |
const float32x4_t vscale = vld1q_dup_f32(¶ms->scalar.scale); |
| 32 |
for (; batch >= 16 * sizeof(uint8_t); batch -= 16 * sizeof(uint8_t)) { |
| 33 |
const uint8x8_t vx01234567 = vld1_u8(input); input += 8; |
| 34 |
const uint8x8_t vx89ABCDEF = vld1_u8(input); input += 8; |
| 35 |
|
| 36 |
const int16x8_t vhx01234567 = vreinterpretq_s16_u16(vaddw_u8(vreinterpretq_u16_s16(vminus_zero_point), vx01234567)); |
| 37 |
const int16x8_t vhx89ABCDEF = vreinterpretq_s16_u16(vaddw_u8(vreinterpretq_u16_s16(vminus_zero_point), vx89ABCDEF)); |
| 38 |
|
| 39 |
const int32x4_t vwx0123 = vmovl_s16(vget_low_s16(vhx01234567)); |
| 40 |
const int32x4_t vwx4567 = vmovl_s16(vget_high_s16(vhx01234567)); |
| 41 |
const int32x4_t vwx89AB = vmovl_s16(vget_low_s16(vhx89ABCDEF)); |
| 42 |
const int32x4_t vwxCDEF = vmovl_s16(vget_high_s16(vhx89ABCDEF)); |
| 43 |
|
| 44 |
float32x4_t vy0123 = vcvtq_f32_s32(vwx0123); |
| 45 |
float32x4_t vy4567 = vcvtq_f32_s32(vwx4567); |
| 46 |
float32x4_t vy89AB = vcvtq_f32_s32(vwx89AB); |
| 47 |
float32x4_t vyCDEF = vcvtq_f32_s32(vwxCDEF); |
| 48 |
|
| 49 |
vy0123 = vmulq_f32(vy0123, vscale); |
| 50 |
vy4567 = vmulq_f32(vy4567, vscale); |
| 51 |
vy89AB = vmulq_f32(vy89AB, vscale); |
| 52 |
vyCDEF = vmulq_f32(vyCDEF, vscale); |
| 53 |
|
| 54 |
vst1q_f32(output, vy0123); output += 4; |
| 55 |
vst1q_f32(output, vy4567); output += 4; |
| 56 |
vst1q_f32(output, vy89AB); output += 4; |
| 57 |
vst1q_f32(output, vyCDEF); output += 4; |
| 58 |
} |
| 59 |
for (; batch >= 8 * sizeof(uint8_t); batch -= 8 * sizeof(uint8_t)) { |
| 60 |
const uint8x8_t vx = vld1_u8(input); input += 8; |
| 61 |
|
| 62 |
const int16x8_t vhx = vreinterpretq_s16_u16(vaddw_u8(vreinterpretq_u16_s16(vminus_zero_point), vx)); |
| 63 |
|
| 64 |
const int32x4_t vwx_lo = vmovl_s16(vget_low_s16(vhx)); |
| 65 |
const int32x4_t vwx_hi = vmovl_s16(vget_high_s16(vhx)); |
| 66 |
|
| 67 |
float32x4_t vy_lo = vcvtq_f32_s32(vwx_lo); |
| 68 |
float32x4_t vy_hi = vcvtq_f32_s32(vwx_hi); |
| 69 |
|
| 70 |
vy_lo = vmulq_f32(vy_lo, vscale); |
| 71 |
vy_hi = vmulq_f32(vy_hi, vscale); |
| 72 |
|
| 73 |
vst1q_f32(output, vy_lo); output += 4; |
| 74 |
vst1q_f32(output, vy_hi); output += 4; |
| 75 |
} |
| 76 |
if XNN_UNLIKELY(batch != 0) { |
| 77 |
assert(batch >= 1 * sizeof(uint8_t)); |
| 78 |
assert(batch <= 7 * sizeof(uint8_t)); |
| 79 |
|
| 80 |
const uint8x8_t vx = vld1_u8(input); |
| 81 |
|
| 82 |
const int16x8_t vhx = vreinterpretq_s16_u16(vaddw_u8(vreinterpretq_u16_s16(vminus_zero_point), vx)); |
| 83 |
|
| 84 |
const int32x4_t vwx_lo = vmovl_s16(vget_low_s16(vhx)); |
| 85 |
const int32x4_t vwx_hi = vmovl_s16(vget_high_s16(vhx)); |
| 86 |
|
| 87 |
float32x4_t vy = vcvtq_f32_s32(vwx_lo); |
| 88 |
vy = vmulq_f32(vy, vscale); |
| 89 |
|
| 90 |
if (batch & (4 * sizeof(uint8_t))) { |
| 91 |
vst1q_f32(output, vy); output += 4; |
| 92 |
vy = vcvtq_f32_s32(vwx_hi); |
| 93 |
vy = vmulq_f32(vy, vscale); |
| 94 |
} |
| 95 |
float32x2_t vy_lo = vget_low_f32(vy); |
| 96 |
if (batch & (2 * sizeof(uint8_t))) { |
| 97 |
vst1_f32(output, vy_lo); output += 2; |
| 98 |
vy_lo = vget_high_f32(vy); |
| 99 |
} |
| 100 |
if (batch & (1 * sizeof(uint8_t))) { |
| 101 |
vst1_lane_f32(output, vy_lo, 0); |
| 102 |
} |
| 103 |
} |
| 104 |
} |