Received: by 2002:a05:7412:9c07:b0:fa:6e18:a558 with SMTP id lr7csp564830rdb; Sat, 27 Jan 2024 21:39:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IHXa+eYFhQ0lvHTCs1T8CpIZ0Cqg/YDDNKnlo7Mxuj09CV5TFTUPrXSCNDxaZv5eyTkxmFJ X-Received: by 2002:a05:6808:228e:b0:3be:2b4f:cd1b with SMTP id bo14-20020a056808228e00b003be2b4fcd1bmr2873779oib.17.1706420374170; Sat, 27 Jan 2024 21:39:34 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706420374; cv=pass; d=google.com; s=arc-20160816; b=jDOyLwi7BwSU4INh6pMyyzKObHZ61W3cjtX+KoCWmJ1L4efGS9kz3HyUXH/dGNJCuA UefRTdoychy9iLkTiNQCerlVAwer4cSk1js9xomGRpjldY6UiW8dMueP51YZg7Fx4FV2 Dw5i+VDmnBxY89/1S+pYGnehHafdOVm6Rv28ujKT2T0I2pnhBm7qfw3QKt7VH/DiSwJE YMkYl2F4cRulHXABgMIx29gSQ+eBZhBYofm7xLUiZKshkIJu0r9gYxYmiePKOAp0hBF2 vA2FNIZIHIw8q5oH+OvT83f5+JtBAWy8O5N0GD6BHgdkgsHNOQPhW37LKyZxagJ2NOOy LTow== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:in-reply-to:subject:cc:to:from:date :feedback-id:dkim-signature; bh=/tykfuzP/yR2RGWwFOx8HgWGqcUIyxkAtWGbaAySd0o=; fh=Jjxe1vGgQXObW9eoMeKv9GnKJD28uQFIIFyBhsigxI0=; b=asAStXfHJiapXsH1l0qh6TByAhq1jVDR2/TvsOmVzS4eMKmsP5p9Pdi0GYvk+P8DeR XLF4CazKUne3EDg0irl06WkzmVk7/SI3ypasvJRHnmTbqsNc7NJ+mmkvnudBuxuYc45e 1TyyeZhjjjhH4dLUdP5SGBQcRZbJfV2BS7mzfMVpvUu8W7Limw/hNqITdBoZshZgj7wV TiwRCkTRbz6wqA/UOt0FPKhszS3EcdzOppCKO8t7MoS123hFBSq2com/X9JQt8K6hZ5f 8x3fA1jp0Vieh8AYI1rojUJ8DdB0Dl1o6PS6J4cemOOjRomz5xhQpzCfzw97DDHURVEJ awHQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=QGIBCckh; arc=pass (i=1 dkim=pass dkdomain=messagingengine.com); spf=pass (google.com: domain of linux-kernel+bounces-41544-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-41544-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id z20-20020a170903409400b001d8923d8a60si3603595plc.507.2024.01.27.21.39.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 Jan 2024 21:39:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-41544-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=QGIBCckh; arc=pass (i=1 dkim=pass dkdomain=messagingengine.com); spf=pass (google.com: domain of linux-kernel+bounces-41544-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-41544-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id C4018283FC0 for ; Sun, 28 Jan 2024 05:39:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 98323D52A; Sun, 28 Jan 2024 05:39:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="QGIBCckh" Received: from wout3-smtp.messagingengine.com (wout3-smtp.messagingengine.com [64.147.123.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9DAECD51C for ; Sun, 28 Jan 2024 05:39:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.19 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706420366; cv=none; b=hqKo/daZfWaK4LTLnW4Jo9uAnuLj8otpz+D4a+jGVnCcIJp5kje24+AIFIkDlIjcsQ7UOAR5cgVhF5dm65YTpsl5XKE3/2vnx3Hk3vEshGWA1QS6wwUODFk5vg9hNCJjO1q2U1l5DXc0KkLKEqagyXhM/k2XpPt4v65LsC1P2oM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706420366; c=relaxed/simple; bh=ACKTKOuJWUOirQ98WBHpdV1H/YZfxrXRPTERjk4FaYg=; h=Date:From:To:cc:Subject:In-Reply-To:Message-ID:References: MIME-Version:Content-Type; b=FZ7JaJBucxvepqSgltHgLHW/xKc8FB+wcSeA4lyeKxfcPYFjhUET/ztOzD9R9OQNyfhbkYPVKXzcw6req9yqH6SAxu41xV6ug2k6SiCzUF/Yuo6Skeg09mk/wlqnVQPyJJQYzU/9YKl3C03aNrWiQrQoZBz6j04j55pPcL6WAEo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=linux-m68k.org; spf=none smtp.mailfrom=linux-m68k.org; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=QGIBCckh; arc=none smtp.client-ip=64.147.123.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=linux-m68k.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux-m68k.org Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailout.west.internal (Postfix) with ESMTP id 0443F32004CE; Sun, 28 Jan 2024 00:39:19 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Sun, 28 Jan 2024 00:39:21 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1706420359; x=1706506759; bh=/tykfuzP/yR2RGWwFOx8HgWGqcUI yxkAtWGbaAySd0o=; b=QGIBCckh5pOYqdjAwRDpZ5oAxbCS1/KBe2w3cEpypgWA CDMJDnnDumnw9Mpknp92wKit1tdkTEnN7cXRdtTYHDM3ssaigpx90XRr9hRub+FJ QL4yDoP2uM2xtF0MNfGPQO1QuljgMUSEHFM3O4KIccPPg07SirFI9DpdKzlvgDRJ cX1onb86SbT9miZaZKSYNrCS2flEEwxVXb9x63zuA8agwsoUhFVSPXxJ2S2JrvYi bx68MHms7RG//VDiNryn5MhaYhpaOs/eEokgUK/PHBDgPx+fabQzDzn2cPzbNMZL wy121y6ijwYVVzAgsnE/WOcIKRC21Q+iSx0KUiB9gg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrfedttddgkedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevufgjkfhfgggtsehttdertddttddvnecuhfhrohhmpefhihhnnhcu vfhhrghinhcuoehfthhhrghinheslhhinhhugidqmheikehkrdhorhhgqeenucggtffrrg htthgvrhhnpeefieehjedvtefgiedtudethfekieelhfevhefgvddtkeekvdekhefftdek vedvueenucffohhmrghinhepkhgvrhhnvghlrdhorhhgnecuvehluhhsthgvrhfuihiivg eptdenucfrrghrrghmpehmrghilhhfrhhomhepfhhthhgrihhnsehlihhnuhigqdhmieek khdrohhrgh X-ME-Proxy: Feedback-ID: i58a146ae:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 28 Jan 2024 00:39:16 -0500 (EST) Date: Sun, 28 Jan 2024 16:39:18 +1100 (AEDT) From: Finn Thain To: Vincent Mailhol cc: Andrew Morton , linux-kernel@vger.kernel.org, Yury Norov , Nick Desaulniers , Douglas Anderson , Kees Cook , Petr Mladek , Randy Dunlap , Zhaoyang Huang , Geert Uytterhoeven , Marco Elver , Brian Cain , Geert Uytterhoeven , Matthew Wilcox , "Paul E . McKenney" , linux-m68k@lists.linux-m68k.org Subject: Re: [PATCH v4 2/5] m68k/bitops: use __builtin_{clz,ctzl,ffs} to evaluate constant expressions In-Reply-To: <20240128050449.1332798-3-mailhol.vincent@wanadoo.fr> Message-ID: References: <20221111081316.30373-1-mailhol.vincent@wanadoo.fr> <20240128050449.1332798-1-mailhol.vincent@wanadoo.fr> <20240128050449.1332798-3-mailhol.vincent@wanadoo.fr> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII On Sun, 28 Jan 2024, Vincent Mailhol wrote: > The compiler is not able to do constant folding on "asm volatile" code. > > Evaluate whether or not the function argument is a constant expression > and if this is the case, return an equivalent builtin expression. > > On linux 6.7 with an allyesconfig and GCC 13.2.1, it saves roughly 11 KB. > > $ size --format=GNU vmlinux.before vmlinux.after > text data bss total filename > 60457964 70953697 2288644 133700305 vmlinux.before > 60441196 70957057 2290724 133688977 vmlinux.after > > Reference: commit fdb6649ab7c1 ("x86/asm/bitops: Use __builtin_ctzl() to evaluate constant expressions") > Link: https://git.kernel.org/torvalds/c/fdb6649ab7c1 > > Reviewed-by: Geert Uytterhoeven > Signed-off-by: Vincent Mailhol > --- > arch/m68k/include/asm/bitops.h | 12 ++++++++++++ > 1 file changed, 12 insertions(+) > > diff --git a/arch/m68k/include/asm/bitops.h b/arch/m68k/include/asm/bitops.h > index a8b23f897f24..02ec8a193b96 100644 > --- a/arch/m68k/include/asm/bitops.h > +++ b/arch/m68k/include/asm/bitops.h > @@ -469,6 +469,9 @@ static __always_inline unsigned long ffz(unsigned long word) > { > int res; > > + if (__builtin_constant_p(word)) > + return __builtin_ctzl(~word); > + > __asm__ __volatile__ ("bfffo %1{#0,#0},%0" > : "=d" (res) : "d" (~word & -~word)); > return res ^ 31; If the builtin has the desired behaviour, why do we reimplement it in asm? Shouldn't we abandon one or the other to avoid having to prove (and maintain) their equivalence? > @@ -490,6 +493,9 @@ static __always_inline unsigned long ffz(unsigned long word) > !defined(CONFIG_M68000) > static __always_inline unsigned long __ffs(unsigned long x) > { > + if (__builtin_constant_p(x)) > + return __builtin_ctzl(x); > + > __asm__ __volatile__ ("bitrev %0; ff1 %0" > : "=d" (x) > : "0" (x)); > @@ -522,6 +528,9 @@ static __always_inline int ffs(int x) > { > int cnt; > > + if (__builtin_constant_p(x)) > + return __builtin_ffs(x); > + > __asm__ ("bfffo %1{#0:#0},%0" > : "=d" (cnt) > : "dm" (x & -x)); > @@ -540,6 +549,9 @@ static __always_inline int fls(unsigned int x) > { > int cnt; > > + if (__builtin_constant_p(x)) > + return x ? BITS_PER_TYPE(x) - __builtin_clz(x) : 0; > + > __asm__ ("bfffo %1{#0,#0},%0" > : "=d" (cnt) > : "dm" (x)); >