From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from angie.orcam.me.uk (angie.orcam.me.uk [IPv6:2001:4190:8020::34]) by sourceware.org (Postfix) with ESMTP id 397303858D3C for ; Sun, 12 May 2024 17:06:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 397303858D3C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=orcam.me.uk Authentication-Results: sourceware.org; spf=none smtp.mailfrom=orcam.me.uk ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 397303858D3C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:4190:8020::34 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715533619; cv=none; b=aeYTGsdbXlmanB6kn8/pLwssMYn0P6HFqbeNmF8I6i3b7fR+UTg2eNqh40/fwh90oBDnF1bBfGadthi3a0PuQDRos4w4g22lbkuOUydSi0iWRHDsKCYnFihr//v7uWWMi2J6hDbUwR2HqNMzxZQOzKRamMPtyaXdQtNVASvgMto= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715533619; c=relaxed/simple; bh=wBjC5WWCWoLym07C+bjpY3v6G+AhXgM92YhjXg1nA54=; h=Date:From:To:Subject:Message-ID:MIME-Version; b=c7mHPCEgpfNfs8i9J8E27j9eBbNy8ZxQhyXSJIupQd3AM0BBCF8h/hTudsfgCUNuXoGLnZxWC1ZLoPNcpDXModqutXU0tGJt4CYvFgXSy+KcI5AVCwYvpsa47PZ9nWFNt0LOv4NAjxZBMvddw+l0w+RkHKqOrQHmDHt8W5Yl6ks= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by angie.orcam.me.uk (Postfix, from userid 500) id 12CEC92009C; Sun, 12 May 2024 19:06:56 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by angie.orcam.me.uk (Postfix) with ESMTP id 043AC92009B; Sun, 12 May 2024 18:06:55 +0100 (BST) Date: Sun, 12 May 2024 18:06:55 +0100 (BST) From: "Maciej W. Rozycki" To: Adhemerval Zanella Netto cc: Junxian Zhu , libc-alpha@sourceware.org Subject: Re: [PATCH] mips: Use builtins for ffs and ffsll In-Reply-To: <850a7fa0-e9c0-4c92-bde8-9f4f6773381f@linaro.org> Message-ID: References: <20240204101132.653-2-zhujunxian@oss.cipunited.com> <850a7fa0-e9c0-4c92-bde8-9f4f6773381f@linaro.org> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-3494.5 required=5.0 tests=BAYES_00,GIT_PATCH_0,KAM_DMARC_STATUS,KAM_INFOUSMEBIZ,KAM_LAZY_DOMAIN_SECURITY,SPF_HELO_NONE,SPF_NONE,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: On Mon, 5 Feb 2024, Adhemerval Zanella Netto wrote: > >> __builtin_ffs{,ll} basically on __builtin_ctz{,ll} in MIPS GCC compiler. > >> The hardware ctz instructions were available after MIPS{32,64} Release1. By > using builtin ctz. It can also reduce code size of ffs/ffsll. > >> > >> Checked on mips o32. mips64. > >> > >> Signed-off-by: Junxian Zhu > > > > LGTM, thanks. > > > > Reviewed-by: Adhemerval Zanella > > > >> --- > >> sysdeps/mips/math-use-builtins-ffs.h | 2 ++ > >> 1 file changed, 2 insertions(+) > >> create mode 100644 sysdeps/mips/math-use-builtins-ffs.h > >> > >> diff --git a/sysdeps/mips/math-use-builtins-ffs.h > b/sysdeps/mips/math-use-builtins-ffs.h > >> new file mode 100644 > >> index 0000000000..78b3f14fae > >> --- /dev/null > >> +++ b/sysdeps/mips/math-use-builtins-ffs.h > >> @@ -0,0 +1,2 @@ > >> +#define USE_FFS_BUILTIN (__mips_isa_rev >= 1) > >> +#define USE_FFSLL_BUILTIN (__mips_isa_rev >= 1) > > In fact you need to include since gcc only defines __mips_isa_rev > for -mips32 or higher. Also this causes code pessimisation for MIPS32 and `ffsll', as there is no hw instruction for this operation in the 32-bit ABI and consequently `__builtin_ffsll' resorts to a libcall. So IMO USE_FFSLL_BUILTIN ought to only be set for 64-bit ABIs, making `ffsll' defer to `ffs' (and then use 32-bit CLZ as appropriate). NB contrary to the change description there is no CTZ instruction in the MIPS ISA at any level. There are: CLO, CLZ, and for 64-bit: DCLO, DCLZ, and `__builtin_ctz', etc. can be synthesized with the usual calculation. Maciej