Quote:
Originally Posted by KLS
That extra credit is going to give someone a brain aneurysm.
|
Heh, it's one of the neater tricks used to avoid division by constants. It also proves the guys that write the optimizers are way smarter than me.
http://homepage.cs.uiowa.edu/~jones/bcd/divide.html
I remember back in the old days before optimizers were scary good my boss would compile code to asm and then go through and hand optimize some simple things like xor ax,ax instead of mov ax,0 because it saved 1 cycle. Probably pointless, but it seemed to make him happy. He'd also freak if you used division instead of converting to a right shift or two where possible.
Nowadays that kind of stuff is boring compared to the lengths people will go to in order to avoid a branch on a console.
More reading if your brain doesn't already hurt:
http://graphics.stanford.edu/~seander/bithacks.html