From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout-p-103.mailbox.org (mout-p-103.mailbox.org [IPv6:2001:67c:2050:0:465::103]) by sourceware.org (Postfix) with ESMTPS id B002C3857711; Mon, 7 Aug 2023 11:19:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B002C3857711 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=aarsen.me Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=aarsen.me Received: from smtp1.mailbox.org (smtp1.mailbox.org [10.196.197.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-103.mailbox.org (Postfix) with ESMTPS id 4RKDNf0Thnz9snW; Mon, 7 Aug 2023 13:19:14 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aarsen.me; s=MBO0001; t=1691407154; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hfpm/gFTtsWlEeNQSWak70B0+gQNOGn4k6i/QEnGB3w=; b=bu/rz9slqETIO5Kuv8OeFjpULy16os8Y5aRkN6JnP3uEgJfOPVz2ABY5Y5rrJbw6ij4AAr VstgNYoetePdn4Zu+DJbU/srWFIuInyupWAuYCOxhL73Hi3lOTSfawjXzsSv//GzYkLLYX aNlEdQSD+QOCEEz9XMEM0//DvB50XBZA5xEXzXLu5dDdec3721yVjFgR1L04sxrKw7Cpjq xHwdv3EhAkVtK5eE0x0W5jwO8d96sOVP7DteZ/3MNV3mgo/I1L5nu+aRhXWE4/FFvJov6V J6/NiUa2XjFMuXhZXXAbPRmHseuAMZNGuwq62o8iptN8hb977BFrGgqiv8aHZw== From: =?UTF-8?q?Arsen=20Arsenovi=C4=87?= To: gdb-patches@sourceware.org, binutils@sourceware.org Cc: Xi Ruoyao Subject: [PATCH 05/45] LoongArch: implement count_{leading,trailing}_zeros Date: Mon, 7 Aug 2023 13:07:08 +0200 Message-ID: <20230807111029.2320238-6-arsen@aarsen.me> In-Reply-To: <20230807111029.2320238-1-arsen@aarsen.me> References: <20230807111029.2320238-1-arsen@aarsen.me> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_INFOUSMEBIZ,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,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: From: 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 9948a58769c..32d2048d353 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. */ \ -- 2.41.0