vaddv_u8
and some other similar new v-intrinsics from AArch64 (arm64) return uint8_t
. How can I treat result of this intrinsic as a neon register instead of plain C type?
void paddClz(uint8_t* x)
{
uint8x8_t ret = vdup_n_u8(0);
for (int i = 0; i < 8; ++i, x += 8)
{
uint8x8_t x8 = vld1_u8(x);
uint8_t sum = vaddv_u8(x8);
uint8x8_t r = vdup_n_u8(sum); //or: r = vset_lane_u8(sum, r, 0);
r = vclz_u8(r);
ret = vext_u8(ret, r, 1);
}
vst1_u8(x, ret);
}
what clang generated:
paddClz(unsigned char*): // @paddClz(unsigned char*)
mov x8, xzr
movi d0, #0000000000000000
.LBB0_1: // =>This Inner Loop Header: Depth=1
ldr d1, [x0, x8]
add x8, x8, #8 // =8
cmp w8, #64 // =64
addv b1, v1.8b
dup v1.8b, v1.b[0] <<== useless! I only need/use/care about v1.b[0]
clz v1.8b, v1.8b
ext v0.8b, v0.8b, v1.8b, #1
b.ne .LBB0_1
str d0, [x0, #64]
ret
As you can see there is a useless dup
intrinsic required to get the uint8_t vaddv_u8
result converted to a type that will work as an argument for vclz_u8
. I take only first lane from the subsequent vclz_u8
result, so actually duplicating it to all lanes would be wasted work.
How can I write it in intrinsics to get that sum
in neon typed variable without making the compiler emit useless opcodes? (And preferably without this extra noise in the source code.) To make it clear and obvious if it wasn't: I'm not asking to optimize or improve that piece of code that I posted; I simply wrote it to show the issue.
clang -target aarch64
on godbolt.org next time I'm looking at ARM intrinsics. (I only mess around with ARM code for SO answers.)