https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97759
--- Comment #13 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
For aarch64, we get:
is_power2_popcnt(int):
fmov s0, w0
cnt v0.8b, v0.8b
addv b0, v0.8b
fmov w0, s0
cmp w0, 1
cset w0, eq
ret
is_power2_arithmetic(int):
sub w1, w0, #1
tst w1, w0
ccmp w0, 0, 4, eq
cset w0, ne
ret
Obviously is_power2_arithmetic is better.
Note clang uses popcntl for both (on both x86 and arm64) if popcntl can be done
inline and uses test/set/and if popcntl does not exist.