From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7856) id C1C423850208; Thu, 13 Oct 2022 10:05:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C1C423850208 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1665655543; bh=tPgsCewxGv9eAOqgRVNa1TGv+GAL+2FuImlFpB5/39A=; h=From:To:Subject:Date:From; b=Y/bYexUMC1cJvokSmPYdUfFdcHcdkLgkgeOv+oB92AznYMcAH+/5s2ng1ipgpm0nd FZqybmTrgcscUXBetPeflQU39wMMs+UnQldrqXd+ICvgc7cePC411Integg884nPDy w/5kKTxOdbUausDj0dVVWU0/kvJKBxQN62hMvpPc= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Xi Ruoyao To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-3269] LoongArch: implement count_{leading,trailing}_zeros X-Act-Checkin: gcc X-Git-Author: Xi Ruoyao X-Git-Refname: refs/heads/master X-Git-Oldrev: 7f9a7465c863e482708d2a00f5f7ff91ae3a7e0b X-Git-Newrev: 6f653a2c85a450714bac905ea4f153234bc6cd5f Message-Id: <20221013100543.C1C423850208@sourceware.org> Date: Thu, 13 Oct 2022 10:05:43 +0000 (GMT) List-Id: https://gcc.gnu.org/g:6f653a2c85a450714bac905ea4f153234bc6cd5f commit r13-3269-g6f653a2c85a450714bac905ea4f153234bc6cd5f Author: Xi Ruoyao 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. */ \