3 ms·
That's likely there to make modulo power-of-two operations faster by turning them into a single AND operation. Otherwise it doesn't make sense to me.
by 0-_-0 7y ago
That's likely there to make modulo power-of-two operations faster by turning them into a single AND operation. Otherwise it doesn't make sense to me.
- kragen 7y agoThat's not why, no. Why don't you implement signed integer division (with shifts, masks, and adds/subtracts) and see what you come out with?
- 0-_-0 7y agoAccording to wahern's quote above it was to "avoid incurring overhead in run-time code to check for special case", like the ability to accelerate mod power-of-two by convertig to AND.
- Dylan16807 7y agoYou get a positive number if you use AND.
- 0-_-0 7y agoYou don't mask the sign bit...
- Dylan16807 7y agoIn two's complement? You'd need to add extra masks and shifts to replicate the sign bit. It puts you in much more complex territory than throwing an AND at it.