Re: [PATCH v4 3/8] arm64/runtime-const: Introduce runtime_const_mask_32()
From: Charlie Jenkins
Date: Tue Jun 23 2026 - 01:27:24 EST
On Thu, 30 Apr 2026 09:47:25 +0000, K Prateek Nayak <kprateek.nayak@xxxxxxx> wrote:
> [...]
> is intentiaonally placed outside of asm block to allow compilers to
> further optimize it if possible.
>
> __runtime_fixup_ptr() already patches a "movz, + movk lsl #16" sequence
> which has been reused to patch the same sequence for
> __runtime_fixup_mask().
I think we should opt to do power of 2 masks instead of arbitrary masks
since that is what the usecase is and we can reduce these three
instructions into a single instruction for arm (and benefit riscv as
well). It is convenient to have this function as arbitrary masks, but
since we are going down the route of hyper optimizations already with
runtime constants here (and we can always add an arbitrary mask later if
there becomes a usecase), I feel like we should go all the way :)
The and immediate instruction for arm supports all power of 2 masks so
you can do:
and w0, w0, #0xMASK
- Charlie
--
Charlie Jenkins <thecharlesjenkins@xxxxxxxxx>