Mail Archives: djgpp/1996/12/14/10:19:00
From: | murray AT southeast DOT net (Murray Stokely)
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | math optimization
|
Date: | Sat, 14 Dec 1996 08:48:58 GMT
|
Organization: | ACiD Productions
|
Lines: | 49
|
Message-ID: | <32b26866.241305048@nntp.southeast.net>
|
Reply-To: | murray AT southeast DOT net
|
NNTP-Posting-Host: | ts7-000.southeast.net
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
This is a little code snippet from a vesa lens effect I coded,
The diameter and magnification of the lens are adjustable in realtime
via the +/- keys so I need the lens calculating function as fast as
possible. Someone gave me a good tip with my sqrt problem earlier in
using the difference of squares to take out one of the multiplies but
I'd like to take it a step further. This routine is actualy faster
than I expected it would be on my 486dx4, but still every clock cycle
counts ;) I know theres lots of room for improvement, so any tips
would be appreciated.
( I'll eventualy convert all doubles/floats to 16.16 fixed point, so
skip that obvious MAJOR optimization )
void calculate_tfm(int diameter, char magnification)
{
int a,b,x,y,z,s;
int radius;
z=0;
radius=diameter/2;
// s=round(sqrt(abs((radius*radius) -
(magnification*magnification))));
// difference of squares - (only one imul instruction)
s=round(sqrt(abs((radius-magnification) *
(radius+magnification))));
for(y=-radius;y<diameter-radius;y++)
{
for(x=-radius;x<diameter-radius;x++)
{
if (((x*x) + (y*y)) >= (s*s))
{
a=x;
b=y;
} else {
//
z=round(sqrt((radius*radius)-(x*x)-(y*y)));
z=round(sqrt((radius-x)*(radius+x)-(y*y)));
a=round(x*magnification/z);
b=round(y*magnification/z);
}
tfm[(y+radius)*diameter+(x+radius)]=(b+radius)*diameter+(a+radius);
} // end of for x
} // end of for y
}
Murray Stokely ( murray AT southeast DOT net )
http://www.cdrom.com/pub/artpacks
- Raw text -