I feel like there could be a decent intermediate option here. It quickly glosses over page sizes and then talks about the modulus operator, but misses the fact that bitwise operations can emulate modulus for powers of two, which is generally the sorts of sizes that pages tend to be, and bitwise is generally much faster than the division that modulus performs.
In short, x % z is generally equivalent to x & (z-1) when z is a power of two and is often much faster.
Now, I get that the compiler might be clever enough to turn a modulus operation of the right size into a bitwise operation, but it’s still necessary that the programmer specify that power-of-two size for their circular buffer in the first place.
I would be curious as to whether this “greyer” magic has any benefit when not performing the page table hack.
I feel like there could be a decent intermediate option here. It quickly glosses over page sizes and then talks about the modulus operator, but misses the fact that bitwise operations can emulate modulus for powers of two, which is generally the sorts of sizes that pages tend to be, and bitwise is generally much faster than the division that modulus performs.
In short,
x % z
is generally equivalent tox & (z-1)
when z is a power of two and is often much faster.Now, I get that the compiler might be clever enough to turn a modulus operation of the right size into a bitwise operation, but it’s still necessary that the programmer specify that power-of-two size for their circular buffer in the first place.
I would be curious as to whether this “greyer” magic has any benefit when not performing the page table hack.