Tuesday, August 28, 2007

I'm back....packing reduced instruction optimization

Been a while since I posted, but I am knee deep in assembly at the moment, reviewing for game programming class. Binary divison was a recent topic for reducing instructions by using bit shifts. The interesting part is how to find the remainder on number other than factor of 2. NOTE: This works with divisors that are a factor of 2 (typical for mov(b/w/l) instructions).

These operations are used with strings alot.

Lets say we have a string with a length of 10 and we want to use movl (4 byte stride) to read the value in.

10/4 = 1010 >> 2 = 10 = 2

Now we know that 10/4 is 2.5, so to calculate the remainder simply do this.

4 - 1 = 11 10 & 11 = 10 = 2 2 of 4 bytes is .5

Bit shifting is much more efficient in terms of instructions for the cpu, which equates to better performance. This is useful when trying to optimize C++ game code to get acceptable performance.

No comments: