-
Notifications
You must be signed in to change notification settings - Fork 14.9k
Closed
Description
https://godbolt.org/z/e9qPT9z81
C++ code
#include <cstdint>
auto popcount_u8(std::uint8_t x) { return __builtin_popcountg(x); }
Assembly (LLVM)
popcount_u8(unsigned char):
and w8, w0, #0xff
fmov s0, w8
cnt v0.8b, v0.8b
addv b0, v0.8b
fmov w0, s0
ret
Assembly (GCC)
popcount_u8(unsigned char):
and w0, w0, 255
fmov d31, x0
cnt v31.8b, v31.8b
smov w0, v31.b[0]
ret
As you can see from GCC's assembly, the addv
is unecessary, because all the lanes except for the first will be zero.