Since the function Align::value() ALWAYS returns power of 2,
it is easier to check reminder by conjunction with mask, which is (Pow2Value - 1).
Details
Details
Diff Detail
Diff Detail
Event Timeline
Comment Actions
it is easier to check reminder by conjunction with mask, which is (Pow2Value - 1).
Hmm, easier in what respect? Isn't the original code more straight-forward?
Comment Actions
easier in what respect?
I mean, easier for CPU :-)
The division operation reasonably seems to be more complex than bitwise AND. And since this function is pretty hot it can save a bit of performance.
(Actually that's just my assumption. I did not make benchmark really.)
Side thought: I suspect some advanced CPUs can optimize such kind of divisions by powers of 2 by themselves.