Re: Faster divides

idr@cs.pdx.edu (Ian D Romanick)
Mon, 23 Oct 1995 18:32:22 GMT

          From comp.compilers

Related articles
Faster divides sdenman@wolf.cs.washington.edu (1995-10-14)
Re: Faster divides idr@cs.pdx.edu (1995-10-23)
Re: Faster divides cdg@nullstone.com (1995-10-25)
| List of all articles for this month |
Newsgroups: comp.graphics.algorithms,comp.compilers
From: idr@cs.pdx.edu (Ian D Romanick)
Keywords: arithmetic, performance
Organization: Compilers Central
References: 95-10-084
Date: Mon, 23 Oct 1995 18:32:22 GMT

sdenman@wolf.cs.washington.edu (Stuart Denman) writes:


>long dsh,dtx,dty,dy;
>...do some calculations to find values for them...
>dsh = (dsh << 16) / dy;
>dtx = (dtx << 16) / dy;
>dty = (dty << 16) / dy;


Uh...I may be totally wrong here, but you should be able to do it with
three fixed point multiplies. Try this:


dy_inv = (0x00010000 << 14) / (dy >> 2); /* dy^(-1) = 1 / dy */
dsh = (dsh * dy) >> 16;
dtx = (dtx * dy) >> 16;
dty = (dty * dy) >> 16;


The reason for the shift by 14 and the shift by 2 is that 0x010000
shifted by 16 won't fit in 32 bits. Which could be a problem. :) Hope
this helps.


--
- See the Epsilon coder page at: ____ ____
    http://www.cs.pdx.edu/~idr/
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.