| 1 |
// Auto-generated file. Do not edit! |
| 2 |
// Template: src/qs8-vmulc/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/vbinary.h" |
| 15 |
|
| 16 |
|
| 17 |
void xnn_qs8_vmulc_minmax_fp32_ukernel__neon_ld64_u8( |
| 18 |
size_t batch, |
| 19 |
const int8_t* input_a, |
| 20 |
const int8_t* input_b, |
| 21 |
int8_t* output, |
| 22 |
const union xnn_qs8_mul_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS |
| 23 |
{ |
| 24 |
assert(batch != 0); |
| 25 |
assert(batch % sizeof(int8_t) == 0); |
| 26 |
assert(input_a != NULL); |
| 27 |
assert(input_b != NULL); |
| 28 |
assert(output != NULL); |
| 29 |
|
| 30 |
const int8x8_t va_zero_point = vld1_dup_s8(¶ms->scalar.a_zero_point); |
| 31 |
const float32x4_t vscale = vld1q_dup_f32(¶ms->scalar.scale); |
| 32 |
const float32x4_t vmagic_bias = vdupq_n_f32(12582912.0f); |
| 33 |
const int32x4_t vmagic_bias_less_output_zero_point = vdupq_n_s32(INT32_C(0x4B400000) - (int32_t) params->scalar.output_zero_point); |
| 34 |
const int8x8_t voutput_min = vld1_dup_s8(¶ms->scalar.output_min); |
| 35 |
const int8x8_t voutput_max = vld1_dup_s8(¶ms->scalar.output_max); |
| 36 |
|
| 37 |
const int8x8_t vb = vld1_dup_s8(input_b); |
| 38 |
const int8x8_t vb_zero_point = vld1_dup_s8(¶ms->scalar.b_zero_point); |
| 39 |
const int16x8_t vxb = vsubl_s8(vb, vb_zero_point); |
| 40 |
for (; batch >= 8 * sizeof(int8_t); batch -= 8 * sizeof(int8_t)) { |
| 41 |
const int8x8_t va01234567 = vld1_s8(input_a); input_a += 8; |
| 42 |
|
| 43 |
const int16x8_t vxa01234567 = vsubl_s8(va01234567, va_zero_point); |
| 44 |
|
| 45 |
int32x4_t vacc0123 = vmull_s16(vget_low_s16(vxa01234567), vget_low_s16(vxb)); |
| 46 |
int32x4_t vacc4567 = vmull_s16(vget_high_s16(vxa01234567), vget_high_s16(vxb)); |
| 47 |
|
| 48 |
float32x4_t vfpacc0123 = vcvtq_f32_s32(vacc0123); |
| 49 |
float32x4_t vfpacc4567 = vcvtq_f32_s32(vacc4567); |
| 50 |
|
| 51 |
vfpacc0123 = vmulq_f32(vfpacc0123, vscale); |
| 52 |
vfpacc4567 = vmulq_f32(vfpacc4567, vscale); |
| 53 |
|
| 54 |
vacc0123 = vreinterpretq_s32_f32(vaddq_f32(vfpacc0123, vmagic_bias)); |
| 55 |
vacc4567 = vreinterpretq_s32_f32(vaddq_f32(vfpacc4567, vmagic_bias)); |
| 56 |
|
| 57 |
vacc0123 = vqsubq_s32(vacc0123, vmagic_bias_less_output_zero_point); |
| 58 |
vacc4567 = vqsubq_s32(vacc4567, vmagic_bias_less_output_zero_point); |
| 59 |
|
| 60 |
#if XNN_ARCH_ARM64 |
| 61 |
int16x8_t vacc01234567 = vqmovn_high_s32(vqmovn_s32(vacc0123), vacc4567); |
| 62 |
#else |
| 63 |
int16x8_t vacc01234567 = vcombine_s16(vqmovn_s32(vacc0123), vqmovn_s32(vacc4567)); |
| 64 |
#endif |
| 65 |
|
| 66 |
|
| 67 |
#if XNN_ARCH_ARM64 |
| 68 |
int8x8_t vout01234567 = vqmovn_s16(vacc01234567); |
| 69 |
#else |
| 70 |
int8x8_t vout01234567 = vqmovn_s16(vacc01234567); |
| 71 |
#endif |
| 72 |
|
| 73 |
vout01234567 = vmax_s8(vout01234567, voutput_min); |
| 74 |
|
| 75 |
vout01234567 = vmin_s8(vout01234567, voutput_max); |
| 76 |
|
| 77 |
vst1_s8(output, vout01234567); output += 8; |
| 78 |
} |
| 79 |
if XNN_UNLIKELY(batch != 0) { |
| 80 |
{ |
| 81 |
const int8x8_t va01234567 = vld1_s8(input_a); |
| 82 |
|
| 83 |
const int16x8_t vxa01234567 = vsubl_s8(va01234567, va_zero_point); |
| 84 |
|
| 85 |
int32x4_t vacc0123 = vmull_s16(vget_low_s16(vxa01234567), vget_low_s16(vxb)); |
| 86 |
int32x4_t vacc4567 = vmull_s16(vget_high_s16(vxa01234567), vget_high_s16(vxb)); |
| 87 |
|
| 88 |
float32x4_t vfpacc0123 = vcvtq_f32_s32(vacc0123); |
| 89 |
float32x4_t vfpacc4567 = vcvtq_f32_s32(vacc4567); |
| 90 |
|
| 91 |
vfpacc0123 = vmulq_f32(vfpacc0123, vscale); |
| 92 |
vfpacc4567 = vmulq_f32(vfpacc4567, vscale); |
| 93 |
|
| 94 |
vacc0123 = vreinterpretq_s32_f32(vaddq_f32(vfpacc0123, vmagic_bias)); |
| 95 |
vacc4567 = vreinterpretq_s32_f32(vaddq_f32(vfpacc4567, vmagic_bias)); |
| 96 |
|
| 97 |
vacc0123 = vqsubq_s32(vacc0123, vmagic_bias_less_output_zero_point); |
| 98 |
vacc4567 = vqsubq_s32(vacc4567, vmagic_bias_less_output_zero_point); |
| 99 |
|
| 100 |
#if XNN_ARCH_ARM64 |
| 101 |
int16x8_t vacc01234567 = vqmovn_high_s32(vqmovn_s32(vacc0123), vacc4567); |
| 102 |
#else |
| 103 |
int16x8_t vacc01234567 = vcombine_s16(vqmovn_s32(vacc0123), vqmovn_s32(vacc4567)); |
| 104 |
#endif |
| 105 |
|
| 106 |
|
| 107 |
int8x8_t vout01234567 = vqmovn_s16(vacc01234567); |
| 108 |
|
| 109 |
vout01234567 = vmax_s8(vout01234567, voutput_min); |
| 110 |
vout01234567 = vmin_s8(vout01234567, voutput_max); |
| 111 |
if (batch & (4 * sizeof(int8_t))) { |
| 112 |
vst1_lane_u32((void*) output, vreinterpret_u32_s8(vout01234567), 0); output += 4; |
| 113 |
vout01234567 = vext_s8(vout01234567, vout01234567, 4); |
| 114 |
} |
| 115 |
if (batch & (2 * sizeof(int8_t))) { |
| 116 |
vst1_lane_u16((void*) output, vreinterpret_u16_s8(vout01234567), 0); output += 2; |
| 117 |
vout01234567 = vext_s8(vout01234567, vout01234567, 2); |
| 118 |
} |
| 119 |
if (batch & (1 * sizeof(int8_t))) { |
| 120 |
vst1_lane_s8(output, vout01234567, 0); |
| 121 |
} |
| 122 |
} |
| 123 |
} |
| 124 |
} |