[PATCH v2 1/1] PCI: brcmstb: Use BIT() as __GENMASK() is for internal use only

Andy Shevchenko andriy.shevchenko at linux.intel.com
Wed Nov 17 04:42:25 PST 2021


On Tue, Nov 16, 2021 at 12:38:39PM -0800, Florian Fainelli wrote:
> On 11/15/21 3:20 AM, Andy Shevchenko wrote:
> > Use BIT() as __GENMASK() is for internal use only. The rationale
> > of switching to BIT() is to provide better generated code. The
> > GENMASK() against non-constant numbers may produce an ugly assembler
> > code. On contrary the BIT() is simply converted to corresponding shift
> > operation.
> 
> The code is not necessarily any different on ARMv8 as far as I can tell,
> before:
> 
> static void brcm_msi_set_regs(struct brcm_msi *msi)
> {
>         u32 val = __GENMASK(31, msi->legacy_shift);
>       84:       b9406402        ldr     w2, [x0,#100]
>       88:       d2800021        mov     x1, #0x1
> // #1
>       8c:       9ac22021        lsl     x1, x1, x2
>       90:       4b0103e1        neg     w1, w1
> 
> 
> after:
> 
> static void brcm_msi_set_regs(struct brcm_msi *msi)
> {
>         u32 val = ~(BIT(msi->legacy_shift) - 1);
>       84:       b9406402        ldr     w2, [x0,#100]
>       88:       d2800021        mov     x1, #0x1
> // #1
>       8c:       9ac22021        lsl     x1, x1, x2
>       90:       4b0103e1        neg     w1, w1
> 
> and the usage of BIT() does not make this any clearer.

While I disagree on the conclusion it's good that assembly isn't bad.
Last time I have tried to compile just GENMASK() excerpts for arm32
the non-constant variants were quite bad. And it was obvious win for
BIT() over GENMASK().

Actually it maybe that I have tested something like

  `GENMASK(C1 + var, C2 + var)` vs. `GENMASK(C1, C2) << var`

that time.

-- 
With Best Regards,
Andy Shevchenko





More information about the linux-arm-kernel mailing list