From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from xry111.site (xry111.site [89.208.246.23]) by sourceware.org (Postfix) with ESMTPS id A72323850208 for ; Thu, 13 Oct 2022 10:06:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A72323850208 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=xry111.site Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=xry111.site DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xry111.site; s=default; t=1665655583; bh=ngK4O15TXYnp+RhXZ390zFn3j8NdRYnU13SIIHcUYrU=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=j+sf/VXr4VrS+XrKzXbieh9CDYVr6by94kCwFJi9mL0Rqke15Kaf9krQzENm+TZUa KVEPtz3oxvqwCR2wfFUdYCDYUD+i5r8p/vYhyG5TczWKRXW6ZbpOYWexgmhkzMxuiU d+mDzq1Kch3fyyHvauQBtdwwEWDKcO9JN2bu6SY4= Received: from localhost.localdomain (xry111.site [IPv6:2001:470:683e::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) (Authenticated sender: xry111@xry111.site) by xry111.site (Postfix) with ESMTPSA id 74D54661C7; Thu, 13 Oct 2022 06:06:22 -0400 (EDT) Message-ID: <0d4b3da24c0e0cace0d0957f5b93ee63c68a31f6.camel@xry111.site> Subject: pushed: [PATCH] LoongArch: implement count_{leading,trailing}_zeros From: Xi Ruoyao To: Lulu Cheng , gcc-patches@gcc.gnu.org Cc: Wang Xuerui , Chenghua Xu Date: Thu, 13 Oct 2022 18:06:20 +0800 In-Reply-To: <53649638-7e6f-508f-b590-a66388c806b4@loongson.cn> References: <20221012142300.16833-1-xry111@xry111.site> <53649638-7e6f-508f-b590-a66388c806b4@loongson.cn> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.46.0 MIME-Version: 1.0 X-Spam-Status: No, score=-6.2 required=5.0 tests=BAYES_00,BODY_8BITS,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FROM_SUSPICIOUS_NTLD,GIT_PATCH_0,LIKELY_SPAM_FROM,SPF_HELO_PASS,SPF_PASS,TXREP,T_PDS_OTHER_BAD_TLD 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: On Thu, 2022-10-13 at 16:43 +0800, Lulu Cheng wrote: > Looks good to me! >=20 > Thanks! Pushed r13-3269. >=20 > =E5=9C=A8 2022/10/12 =E4=B8=8B=E5=8D=8810:23, Xi Ruoyao =E5=86=99=E9=81= =93: > > LoongArch always support clz and ctz instructions, so we can always > > use > > __builtin_{clz,ctz} for count_{leading,trailing}_zeros.=C2=A0 This > > improves > > the code of libgcc, and also benefits Glibc once we merge longlong.h > > there. > >=20 > > Bootstrapped and regtested on loongarch64-linux-gnu. > >=20 > > include/ChangeLog: > >=20 > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0* longlong.h [__loongar= ch__] (count_leading_zeros): Define. > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0[__loongarch__] (count_= trailing_zeros): Likewise. > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0[__loongarch__] (COUNT_= LEADING_ZEROS_0): Likewise. > > --- > > =C2=A0 include/longlong.h | 12 ++++++++++++ > > =C2=A0 1 file changed, 12 insertions(+) > >=20 > > 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); > > =C2=A0 #define UMUL_TIME 14 > > =C2=A0 #endif > > =C2=A0=20 > > +#ifdef __loongarch__ > > +# if W_TYPE_SIZE =3D=3D 32 > > +#=C2=A0 define count_leading_zeros(count, x)=C2=A0 ((count) =3D __buil= tin_clz > > (x)) > > +#=C2=A0 define count_trailing_zeros(count, x) ((count) =3D __builtin_c= tz > > (x)) > > +#=C2=A0 define COUNT_LEADING_ZEROS_0 32 > > +# elif W_TYPE_SIZE =3D=3D 64 > > +#=C2=A0 define count_leading_zeros(count, x)=C2=A0 ((count) =3D __buil= tin_clzll > > (x)) > > +#=C2=A0 define count_trailing_zeros(count, x) ((count) =3D __builtin_c= tzll > > (x)) > > +#=C2=A0 define COUNT_LEADING_ZEROS_0 64 > > +# endif > > +#endif > > + > > =C2=A0 #if defined (__M32R__) && W_TYPE_SIZE =3D=3D 32 > > =C2=A0 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \ > > =C2=A0=C2=A0=C2=A0 /* The cmp clears the condition bit.=C2=A0 */ \ >=20 --=20 Xi Ruoyao School of Aerospace Science and Technology, Xidian University