| 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/ibilinear.h" |
| 16 |
|
| 17 |
|
| 18 |
void xnn_s8_ibilinear_ukernel__neon_c8( |
| 19 |
size_t output_pixels, |
| 20 |
size_t channels, |
| 21 |
const int8_t** restrict input, |
| 22 |
size_t input_offset, |
| 23 |
const int16_t* restrict weights, |
| 24 |
int8_t* restrict output, |
| 25 |
size_t output_increment) XNN_OOB_READS |
| 26 |
{ |
| 27 |
assert(output_pixels != 0); |
| 28 |
assert(channels != 0); |
| 29 |
|
| 30 |
do { |
| 31 |
const int8_t* i0 = (const int8_t*) ((uintptr_t) input[0] + input_offset); |
| 32 |
const int8_t* i1 = (const int8_t*) ((uintptr_t) input[1] + input_offset); |
| 33 |
const int8_t* i2 = (const int8_t*) ((uintptr_t) input[2] + input_offset); |
| 34 |
const int8_t* i3 = (const int8_t*) ((uintptr_t) input[3] + input_offset); |
| 35 |
input += 4; |
| 36 |
|
| 37 |
#if XNN_ARCH_ARM64 |
| 38 |
const int16x8_t valphah = vld1q_dup_s16(weights); weights += 1; |
| 39 |
#else |
| 40 |
const int16x4_t valphah = vld1_dup_s16(weights); weights += 1; |
| 41 |
#endif |
| 42 |
const int32x4_t valphav = vmovl_s16(vld1_dup_s16(weights)); weights += 1; |
| 43 |
|
| 44 |
size_t c = channels; |
| 45 |
for (; c >= 8 * sizeof(int8_t); c -= 8 * sizeof(int8_t)) { |
| 46 |
const int8x8_t vtl01234567 = vld1_s8(i0); i0 += 8; |
| 47 |
const int8x8_t vtr01234567 = vld1_s8(i1); i1 += 8; |
| 48 |
const int8x8_t vbl01234567 = vld1_s8(i2); i2 += 8; |
| 49 |
const int8x8_t vbr01234567 = vld1_s8(i3); i3 += 8; |
| 50 |
|
| 51 |
const int16x8_t vtd01234567 = vsubl_s8(vtr01234567, vtl01234567); |
| 52 |
const int16x8_t vbd01234567 = vsubl_s8(vbr01234567, vbl01234567); |
| 53 |
const int16x8_t vdl01234567 = vsubl_s8(vbl01234567, vtl01234567); |
| 54 |
const int16x8_t vxtl01234567 = vmovl_s8(vtl01234567); |
| 55 |
|
| 56 |
const int16x8_t vdd01234567 = vsubq_s16(vbd01234567, vtd01234567); |
| 57 |
|
| 58 |
#if XNN_ARCH_ARM64 |
| 59 |
const int32x4_t vt0123 = vmlal_s16(vshll_n_s16(vget_low_s16(vxtl01234567), 11), vget_low_s16(vtd01234567), vget_low_s16(valphah)); |
| 60 |
const int32x4_t vt4567 = vmlal_high_s16(vshll_n_s16(vget_high_s16(vxtl01234567), 11), vtd01234567, valphah); |
| 61 |
|
| 62 |
const int32x4_t vd0123 = vmlal_s16(vshll_n_s16(vget_low_s16(vdl01234567), 11), vget_low_s16(vdd01234567), vget_low_s16(valphah)); |
| 63 |
const int32x4_t vd4567 = vmlal_high_s16(vshll_n_s16(vget_high_s16(vdl01234567), 11), vdd01234567, valphah); |
| 64 |
#else |
| 65 |
const int32x4_t vt0123 = vmlal_s16(vshll_n_s16(vget_low_s16(vxtl01234567), 11), vget_low_s16(vtd01234567), valphah); |
| 66 |
const int32x4_t vt4567 = vmlal_s16(vshll_n_s16(vget_high_s16(vxtl01234567), 11), vget_high_s16(vtd01234567), valphah); |
| 67 |
|
| 68 |
const int32x4_t vd0123 = vmlal_s16(vshll_n_s16(vget_low_s16(vdl01234567), 11), vget_low_s16(vdd01234567), valphah); |
| 69 |
const int32x4_t vd4567 = vmlal_s16(vshll_n_s16(vget_high_s16(vdl01234567), 11), vget_high_s16(vdd01234567), valphah); |
| 70 |
#endif |
| 71 |
|
| 72 |
const int32x4_t vacc0123 = vmlaq_s32(vshlq_n_s32(vt0123, 11), vd0123, valphav); |
| 73 |
const int32x4_t vacc4567 = vmlaq_s32(vshlq_n_s32(vt4567, 11), vd4567, valphav); |
| 74 |
|
| 75 |
#if XNN_ARCH_ARM64 |
| 76 |
const int16x8_t vacc01234567 = vuzp2q_s16(vreinterpretq_s16_s32(vacc0123), vreinterpretq_s16_s32(vacc4567)); |
| 77 |
#else |
| 78 |
const int16x8_t vacc01234567 = vcombine_s16(vshrn_n_s32(vacc0123, 16), vshrn_n_s32(vacc4567, 16)); |
| 79 |
#endif |
| 80 |
|
| 81 |
const int8x8_t vo01234567 = vrshrn_n_s16(vacc01234567, 6); |
| 82 |
|
| 83 |
vst1_s8(output, vo01234567); output += 8; |
| 84 |
} |
| 85 |
if XNN_UNLIKELY(c != 0) { |
| 86 |
const int8x8_t vtl01234567 = vld1_s8(i0); |
| 87 |
const int8x8_t vtr01234567 = vld1_s8(i1); |
| 88 |
const int8x8_t vbl01234567 = vld1_s8(i2); |
| 89 |
const int8x8_t vbr01234567 = vld1_s8(i3); |
| 90 |
|
| 91 |
const int16x8_t vtd01234567 = vsubl_s8(vtr01234567, vtl01234567); |
| 92 |
const int16x8_t vbd01234567 = vsubl_s8(vbr01234567, vbl01234567); |
| 93 |
const int16x8_t vdl01234567 = vsubl_s8(vbl01234567, vtl01234567); |
| 94 |
const int16x8_t vxtl01234567 = vmovl_s8(vtl01234567); |
| 95 |
|
| 96 |
const int16x8_t vdd01234567 = vsubq_s16(vbd01234567, vtd01234567); |
| 97 |
|
| 98 |
#if XNN_ARCH_ARM64 |
| 99 |
const int32x4_t vt0123 = vmlal_s16(vshll_n_s16(vget_low_s16(vxtl01234567), 11), vget_low_s16(vtd01234567), vget_low_s16(valphah)); |
| 100 |
const int32x4_t vt4567 = vmlal_high_s16(vshll_n_s16(vget_high_s16(vxtl01234567), 11), vtd01234567, valphah); |
| 101 |
|
| 102 |
const int32x4_t vd0123 = vmlal_s16(vshll_n_s16(vget_low_s16(vdl01234567), 11), vget_low_s16(vdd01234567), vget_low_s16(valphah)); |
| 103 |
const int32x4_t vd4567 = vmlal_high_s16(vshll_n_s16(vget_high_s16(vdl01234567), 11), vdd01234567, valphah); |
| 104 |
#else |
| 105 |
const int32x4_t vt0123 = vmlal_s16(vshll_n_s16(vget_low_s16(vxtl01234567), 11), vget_low_s16(vtd01234567), valphah); |
| 106 |
const int32x4_t vt4567 = vmlal_s16(vshll_n_s16(vget_high_s16(vxtl01234567), 11), vget_high_s16(vtd01234567), valphah); |
| 107 |
|
| 108 |
const int32x4_t vd0123 = vmlal_s16(vshll_n_s16(vget_low_s16(vdl01234567), 11), vget_low_s16(vdd01234567), valphah); |
| 109 |
const int32x4_t vd4567 = vmlal_s16(vshll_n_s16(vget_high_s16(vdl01234567), 11), vget_high_s16(vdd01234567), valphah); |
| 110 |
#endif |
| 111 |
|
| 112 |
const int32x4_t vacc0123 = vmlaq_s32(vshlq_n_s32(vt0123, 11), vd0123, valphav); |
| 113 |
const int32x4_t vacc4567 = vmlaq_s32(vshlq_n_s32(vt4567, 11), vd4567, valphav); |
| 114 |
|
| 115 |
#if XNN_ARCH_ARM64 |
| 116 |
const int16x8_t vacc01234567 = vuzp2q_s16(vreinterpretq_s16_s32(vacc0123), vreinterpretq_s16_s32(vacc4567)); |
| 117 |
#else |
| 118 |
const int16x8_t vacc01234567 = vcombine_s16(vshrn_n_s32(vacc0123, 16), vshrn_n_s32(vacc4567, 16)); |
| 119 |
#endif |
| 120 |
|
| 121 |
int8x8_t vo01234567 = vrshrn_n_s16(vacc01234567, 6); |
| 122 |
|
| 123 |
if (c & (4 * sizeof(int8_t))) { |
| 124 |
vst1_lane_u32((void*) output, vreinterpret_u32_s8(vo01234567), 0); output += 4; |
| 125 |
vo01234567 = vext_s8(vo01234567, vo01234567, 4); |
| 126 |
} |
| 127 |
if (c & (2 * sizeof(int8_t))) { |
| 128 |
vst1_lane_u16((void*) output, vreinterpret_u16_s8(vo01234567), 0); output += 2; |
| 129 |
vo01234567 = vext_s8(vo01234567, vo01234567, 2); |
| 130 |
} |
| 131 |
if (c & (1 * sizeof(int8_t))) { |
| 132 |
vst1_lane_s8(output, vo01234567, 0); output += 1; |
| 133 |
} |
| 134 |
} |
| 135 |
|
| 136 |
output = (int8_t*) ((uintptr_t) output + output_increment); |
| 137 |
} while (--output_pixels != 0); |
| 138 |
} |