| 1 |
// Auto-generated file. Do not edit! |
| 2 |
// Template: src/f16-f32acc-rsum/neonfp16arith.c.in |
| 3 |
// Generator: tools/xngen |
| 4 |
// |
| 5 |
// Copyright 2023 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/reduce.h" |
| 16 |
|
| 17 |
|
| 18 |
void xnn_f16_f32acc_rsum_ukernel__neonfp16arith_u32_acc2( |
| 19 |
size_t batch, |
| 20 |
const xnn_float16* input, |
| 21 |
float* output, |
| 22 |
const struct xnn_f16_f32acc_scale_params params[restrict XNN_MIN_ELEMENTS(1)]) |
| 23 |
{ |
| 24 |
assert(batch != 0); |
| 25 |
assert(batch % sizeof(uint16_t) == 0); |
| 26 |
assert(input != NULL); |
| 27 |
assert(output != NULL); |
| 28 |
|
| 29 |
const uint16_t* i = (const uint16_t*) input; |
| 30 |
float32x4_t vacc0 = vmovq_n_f32(0.0f); |
| 31 |
float32x4_t vacc1 = vmovq_n_f32(0.0f); |
| 32 |
for (; batch >= 32 * sizeof(uint16_t); batch -= 32 * sizeof(uint16_t)) { |
| 33 |
const float16x8_t vh01 = vreinterpretq_f16_u16(vld1q_u16(i)); i += 8; |
| 34 |
const float16x8_t vh23 = vreinterpretq_f16_u16(vld1q_u16(i)); i += 8; |
| 35 |
const float16x8_t vh45 = vreinterpretq_f16_u16(vld1q_u16(i)); i += 8; |
| 36 |
const float16x8_t vh67 = vreinterpretq_f16_u16(vld1q_u16(i)); i += 8; |
| 37 |
|
| 38 |
const float32x4_t vt0 = vcvt_f32_f16(vget_low_f16(vh01)); |
| 39 |
const float32x4_t vt1 = vcvt_f32_f16(vget_high_f16(vh01)); |
| 40 |
const float32x4_t vt2 = vcvt_f32_f16(vget_low_f16(vh23)); |
| 41 |
const float32x4_t vt3 = vcvt_f32_f16(vget_high_f16(vh23)); |
| 42 |
const float32x4_t vt4 = vcvt_f32_f16(vget_low_f16(vh45)); |
| 43 |
const float32x4_t vt5 = vcvt_f32_f16(vget_high_f16(vh45)); |
| 44 |
const float32x4_t vt6 = vcvt_f32_f16(vget_low_f16(vh67)); |
| 45 |
const float32x4_t vt7 = vcvt_f32_f16(vget_high_f16(vh67)); |
| 46 |
|
| 47 |
vacc0 = vaddq_f32(vacc0, vt0); |
| 48 |
vacc1 = vaddq_f32(vacc1, vt1); |
| 49 |
vacc0 = vaddq_f32(vacc0, vt2); |
| 50 |
vacc1 = vaddq_f32(vacc1, vt3); |
| 51 |
vacc0 = vaddq_f32(vacc0, vt4); |
| 52 |
vacc1 = vaddq_f32(vacc1, vt5); |
| 53 |
vacc0 = vaddq_f32(vacc0, vt6); |
| 54 |
vacc1 = vaddq_f32(vacc1, vt7); |
| 55 |
} |
| 56 |
vacc0 = vaddq_f32(vacc0, vacc1); |
| 57 |
for (; batch >= 4 * sizeof(uint16_t); batch -= 4 * sizeof(uint16_t)) { |
| 58 |
const float16x4_t vh = vreinterpret_f16_u16(vld1_u16(i)); i += 4; |
| 59 |
const float32x4_t vt = vcvt_f32_f16(vh); |
| 60 |
vacc0 = vaddq_f32(vacc0, vt); |
| 61 |
} |
| 62 |
const float32x2_t vscale = vld1_dup_f32(¶ms->scalar.scale); |
| 63 |
float32x2_t vacc = vadd_f32(vget_low_f32(vacc0), vget_high_f32(vacc0)); |
| 64 |
if XNN_UNLIKELY(batch & (2 * sizeof(uint16_t))) { |
| 65 |
const float16x4_t vh = vreinterpret_f16_u32(vld1_dup_u32((const void*) i)); i += 2; |
| 66 |
const float32x4_t vt = vcvt_f32_f16(vh); |
| 67 |
vacc = vadd_f32(vacc, vget_low_f32(vt)); |
| 68 |
} |
| 69 |
vacc = vpadd_f32(vacc, vacc); |
| 70 |
if XNN_UNLIKELY(batch & (1 * sizeof(uint16_t))) { |
| 71 |
const float16x4_t vh = vreinterpret_f16_u16(vld1_dup_u16(i)); |
| 72 |
const float32x4_t vt = vcvt_f32_f16(vh); |
| 73 |
vacc = vadd_f32(vacc, vget_low_f32(vt)); |
| 74 |
} |
| 75 |
vacc = vmul_f32(vacc, vscale); |
| 76 |
|
| 77 |
float vout = vget_lane_f32(vacc, 0); |
| 78 |
*output += vout; |
| 79 |
} |