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 92268C46CD2 for ; Tue, 9 Jan 2024 11:41:05 +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:MIME-Version:References:In-Reply-To: Subject:Cc:To:From:Message-ID:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=HZb2EdrwlueAf8OET+KaLrBx5MxO6RihN3oyXvzToFo=; b=dpmFDSg+85ubIl bVAru7A8H7FZUdjIvUJan2pJzGsiW1pj9rMxD3LzmIv598NLJMDUf8ICZ8HFMqB7lqAuHAnZasilW a5RcKuBsNnzXfAba2N76n1nPdH5Xoptj2FmNG7wYnorGZjftYHhjhocwcnhwTkHKRXPgOWhV0LKG3 ihLwWUPtLCMSUUlfKLxcTHpck5QF+DjADbGPfo9oLJF0vlrp7ewlILPz2CaalHA7BLndhpb+jYSGI BoblIDMYvJPpBQKZWYuWo3pOpFZ2CvEKO3knUgSy1cEHDY366R1TDBBcr0foSS5+4OTaNzZkALwbq X6a0UOdQPqlW+YgHaePw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rNATF-007z6j-1A; Tue, 09 Jan 2024 11:40:37 +0000 Received: from ams.source.kernel.org ([145.40.68.75]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rNAT9-007z2R-0y for linux-arm-kernel@lists.infradead.org; Tue, 09 Jan 2024 11:40:35 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by ams.source.kernel.org (Postfix) with ESMTP id 1FB6AB81AD6; Tue, 9 Jan 2024 11:40:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6D11CC433F1; Tue, 9 Jan 2024 11:40:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704800428; bh=9v2sF+hZQgGLtSlalEb8xpEOtIYWC2+MtHxdv7xG+bU=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Ha680r0rM5BJ2jvajxvVgLRnPLH2VjdFQaKzk0el+sFtl/BYV0OKJff8NK5cAHp7j mjgrsZWltrB11RVmeMCcZw6Go34MVE/NJC3gd7l/MX/0oC1K1Oy44vepHgTHFWkYb/ S0rALmgs6QtiwbEFw9rVDCRW6pOtQKE9Q++ZqJQR5d/cmj2dkmtXbaiXn8tqTjOfVj HNh+/9laJU3brFmvHMYEIWOOr8FnUhOTfSmecoCFwQn/HEZPo3VhgrjIiQSNRl/Wdg rtYAxE5m4fLWbvEhn+WBpXX7Jnt3kuo4ApIQJKKqNntMH7ncifn+HsDk+p+0SO0Cxx bqMeYeHeX227w== Received: from sofa.misterjones.org ([185.219.108.64] helo=wait-a-minute.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1rNAT3-00AACE-IH; Tue, 09 Jan 2024 11:40:25 +0000 Date: Tue, 09 Jan 2024 11:40:19 +0000 Message-ID: <87plyau44c.wl-maz@kernel.org> From: Marc Zyngier To: Will Deacon Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, Catalin Marinas , Mark Rutland , Ard Biesheuvel , James Morse , Suzuki K Poulose , Oliver Upton , Zenghui Yu Subject: Re: [PATCH v3 02/13] arm64: cpufeatures: Correctly handle signed values In-Reply-To: <86a5pfafbv.wl-maz@kernel.org> References: <20231127114559.990314-1-maz@kernel.org> <20231127114559.990314-3-maz@kernel.org> <20231211122416.GA25277@willie-the-truck> <86a5pfafbv.wl-maz@kernel.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/28.2 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: will@kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, catalin.marinas@arm.com, mark.rutland@arm.com, ardb@kernel.org, james.morse@arm.com, suzuki.poulose@arm.com, oliver.upton@linux.dev, yuzenghui@huawei.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240109_034031_667787_406A7AA1 X-CRM114-Status: GOOD ( 19.75 ) 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 Mon, 08 Jan 2024 17:46:12 +0000, Marc Zyngier wrote: > > On Mon, 11 Dec 2023 12:24:16 +0000, > Will Deacon wrote: [...] > > > diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c > > > index 646591c67e7a..bc8787f28ffd 100644 > > > --- a/arch/arm64/kernel/cpufeature.c > > > +++ b/arch/arm64/kernel/cpufeature.c > > > @@ -140,12 +140,42 @@ void dump_cpu_features(void) > > > pr_emerg("0x%*pb\n", ARM64_NCAPS, &system_cpucaps); > > > } > > > > > > +#define __ARM64_MAX_POSITIVE(reg, field) \ > > > + ((reg##_##field##_SIGNED ? \ > > > + BIT(reg##_##field##_WIDTH - 1) : \ > > > + BIT(reg##_##field##_WIDTH)) - 1) > > > + > > > +#define __ARM64_MIN_NEGATIVE(reg, field) BIT(reg##_##field##_WIDTH - 1) > > > > I'm struggling to grok these two macros. For example, let's say I have a > > 4-bit signed field. In that case, the maximum positive value is 7 (0b0111) > > and the minimum negative value is -8 (0b1000), but the macros above appear > > to give 0b1000 for both. > > Crap. Well spotted. The signed maximum needs to be further adjusted > like this: Actually, scratch that. The original code is correct and does return 0b0111 for the max of a signed 4 bit value, and 0b1000 for the min. The clue is in the bracketing (the '- 1' is applied to the result of the conditional expression in the max case). M. -- Without deviation from the norm, progress is not possible. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel