| 1 |
// Auto-generated file. Do not edit! |
| 2 |
// Template: src/qs8-rsum/neon.c.in |
| 3 |
// Generator: tools/xngen |
| 4 |
// |
| 5 |
// Copyright 2024 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 |
|
| 11 |
#include <assert.h> |
| 12 |
|
| 13 |
#include <arm_neon.h> |
| 14 |
|
| 15 |
#include "xnnpack/common.h" |
| 16 |
#include "xnnpack/reduce.h" |
| 17 |
|
| 18 |
void xnn_qu8_rsum_ukernel__neon_u16( |
| 19 |
size_t batch, |
| 20 |
const uint8_t* input, |
| 21 |
uint32_t* output, |
| 22 |
const struct xnn_qs8_rsum_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS |
| 23 |
{ |
| 24 |
assert(batch != 0); |
| 25 |
assert(input != NULL); |
| 26 |
assert(output != NULL); |
| 27 |
assert(params != NULL); |
| 28 |
|
| 29 |
XNN_ALIGN(16) static const uint8_t onemask_table[32] = { |
| 30 |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
| 31 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 32 |
}; |
| 33 |
|
| 34 |
uint32x4_t vacc0 = vmovq_n_u32(0); |
| 35 |
|
| 36 |
// 256 uint8s may be summed into an uint16 before overflowing. |
| 37 |
// Each register has 8 lanes and there are 1 accumulators so batch size is 2048 |
| 38 |
|
| 39 |
for (; batch >= 2048; batch -= 2048) { |
| 40 |
uint16x8_t vacc16_0 = vmovq_n_u16(0); |
| 41 |
for (size_t current_batch = 2048; current_batch > 0; current_batch -= 16) { |
| 42 |
const uint8x16_t vt0 = vld1q_u8(input); input += 16; |
| 43 |
vacc16_0 = vpadalq_u8(vacc16_0, vt0); |
| 44 |
} |
| 45 |
vacc0 = vpadalq_u16(vacc0, vacc16_0); |
| 46 |
} |
| 47 |
|
| 48 |
if (XNN_UNLIKELY(batch != 0)) { |
| 49 |
assert(batch >= 1 && batch < 2048); |
| 50 |
uint16x8_t vacc16 = vmovq_n_u16(0); |
| 51 |
for (; batch >= 16; batch -= 16) { |
| 52 |
const uint8x16_t vt = vld1q_u8(input); input += 16; |
| 53 |
vacc16 = vpadalq_u8(vacc16, vt); |
| 54 |
} |
| 55 |
if (XNN_UNLIKELY(batch != 0)) { |
| 56 |
const uint8x16_t vt = vld1q_u8(input); |
| 57 |
const uint8x16_t vonemask = vld1q_u8(&onemask_table[16 - batch]); |
| 58 |
const uint8x16_t vtm = vmulq_u8(vt, vonemask); |
| 59 |
vacc16 = vpadalq_u8(vacc16, vtm); |
| 60 |
} |
| 61 |
vacc0 = vpadalq_u16(vacc0, vacc16); |
| 62 |
} |
| 63 |
#if XNN_ARCH_ARM64 |
| 64 |
const uint32_t vacc = vaddvq_u32(vacc0); |
| 65 |
#else |
| 66 |
uint32x2_t vacc_lo = vadd_u32(vget_low_u32(vacc0), vget_high_u32(vacc0)); |
| 67 |
vacc_lo = vpadd_u32(vacc_lo, vacc_lo); |
| 68 |
const uint32_t vacc = vget_lane_u32(vacc_lo, 0); |
| 69 |
#endif |
| 70 |
|
| 71 |
*output += vacc; |
| 72 |
} |