LoongArch: implement count_{leading,trailing}_zeros
authorXi Ruoyao <xry111@xry111.site>
Mon, 7 Aug 2023 11:07:08 +0000 (13:07 +0200)
committerAlan Modra <amodra@gmail.com>
Sat, 12 Aug 2023 00:28:22 +0000 (09:58 +0930)
commit079b20e89d3c511716bafb3369336e2b1c165bd5
treea15f0626d489f986241b536983c3c3ce0a73cae8
parent82fc3423c36c2cdc413910dac2e3c9faf0c59967
LoongArch: implement count_{leading,trailing}_zeros

LoongArch always support clz and ctz instructions, so we can always use
__builtin_{clz,ctz} for count_{leading,trailing}_zeros.  This improves
the code of libgcc, and also benefits Glibc once we merge longlong.h
there.

Bootstrapped and regtested on loongarch64-linux-gnu.

include/
* longlong.h [__loongarch__] (count_leading_zeros): Define.
[__loongarch__] (count_trailing_zeros): Likewise.
[__loongarch__] (COUNT_LEADING_ZEROS_0): Likewise.
include/longlong.h