From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by sourceware.org (Postfix) with ESMTP id 509C53858034 for ; Thu, 13 Oct 2022 08:43:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 509C53858034 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=loongson.cn Received: from [10.20.4.52] (unknown [10.20.4.52]) by localhost.localdomain (Coremail) with SMTP id AQAAf8DxvmvGz0djkeAsAA--.18375S2; Thu, 13 Oct 2022 16:43:51 +0800 (CST) Subject: Re: [PATCH] LoongArch: implement count_{leading,trailing}_zeros To: Xi Ruoyao , gcc-patches@gcc.gnu.org Cc: Wang Xuerui , Chenghua Xu References: <20221012142300.16833-1-xry111@xry111.site> From: Lulu Cheng Message-ID: <53649638-7e6f-508f-b590-a66388c806b4@loongson.cn> Date: Thu, 13 Oct 2022 16:43:51 +0800 User-Agent: Mozilla/5.0 (X11; Linux mips64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: <20221012142300.16833-1-xry111@xry111.site> Content-Type: text/plain; charset=gbk; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-CM-TRANSID:AQAAf8DxvmvGz0djkeAsAA--.18375S2 X-Coremail-Antispam: 1UD129KBjvJXoW7uFWfCF4kuFW7uw17uF45ZFb_yoW8XFWkpF yqyFW7Gr4rGFy7C3yfJa43tr1Svr1rCw13CFyjg397urWUJa4ag3yDKr4aqws8J393tF10 gry7W3W7ZF42krDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvI14x267AKxVWUJVW8JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26F1j6w1UM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4U JVWxJr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Gc CE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E 2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJV W8JwACjcxG0xvEwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lc7I2V7IY0VAS07AlzVAY IcxG8wCY02Avz4vE-syl42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2 IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v2 6r126r1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2 IY6xkF7I0E14v26r1j6r4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv 67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r1j6r4UYxBIdaVFxhVjvjDU0xZFpf 9x0JUywZ7UUUUU= X-CM-SenderInfo: xfkh0wpoxo3qxorr0wxvrqhubq/ X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00,GIT_PATCH_0,KAM_DMARC_STATUS,MIME_CHARSET_FARAWAY,NICE_REPLY_A,SPF_HELO_PASS,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Looks good to me! Thanks! ÔÚ 2022/10/12 ÏÂÎç10:23, Xi Ruoyao дµÀ: > 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. > --- > 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. */ \