Wednesday, August 27, 2008

Bit Haxorz

You can change code like:
if (accumulator >= test)
{
accumulator -= test;
x += stepx;
}
into
int subtract = accumulator - test;
int hibit = 1 - (subtract >> 31) & 1;
accumulator -= test * hibit;
x += stepx * hibit;
Magic! No conditionals! You might use something like this if you're working on a REAL inner-loop, such as code that'll run on a GPU or likewise run many times on a mobile or handheld CPU.

No comments: