From patchwork Mon Aug 7 11:07:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Arsen_Arsenovi=C4=87?= X-Patchwork-Id: 131803 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp1376075vqr; Mon, 7 Aug 2023 04:21:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFyzO7eOCXBmRYxQuDhVY5CHbZMVRmwWfHYpJKuxJDoB1SUuJOjkZnXcqenfLl3vRoy7tA0 X-Received: by 2002:a05:6402:1519:b0:51e:5322:a642 with SMTP id f25-20020a056402151900b0051e5322a642mr7307398edw.27.1691407296752; Mon, 07 Aug 2023 04:21:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691407296; cv=none; d=google.com; s=arc-20160816; b=bAKkraLlVcw4MLh6Pt8OQkPvLopaiiXSDTJ+/fXzIfeUHQ9tBqRsXOtjugCb10Nss0 5iZMX2e6WaS7cNSVqD1P6uNsi2OYBcS8Kd/lk1AJVcrZO0KB5GClwxLYkjb9hEPNlqGS 7ASWKQ7nyAEJLTIp3gnA6RofaMyG5PYjFOV1zabPM6eYAxZTd2BCWJmClojUoWEG9EyS 3MCUw7keO1Ky/PoTbEjPqdbtGyNBqkQWFn/CoaVP0k9vASgNc1IQfQENlPMWujg4d0We n2THL9SrolQOayiXnwnzSghxr/YDveqXZ5iCEgiC0tQDfd5hvO0ZyiFrjWWouDWV0iV8 STCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=hfpm/gFTtsWlEeNQSWak70B0+gQNOGn4k6i/QEnGB3w=; fh=13o7gu6xg1kvASsHMytaYMFsPiuSxejPaQ7nOT5E9q0=; b=hDzmQ2sj1NU2XbThJRC/FWWyKIAqNNRrimyHgyWRFsMoZ0AOvpkMKEgZIPZk/GbwwR b8V5MWGAgMoVm/wCgp3qSr/d1FxUtlcK0Y4u2qlYUncRKBKJAKGEUqIWNHtxLijDzByz E9E/hD0sVoLyoWESSRxUlDqclqbXj4pOALy5wbXdx3sATkSDyhnKhdk6BURj0x9doihX soiKDXdDMrd5a0jve33xrS/ZkC8YW3ig27bIOmzaW694ErPGc7zpUNf0jWsJ95W5OVIH vz56PiTSAbuM8DEIfKCmtOsfBRybaKElTqwjObuKTUGu2Y5aIJrl8i256vq0Kc6kWDue lEHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=h2QeOcbS; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id b24-20020aa7d498000000b00522298f70ffsi2139148edr.182.2023.08.07.04.21.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 04:21:36 -0700 (PDT) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=h2QeOcbS; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 950E2385C6E3 for ; Mon, 7 Aug 2023 11:20:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 950E2385C6E3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1691407226; bh=hfpm/gFTtsWlEeNQSWak70B0+gQNOGn4k6i/QEnGB3w=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=h2QeOcbS5oxJEGdnKwxmZNnmic+OUsPQOwr5S+oTP7uhhek5OJlZDEzk/f51+tH5h 8KnjGXTwGkHr/cprpuROXs0a4nj9tkay7bKBD930kDt8+jncobYdCvF2orhSllrVOW VQVL7G2x7hQOEmMggYzeTtbPoyKdYau5C5/DMHDg= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org 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 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) 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 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 X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: =?utf-8?q?Arsen_Arsenovi=C4=87_via_Binutils?= From: =?utf-8?q?Arsen_Arsenovi=C4=87?= Reply-To: =?utf-8?q?Arsen_Arsenovi=C4=87?= Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773569097796746239 X-GMAIL-MSGID: 1773569097796746239 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. */ \