3 ms·
TL;DR: rounding up to a multiple of 2 requires an addition and an AND, but rounding down only requires the AND. So you save 1 instruction by allocating downward
by pubby 7y ago
TL;DR: rounding up to a multiple of 2 requires an addition and an AND, but rounding down only requires the AND. So you save 1 instruction by allocating downwards, and you save 2 if you insist on checking for overflow.
But honestly, does anyone care about skipping an addition instruction? I'd rather know about the caching behavior and the author's rationale for allowing alignment per-allocation rather than per-allocator.
- sfink 7y agoThat's not the summary I would have picked. The saved register seems a lot more significant. Shaving off some branches is pretty important too. tl;dr - bumping downwards saves a register, possibly some predictable branches, and an ADD.