> On 14 Dec 2023, at 08:12, Amul Sul <sula...@gmail.com> wrote:
> 
> 
> + int bankno = pageno & ctl->bank_mask;
> 
> I am a bit uncomfortable seeing it as a mask, why can't it be simply a number
> of banks (num_banks) and get the bank number through modulus op (pageno %
> num_banks) instead of bitwise & operation (pageno & ctl->bank_mask) which is a
> bit difficult to read compared to modulus op which is quite simple,
> straightforward and much common practice in hashing.
> 
> Are there any advantages of using &  over % ?

The instruction AND is ~20 times faster than IDIV [0]. This is relatively hot 
function, worth sacrificing some readability to save ~ten nanoseconds on each 
check of a status of a transaction.


[0] https://www.agner.org/optimize/instruction_tables.pdf



Reply via email to