[PATCH v3 02/13] arm64: cpufeatures: Correctly handle signed values
Marc Zyngier
maz at kernel.org
Tue Jan 9 03:40:19 PST 2024
On Mon, 08 Jan 2024 17:46:12 +0000,
Marc Zyngier <maz at kernel.org> wrote:
>
> On Mon, 11 Dec 2023 12:24:16 +0000,
> Will Deacon <will at kernel.org> 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.
More information about the linux-arm-kernel
mailing list