public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-3269] LoongArch: implement count_{leading,trailing}_zeros
@ 2022-10-13 10:05 Xi Ruoyao
0 siblings, 0 replies; only message in thread
From: Xi Ruoyao @ 2022-10-13 10:05 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:6f653a2c85a450714bac905ea4f153234bc6cd5f
commit r13-3269-g6f653a2c85a450714bac905ea4f153234bc6cd5f
Author: Xi Ruoyao <xry111@xry111.site>
Date: Wed Oct 12 22:06:07 2022 +0800
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/ChangeLog:
* longlong.h [__loongarch__] (count_leading_zeros): Define.
[__loongarch__] (count_trailing_zeros): Likewise.
[__loongarch__] (COUNT_LEADING_ZEROS_0): Likewise.
Diff:
---
include/longlong.h | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/include/longlong.h b/include/longlong.h
index 64a7b10f9b2..c3a6f1e7eaa 100644
--- a/include/longlong.h
+++ b/include/longlong.h
@@ -593,6 +593,18 @@ extern UDItype __umulsidi3 (USItype, USItype);
#define UMUL_TIME 14
#endif
+#ifdef __loongarch__
+# if W_TYPE_SIZE == 32
+# define count_leading_zeros(count, x) ((count) = __builtin_clz (x))
+# define count_trailing_zeros(count, x) ((count) = __builtin_ctz (x))
+# define COUNT_LEADING_ZEROS_0 32
+# elif W_TYPE_SIZE == 64
+# define count_leading_zeros(count, x) ((count) = __builtin_clzll (x))
+# define count_trailing_zeros(count, x) ((count) = __builtin_ctzll (x))
+# define COUNT_LEADING_ZEROS_0 64
+# endif
+#endif
+
#if defined (__M32R__) && W_TYPE_SIZE == 32
#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
/* The cmp clears the condition bit. */ \
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-10-13 10:05 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-13 10:05 [gcc r13-3269] LoongArch: implement count_{leading,trailing}_zeros Xi Ruoyao
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).