Fractions for division?

Started by
5 comments, last by Nice Coder 19 years ago
Ok. Optimisation for software division using fractions and lut's is the name of the game. Basically, i've got two 32 bit numbers, and i would like to use fractions to find out the results of the division. I've thought of

a * 2^0 + b * 2^1 + c * 2^2
---------------------------
d * 2^0 + e * 2^1 + f * 2^2
As a 3 bit egsample. Now, my problem, is how would i use this to work out the division? From, Nice coder
Click here to patch the mozilla IDN exploit, or click Here then type in Network.enableidn and set its value to false. Restart the browser for the patches to work.
Advertisement
Easy. For your 3-bit example, you just create a lookup table with 26 3-bit entries. The index would be (in binary) abcdef.

For 32-bit division, it is just as easy. You just create a lookup table with 264 32-bit entries (only 64 exabytes of memory needed).
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
Ok. I'm willing to have a 32^2 element lut.

Maybe a bit more.

But not over a few mb.

And an eb. NO way....

From,
Nice coder
Click here to patch the mozilla IDN exploit, or click Here then type in Network.enableidn and set its value to false. Restart the browser for the patches to work.
If x and y are bytes,

x/y is more or less equal to (x * ((1<<24)/y)>>24

and you can store (1<<24)/y in a lookup table with 256 entries.
Seems to me a cheap way to perform division on processors with multiplication but not division support is to first generate a good first guess interval (upper bound and lower bound) and then binary search the interval.

Worst case for 32-bit division would be 32 passes in the binary search but a good first guess interval table should get that down to 8 or fewer.
Quote:Original post by ToohrVyk
If x and y are bytes,

x/y is more or less equal to (x * ((1<<24)/y)>>24

and you can store (1<<24)/y in a lookup table with 256 entries.


x & y are 32 bit numbers.

This makes it a little impractical.

From,
Nice coder
Click here to patch the mozilla IDN exploit, or click Here then type in Network.enableidn and set its value to false. Restart the browser for the patches to work.
Quote:Original post by Anonymous Poster
Seems to me a cheap way to perform division on processors with multiplication but not division support is to first generate a good first guess interval (upper bound and lower bound) and then binary search the interval.

Worst case for 32-bit division would be 32 passes in the binary search but a good first guess interval table should get that down to 8 or fewer.


Yes. I know. I was just thinking for an alternitive to the bsearch.


From,
Nice coder
Click here to patch the mozilla IDN exploit, or click Here then type in Network.enableidn and set its value to false. Restart the browser for the patches to work.

This topic is closed to new replies.

Advertisement