From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1E02CC433EF for ; Mon, 13 Dec 2021 19:45:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=T+S+uC/vHzetrWl+Av6pIPiL8Vc838tUKa4pe1XyDYc=; b=DZ3U8rNwHnK8q1 +CJLrkkPzAorPHeXkGnfEgIXAxMQHSWpS9lyDwy0EjY8zK/v7xFIjQO+EQjUzXXP02bV8b18xfADL lNl0WfzHqDKG4xFc/zsAp9OCv63k8cMsabuTkvM/tRJWIZQmfd99UHfzS5YcaMVGwdveMpyh4wJYY xMBzW6X8KQ52t0jd0zh0eyC66VlSB16WjA9C/fcBgyelrHdGyCWHEzrCNP3APy+ntkqMQfDKpUD97 pOCtWAVQVp1/CCVFycLseignUaVYv8ae/GRdf205grx4A8vGiiTJm/zxWP2owywnmJMWhNRXVak6W iehmfQ+p6mpaz/t1JyZw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mwrEz-00BBYI-D6; Mon, 13 Dec 2021 19:44:05 +0000 Received: from ams.source.kernel.org ([2604:1380:4601:e00::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mwrEv-00BBWq-Jg for linux-arm-kernel@lists.infradead.org; Mon, 13 Dec 2021 19:44:03 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 49552B815A1; Mon, 13 Dec 2021 19:44:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 09F4FC34602; Mon, 13 Dec 2021 19:43:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1639424639; bh=4c5PbBhUn4I6sEh3MgTZcETV3EpsRlr0CpfUKL1CUxk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=CVTuJS7KNVhx21Ud6zwmcz0pVv+ouMgtiI2XglAitVuyuwROFT3riut5kFMPVHnaW 9mNaOIF4RPfXOExrOXViiqj5Nji2F23hy4hidEwcwQPdEs5Bg+UcGeS2dJulQjJ150 yMc2hJyX+dOPdb0mSGMRENUfvsY/RMRJJj/ZMqJEd12adLvvb8O/805rDywuC06CBx 7cCyjKapv7CoDAHnVyVQO6hXDKPGOqYxYzIbDrIe7cCJ1mx1aVeLRJo4L1xb+IwMbE SB6q6d77IibOXVGZR1iJWmJ1DRb+oW5alnXFZ+msdyCDudE3//tKDvsTpe8qCWQnNw 3eWZtVWIfDifw== Date: Mon, 13 Dec 2021 19:43:54 +0000 From: Will Deacon To: Mark Rutland Cc: linux-arm-kernel@lists.infradead.org, boqun.feng@gmail.com, catalin.marinas@arm.com, peterz@infradead.org Subject: Re: [PATCH 5/5] arm64: atomics: lse: define RETURN ops in terms of FETCH ops Message-ID: <20211213194354.GE12868@willie-the-truck> References: <20211210151410.2782645-1-mark.rutland@arm.com> <20211210151410.2782645-6-mark.rutland@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20211210151410.2782645-6-mark.rutland@arm.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211213_114401_961517_79B28924 X-CRM114-Status: GOOD ( 22.95 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, Dec 10, 2021 at 03:14:10PM +0000, Mark Rutland wrote: > The FEAT_LSE atomic instructions include LD* instructions which return > the original value of a memory location can be used to directly > implement FETCH opertations. Each RETURN op is implemented as a copy of > the corresponding FETCH op with a trailing instruction instruction to > generate the new value of the memory location. We only > directly implement *_fetch_add*(), for which we have a trailing `add` > instruction. > > As the compiler has no visibility of the `add`, this leads to less than > optimal code generation when consuming the result. > > For example, the compiler cannot constant-fold the addition into later > operations, and currently GCC 11.1.0 will compile: > > return __lse_atomic_sub_return(1, v) == 0; > > As: > > mov w1, #0xffffffff > ldaddal w1, w2, [x0] > add w1, w1, w2 > cmp w1, #0x0 > cset w0, eq // eq = none > ret > > This patch improves this by replacing the `add` with C addition after > the inline assembly block, e.g. > > ret += i; > > This allows the compiler to manipulate `i`. This permits the compiler to > merge the `add` and `cmp` for the above, e.g. > > mov w1, #0xffffffff > ldaddal w1, w1, [x0] > cmp w1, #0x1 > cset w0, eq // eq = none > ret > > With this change the assembly for each RETURN op is identical to the > corresponding FETCH op (including barriers and clobbers) so I've removed > the inline assembly and rewritten each RETURN op in terms of the > corresponding FETCH op, e.g. > > | static inline void __lse_atomic_add_return(int i, atomic_t *v) > | { > | return __lse_atomic_fetch_add(i, v) + i > | } > > The new construction does not adversely affect the common case, and > before and after this patch GCC 11.1.0 can compile: > > __lse_atomic_add_return(i, v) > > As: > > ldaddal w0, w2, [x1] > add w0, w0, w2 > > ... while having the freedom to do better elsewhere. > > This is intended as an optimization and cleanup. > There should be no functional change as a result of this patch. > > Signed-off-by: Mark Rutland > Cc: Boqun Feng > Cc: Catalin Marinas > Cc: Peter Zijlstra > Cc: Will Deacon > --- > arch/arm64/include/asm/atomic_lse.h | 48 +++++++++-------------------- > 1 file changed, 14 insertions(+), 34 deletions(-) Acked-by: Will Deacon Will _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel