| 1 |
// Auto-generated file. Do not edit! |
| 2 |
// Template: src/qs8-dwconv/unipass-neon-mul16.c.in |
| 3 |
// Generator: tools/xngen |
| 4 |
// |
| 5 |
// Copyright 2020 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/dwconv.h" |
| 15 |
|
| 16 |
|
| 17 |
void xnn_qs8_dwconv_minmax_rndnu_ukernel_9p8c__neon_mul16( |
| 18 |
size_t channels, |
| 19 |
size_t output_width, |
| 20 |
const int8_t** input, |
| 21 |
const void* weights, |
| 22 |
int8_t* output, |
| 23 |
intptr_t input_stride, |
| 24 |
size_t output_increment, |
| 25 |
size_t input_offset, |
| 26 |
const int8_t* zero, |
| 27 |
const union xnn_qs8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS |
| 28 |
{ |
| 29 |
assert(channels != 0); |
| 30 |
assert(output_width != 0); |
| 31 |
|
| 32 |
const int32x4_t vright_pre_shift = vld1q_dup_s32(¶ms->rndnu_neon.right_pre_shift); |
| 33 |
const int32x4_t vmultiplier = vld1q_dup_s32(¶ms->rndnu_neon.multiplier); |
| 34 |
const int32x4_t vright_post_shift = vld1q_dup_s32(¶ms->rndnu_neon.right_post_shift); |
| 35 |
const int16x8_t voutput_zero_point = vld1q_dup_s16(¶ms->rndnu_neon.output_zero_point); |
| 36 |
const int8x8_t voutput_min = vld1_dup_s8(¶ms->rndnu_neon.output_min); |
| 37 |
const int8x8_t voutput_max = vld1_dup_s8(¶ms->rndnu_neon.output_max); |
| 38 |
do { |
| 39 |
const int8_t* i0 = input[0]; |
| 40 |
assert(i0 != NULL); |
| 41 |
if XNN_UNPREDICTABLE(i0 != zero) { |
| 42 |
i0 = (const int8_t*) ((uintptr_t) i0 + input_offset); |
| 43 |
} |
| 44 |
const int8_t* i1 = input[1]; |
| 45 |
assert(i1 != NULL); |
| 46 |
if XNN_UNPREDICTABLE(i1 != zero) { |
| 47 |
i1 = (const int8_t*) ((uintptr_t) i1 + input_offset); |
| 48 |
} |
| 49 |
const int8_t* i2 = input[2]; |
| 50 |
assert(i2 != NULL); |
| 51 |
if XNN_UNPREDICTABLE(i2 != zero) { |
| 52 |
i2 = (const int8_t*) ((uintptr_t) i2 + input_offset); |
| 53 |
} |
| 54 |
const int8_t* i3 = input[3]; |
| 55 |
assert(i3 != NULL); |
| 56 |
if XNN_UNPREDICTABLE(i3 != zero) { |
| 57 |
i3 = (const int8_t*) ((uintptr_t) i3 + input_offset); |
| 58 |
} |
| 59 |
const int8_t* i4 = input[4]; |
| 60 |
assert(i4 != NULL); |
| 61 |
if XNN_UNPREDICTABLE(i4 != zero) { |
| 62 |
i4 = (const int8_t*) ((uintptr_t) i4 + input_offset); |
| 63 |
} |
| 64 |
const int8_t* i5 = input[5]; |
| 65 |
assert(i5 != NULL); |
| 66 |
if XNN_UNPREDICTABLE(i5 != zero) { |
| 67 |
i5 = (const int8_t*) ((uintptr_t) i5 + input_offset); |
| 68 |
} |
| 69 |
const int8_t* i6 = input[6]; |
| 70 |
assert(i6 != NULL); |
| 71 |
if XNN_UNPREDICTABLE(i6 != zero) { |
| 72 |
i6 = (const int8_t*) ((uintptr_t) i6 + input_offset); |
| 73 |
} |
| 74 |
const int8_t* i7 = input[7]; |
| 75 |
assert(i7 != NULL); |
| 76 |
if XNN_UNPREDICTABLE(i7 != zero) { |
| 77 |
i7 = (const int8_t*) ((uintptr_t) i7 + input_offset); |
| 78 |
} |
| 79 |
const int8_t* i8 = input[8]; |
| 80 |
assert(i8 != NULL); |
| 81 |
if XNN_UNPREDICTABLE(i8 != zero) { |
| 82 |
i8 = (const int8_t*) ((uintptr_t) i8 + input_offset); |
| 83 |
} |
| 84 |
input = (const int8_t**) ((uintptr_t) input + input_stride); |
| 85 |
|
| 86 |
size_t c = channels; |
| 87 |
const void* w = weights; |
| 88 |
for (; c >= 8; c -= 8) { |
| 89 |
int32x4_t vacc0123 = vld1q_s32(w); w = (const void*) ((const int32_t*) w + 4); |
| 90 |
int32x4_t vacc4567 = vld1q_s32(w); w = (const void*) ((const int32_t*) w + 4); |
| 91 |
|
| 92 |
|
| 93 |
const int16x8_t vi0x01234567 = vmovl_s8(vld1_s8(i0)); i0 += 8; |
| 94 |
const int16x8_t vk0x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8; |
| 95 |
|
| 96 |
vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi0x01234567), vget_low_s16(vk0x01234567)); |
| 97 |
vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi0x01234567), vget_high_s16(vk0x01234567)); |
| 98 |
|
| 99 |
const int16x8_t vi1x01234567 = vmovl_s8(vld1_s8(i1)); i1 += 8; |
| 100 |
const int16x8_t vk1x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8; |
| 101 |
|
| 102 |
vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi1x01234567), vget_low_s16(vk1x01234567)); |
| 103 |
vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi1x01234567), vget_high_s16(vk1x01234567)); |
| 104 |
|
| 105 |
const int16x8_t vi2x01234567 = vmovl_s8(vld1_s8(i2)); i2 += 8; |
| 106 |
const int16x8_t vk2x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8; |
| 107 |
|
| 108 |
vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi2x01234567), vget_low_s16(vk2x01234567)); |
| 109 |
vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi2x01234567), vget_high_s16(vk2x01234567)); |
| 110 |
|
| 111 |
const int16x8_t vi3x01234567 = vmovl_s8(vld1_s8(i3)); i3 += 8; |
| 112 |
const int16x8_t vk3x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8; |
| 113 |
|
| 114 |
vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi3x01234567), vget_low_s16(vk3x01234567)); |
| 115 |
vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi3x01234567), vget_high_s16(vk3x01234567)); |
| 116 |
|
| 117 |
const int16x8_t vi4x01234567 = vmovl_s8(vld1_s8(i4)); i4 += 8; |
| 118 |
const int16x8_t vk4x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8; |
| 119 |
|
| 120 |
vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi4x01234567), vget_low_s16(vk4x01234567)); |
| 121 |
vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi4x01234567), vget_high_s16(vk4x01234567)); |
| 122 |
|
| 123 |
const int16x8_t vi5x01234567 = vmovl_s8(vld1_s8(i5)); i5 += 8; |
| 124 |
const int16x8_t vk5x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8; |
| 125 |
|
| 126 |
vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi5x01234567), vget_low_s16(vk5x01234567)); |
| 127 |
vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi5x01234567), vget_high_s16(vk5x01234567)); |
| 128 |
|
| 129 |
const int16x8_t vi6x01234567 = vmovl_s8(vld1_s8(i6)); i6 += 8; |
| 130 |
const int16x8_t vk6x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8; |
| 131 |
|
| 132 |
vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi6x01234567), vget_low_s16(vk6x01234567)); |
| 133 |
vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi6x01234567), vget_high_s16(vk6x01234567)); |
| 134 |
|
| 135 |
const int16x8_t vi7x01234567 = vmovl_s8(vld1_s8(i7)); i7 += 8; |
| 136 |
const int16x8_t vk7x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8; |
| 137 |
|
| 138 |
vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi7x01234567), vget_low_s16(vk7x01234567)); |
| 139 |
vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi7x01234567), vget_high_s16(vk7x01234567)); |
| 140 |
|
| 141 |
const int16x8_t vi8x01234567 = vmovl_s8(vld1_s8(i8)); i8 += 8; |
| 142 |
const int16x8_t vk8x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8; |
| 143 |
|
| 144 |
vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi8x01234567), vget_low_s16(vk8x01234567)); |
| 145 |
vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi8x01234567), vget_high_s16(vk8x01234567)); |
| 146 |
|
| 147 |
vacc0123 = vqshlq_s32(vacc0123, vright_pre_shift); |
| 148 |
vacc4567 = vqshlq_s32(vacc4567, vright_pre_shift); |
| 149 |
|
| 150 |
vacc0123 = vqdmulhq_s32(vacc0123, vmultiplier); |
| 151 |
vacc4567 = vqdmulhq_s32(vacc4567, vmultiplier); |
| 152 |
|
| 153 |
vacc0123 = vrshlq_s32(vacc0123, vright_post_shift); |
| 154 |
vacc4567 = vrshlq_s32(vacc4567, vright_post_shift); |
| 155 |
|
| 156 |
#if XNN_ARCH_ARM64 |
| 157 |
int16x8_t vacc01234567 = vqmovn_high_s32(vqmovn_s32(vacc0123), vacc4567); |
| 158 |
|
| 159 |
vacc01234567 = vqaddq_s16(vacc01234567, voutput_zero_point); |
| 160 |
|
| 161 |
int8x8_t vout01234567 = vqmovn_s16(vacc01234567); |
| 162 |
#else // !XNN_ARCH_ARM64 |
| 163 |
int16x8_t vacc01234567 = vcombine_s16(vqmovn_s32(vacc0123), vqmovn_s32(vacc4567)); |
| 164 |
|
| 165 |
vacc01234567 = vqaddq_s16(vacc01234567, voutput_zero_point); |
| 166 |
|
| 167 |
int8x8_t vout01234567 = vqmovn_s16(vacc01234567); |
| 168 |
#endif // !XNN_ARCH_ARM64 |
| 169 |
|
| 170 |
vout01234567 = vmax_s8(vout01234567, voutput_min); |
| 171 |
|
| 172 |
vout01234567 = vmin_s8(vout01234567, voutput_max); |
| 173 |
|
| 174 |
vst1_s8(output, vout01234567); output += 8; |
| 175 |
} |
| 176 |
if XNN_UNLIKELY(c != 0) { |
| 177 |
{ |
| 178 |
int32x4_t vacc0123 = vld1q_s32(w); w = (const void*) ((const int32_t*) w + 4); |
| 179 |
int32x4_t vacc4567 = vld1q_s32(w); w = (const void*) ((const int32_t*) w + 4); |
| 180 |
|
| 181 |
const int16x8_t vi0x01234567 = vmovl_s8(vld1_s8(i0)); |
| 182 |
const int16x8_t vk0x01234567 = vmovl_s8(vld1_s8(w)); |
| 183 |
|
| 184 |
vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi0x01234567), vget_low_s16(vk0x01234567)); |
| 185 |
vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi0x01234567), vget_high_s16(vk0x01234567)); |
| 186 |
const int16x8_t vi1x01234567 = vmovl_s8(vld1_s8(i1)); |
| 187 |
const int16x8_t vk1x01234567 = vmovl_s8(vld1_s8((const void*) ((const int8_t*) w + 8))); |
| 188 |
|
| 189 |
vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi1x01234567), vget_low_s16(vk1x01234567)); |
| 190 |
vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi1x01234567), vget_high_s16(vk1x01234567)); |
| 191 |
const int16x8_t vi2x01234567 = vmovl_s8(vld1_s8(i2)); |
| 192 |
const int16x8_t vk2x01234567 = vmovl_s8(vld1_s8((const void*) ((const int8_t*) w + 16))); |
| 193 |
|
| 194 |
vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi2x01234567), vget_low_s16(vk2x01234567)); |
| 195 |
vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi2x01234567), vget_high_s16(vk2x01234567)); |
| 196 |
const int16x8_t vi3x01234567 = vmovl_s8(vld1_s8(i3)); |
| 197 |
const int16x8_t vk3x01234567 = vmovl_s8(vld1_s8((const void*) ((const int8_t*) w + 24))); |
| 198 |
|
| 199 |
vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi3x01234567), vget_low_s16(vk3x01234567)); |
| 200 |
vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi3x01234567), vget_high_s16(vk3x01234567)); |
| 201 |
const int16x8_t vi4x01234567 = vmovl_s8(vld1_s8(i4)); |
| 202 |
const int16x8_t vk4x01234567 = vmovl_s8(vld1_s8((const void*) ((const int8_t*) w + 32))); |
| 203 |
|
| 204 |
vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi4x01234567), vget_low_s16(vk4x01234567)); |
| 205 |
vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi4x01234567), vget_high_s16(vk4x01234567)); |
| 206 |
const int16x8_t vi5x01234567 = vmovl_s8(vld1_s8(i5)); |
| 207 |
const int16x8_t vk5x01234567 = vmovl_s8(vld1_s8((const void*) ((const int8_t*) w + 40))); |
| 208 |
|
| 209 |
vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi5x01234567), vget_low_s16(vk5x01234567)); |
| 210 |
vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi5x01234567), vget_high_s16(vk5x01234567)); |
| 211 |
const int16x8_t vi6x01234567 = vmovl_s8(vld1_s8(i6)); |
| 212 |
const int16x8_t vk6x01234567 = vmovl_s8(vld1_s8((const void*) ((const int8_t*) w + 48))); |
| 213 |
|
| 214 |
vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi6x01234567), vget_low_s16(vk6x01234567)); |
| 215 |
vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi6x01234567), vget_high_s16(vk6x01234567)); |
| 216 |
const int16x8_t vi7x01234567 = vmovl_s8(vld1_s8(i7)); |
| 217 |
const int16x8_t vk7x01234567 = vmovl_s8(vld1_s8((const void*) ((const int8_t*) w + 56))); |
| 218 |
|
| 219 |
vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi7x01234567), vget_low_s16(vk7x01234567)); |
| 220 |
vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi7x01234567), vget_high_s16(vk7x01234567)); |
| 221 |
const int16x8_t vi8x01234567 = vmovl_s8(vld1_s8(i8)); |
| 222 |
const int16x8_t vk8x01234567 = vmovl_s8(vld1_s8((const void*) ((const int8_t*) w + 64))); |
| 223 |
|
| 224 |
vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi8x01234567), vget_low_s16(vk8x01234567)); |
| 225 |
vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi8x01234567), vget_high_s16(vk8x01234567)); |
| 226 |
|
| 227 |
vacc0123 = vqshlq_s32(vacc0123, vright_pre_shift); |
| 228 |
vacc4567 = vqshlq_s32(vacc4567, vright_pre_shift); |
| 229 |
|
| 230 |
vacc0123 = vqdmulhq_s32(vacc0123, vmultiplier); |
| 231 |
vacc4567 = vqdmulhq_s32(vacc4567, vmultiplier); |
| 232 |
|
| 233 |
vacc0123 = vrshlq_s32(vacc0123, vright_post_shift); |
| 234 |
vacc4567 = vrshlq_s32(vacc4567, vright_post_shift); |
| 235 |
|
| 236 |
#if XNN_ARCH_ARM64 |
| 237 |
int16x8_t vacc01234567 = vqmovn_high_s32(vqmovn_s32(vacc0123), vacc4567); |
| 238 |
#else |
| 239 |
int16x8_t vacc01234567 = vcombine_s16(vqmovn_s32(vacc0123), vqmovn_s32(vacc4567)); |
| 240 |
#endif |
| 241 |
vacc01234567 = vqaddq_s16(vacc01234567, voutput_zero_point); |
| 242 |
|
| 243 |
int8x8_t vout01234567 = vqmovn_s16(vacc01234567); |
| 244 |
vout01234567 = vmax_s8(vout01234567, voutput_min); |
| 245 |
vout01234567 = vmin_s8(vout01234567, voutput_max); |
| 246 |
|
| 247 |
if (c & 4) { |
| 248 |
vst1_lane_u32((void*) output, vreinterpret_u32_s8(vout01234567), 0); output += 4; |
| 249 |
vout01234567 = vext_s8(vout01234567, vout01234567, 4); |
| 250 |
} |
| 251 |
if (c & 2) { |
| 252 |
vst1_lane_u16((void*) output, vreinterpret_u16_s8(vout01234567), 0); output += 2; |
| 253 |
vout01234567 = vext_s8(vout01234567, vout01234567, 2); |
| 254 |
} |
| 255 |
if (c & 1) { |
| 256 |
vst1_lane_s8(output, vout01234567, 0); output += 1; |
| 257 |
} |
| 258 |
} |
| 259 |
} |
| 260 |
|
| 261 |
output = (int8_t*) ((uintptr_t) output + output_increment); |
| 262 |
} while (--output_width != 0); |
| 263 |
} |