Re: [PATCH v5 5/8] riscv/runtime-const: Introduce runtime_const_mask_32()
From: Charlie Jenkins
Date: Fri Jul 10 2026 - 03:53:33 EST
On Tue, 30 Jun 2026 04:55:28 +0000, K Prateek Nayak <kprateek.nayak@xxxxxxx> wrote:
> Futex hash computation requires a mask operation with read-only after
> init data that will be converted to a runtime constant in the subsequent
> commit.
>
> Introduce runtime_const_mask_32 to further optimize the mask operation
> in the futex hash computation hot path. Since all the current use-cases
> are of the form GENMASK(n, 0), with n > 0, following sequence:
I really appreciate you spending the time to do this, thank you!
>
>
> diff --git a/arch/riscv/include/asm/runtime-const.h b/arch/riscv/include/asm/runtime-const.h
> index 1ce02605d2e4..dbf96c937dbb 100644
> --- a/arch/riscv/include/asm/runtime-const.h
> +++ b/arch/riscv/include/asm/runtime-const.h
> @@ -262,6 +279,33 @@ static inline void __runtime_fixup_shift(void *where, unsigned long val)
> [ ... skip 24 lines ... ]
> + BUG_ON(!val || width > 31 || (GENMASK(width - 1, 0) != val));
> +
> + __runtime_fixup_shift(where, 32 - width);
> + __runtime_fixup_shift(where + 4, 32 - width);
> +}
> +
It would be "optimal" to use an andi when the mask is <=11 bits since
andi can fit an 11 bit mask. What you have is good enough but I'll leave
my stab at doing the andi patching here in case you want to apply it.