| 1 |
// Auto-generated file. Do not edit! |
| 2 |
// Template: src/f16-vcmul/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/vbinary.h" |
| 16 |
|
| 17 |
|
| 18 |
void xnn_f16_vcmul_ukernel__neonfp16arith_u16( |
| 19 |
size_t batch, |
| 20 |
const xnn_float16* input_a, |
| 21 |
const xnn_float16* input_b, |
| 22 |
xnn_float16* output, |
| 23 |
const struct xnn_f16_default_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS |
| 24 |
{ |
| 25 |
assert(batch != 0); |
| 26 |
assert(batch % sizeof(uint16_t) == 0); |
| 27 |
assert(input_a != NULL); |
| 28 |
assert(input_b != NULL); |
| 29 |
assert(output != NULL); |
| 30 |
|
| 31 |
const uint16_t* ar = (const uint16_t*) input_a; |
| 32 |
const uint16_t* ai = (const uint16_t*) ((uintptr_t) input_a + batch); |
| 33 |
const uint16_t* br = (const uint16_t*) input_b; |
| 34 |
const uint16_t* bi = (const uint16_t*) ((uintptr_t) input_b + batch); |
| 35 |
uint16_t* or = (uint16_t*) output; |
| 36 |
uint16_t* oi = (uint16_t*) ((uintptr_t) output + batch); |
| 37 |
for (; batch >= 16 * sizeof(uint16_t); batch -= 16 * sizeof(uint16_t)) { |
| 38 |
const float16x8_t va0r = vreinterpretq_f16_u16(vld1q_u16(ar)); ar += 8; |
| 39 |
const float16x8_t va0i = vreinterpretq_f16_u16(vld1q_u16(ai)); ai += 8; |
| 40 |
const float16x8_t vb0r = vreinterpretq_f16_u16(vld1q_u16(br)); br += 8; |
| 41 |
const float16x8_t vb0i = vreinterpretq_f16_u16(vld1q_u16(bi)); bi += 8; |
| 42 |
const float16x8_t va1r = vreinterpretq_f16_u16(vld1q_u16(ar)); ar += 8; |
| 43 |
const float16x8_t va1i = vreinterpretq_f16_u16(vld1q_u16(ai)); ai += 8; |
| 44 |
const float16x8_t vb1r = vreinterpretq_f16_u16(vld1q_u16(br)); br += 8; |
| 45 |
const float16x8_t vb1i = vreinterpretq_f16_u16(vld1q_u16(bi)); bi += 8; |
| 46 |
|
| 47 |
float16x8_t vacc0r = vmulq_f16(va0r, vb0r); |
| 48 |
float16x8_t vacc0i = vmulq_f16(va0r, vb0i); |
| 49 |
float16x8_t vacc1r = vmulq_f16(va1r, vb1r); |
| 50 |
float16x8_t vacc1i = vmulq_f16(va1r, vb1i); |
| 51 |
|
| 52 |
vacc0r = vfmsq_f16(vacc0r, va0i, vb0i); |
| 53 |
vacc0i = vfmaq_f16(vacc0i, va0i, vb0r); |
| 54 |
vacc1r = vfmsq_f16(vacc1r, va1i, vb1i); |
| 55 |
vacc1i = vfmaq_f16(vacc1i, va1i, vb1r); |
| 56 |
|
| 57 |
vst1q_u16(or, vreinterpretq_u16_f16(vacc0r)); or += 8; |
| 58 |
vst1q_u16(oi, vreinterpretq_u16_f16(vacc0i)); oi += 8; |
| 59 |
vst1q_u16(or, vreinterpretq_u16_f16(vacc1r)); or += 8; |
| 60 |
vst1q_u16(oi, vreinterpretq_u16_f16(vacc1i)); oi += 8; |
| 61 |
} |
| 62 |
for (; batch >= 8 * sizeof(uint16_t); batch -= 8 * sizeof(uint16_t)) { |
| 63 |
const float16x8_t var = vreinterpretq_f16_u16(vld1q_u16(ar)); ar += 8; |
| 64 |
const float16x8_t vai = vreinterpretq_f16_u16(vld1q_u16(ai)); ai += 8; |
| 65 |
const float16x8_t vbr = vreinterpretq_f16_u16(vld1q_u16(br)); br += 8; |
| 66 |
const float16x8_t vbi = vreinterpretq_f16_u16(vld1q_u16(bi)); bi += 8; |
| 67 |
|
| 68 |
float16x8_t vaccr = vmulq_f16(var, vbr); |
| 69 |
float16x8_t vacci = vmulq_f16(var, vbi); |
| 70 |
|
| 71 |
vaccr = vfmsq_f16(vaccr, vai, vbi); |
| 72 |
vacci = vfmaq_f16(vacci, vai, vbr); |
| 73 |
|
| 74 |
vst1q_u16(or, vreinterpretq_u16_f16(vaccr)); or += 8; |
| 75 |
vst1q_u16(oi, vreinterpretq_u16_f16(vacci)); oi += 8; |
| 76 |
} |
| 77 |
if XNN_UNLIKELY(batch != 0) { |
| 78 |
const float16x8_t var = vreinterpretq_f16_u16(vld1q_u16(ar)); ar += 8; |
| 79 |
const float16x8_t vai = vreinterpretq_f16_u16(vld1q_u16(ai)); ai += 8; |
| 80 |
const float16x8_t vbr = vreinterpretq_f16_u16(vld1q_u16(br)); br += 8; |
| 81 |
const float16x8_t vbi = vreinterpretq_f16_u16(vld1q_u16(bi)); bi += 8; |
| 82 |
|
| 83 |
float16x8_t vaccr = vmulq_f16(var, vbr); |
| 84 |
float16x8_t vacci = vmulq_f16(var, vbi); |
| 85 |
|
| 86 |
vaccr = vfmsq_f16(vaccr, vai, vbi); |
| 87 |
vacci = vfmaq_f16(vacci, vai, vbr); |
| 88 |
|
| 89 |
float16x4_t vaccr_lo = vget_low_f16(vaccr); |
| 90 |
float16x4_t vacci_lo = vget_low_f16(vacci); |
| 91 |
if (batch & (4 * sizeof(uint16_t))) { |
| 92 |
vst1_u16(or, vreinterpret_u16_f16(vaccr_lo)); or += 4; |
| 93 |
vst1_u16(oi, vreinterpret_u16_f16(vacci_lo)); oi += 4; |
| 94 |
vaccr_lo = vget_high_f16(vaccr); |
| 95 |
vacci_lo = vget_high_f16(vacci); |
| 96 |
} |
| 97 |
if (batch & (2 * sizeof(uint16_t))) { |
| 98 |
vst1_lane_u32((void*) or, vreinterpret_u32_f16(vaccr_lo), 0); or += 2; |
| 99 |
vst1_lane_u32((void*) oi, vreinterpret_u32_f16(vacci_lo), 0); oi += 2; |
| 100 |
vaccr_lo = vext_f16(vaccr_lo, vaccr_lo, 2); |
| 101 |
vacci_lo = vext_f16(vacci_lo, vacci_lo, 2); |
| 102 |
} |
| 103 |
if (batch & (1 * sizeof(uint16_t))) { |
| 104 |
vst1_lane_u16(or, vreinterpret_u16_f16(vaccr_lo), 0); |
| 105 |
vst1_lane_u16(oi, vreinterpret_u16_f16(vacci_lo), 0); |
| 106 |
} |
| 107 |
} |
| 108 |
} |