Re: [PATCH] dma-direct: Optimize get_required_mask

From: Luben Tuikov
Date: Wed Dec 14 2022 - 23:31:11 EST


On 2022-12-14 15:57, Robin Murphy wrote:
> On 2022-12-14 18:00, Luben Tuikov wrote:
>> Optimize dma_direct_get_required_mask(), in that we don't need to multiply by
>> two if we don't subtract 1 from the exponent. That is,
>>
>> (1 << (n - 1)) * 2 - 1 <==>
>> 2^(n-1) * 2^1 - 1 = (by rule of exponents)
>> 2^n - 1 <==>
>> (1 << n) - 1.
>
> ...except when n==64 (for the actual code below), in which case the
> result of the shift becomes undefined.

Oh, right, for bit 63 being set. Forgot about that one. Good call.

Thanks,
Luben