From: Steven Scott Falls Newsgroups: comp.os.msdos.djgpp Subject: Optimization With Assembly Date: Sun, 26 Jan 1997 18:10:48 -0800 Organization: Steven S. Falls CPA Lines: 97 Message-ID: <32EC0EA8.27D9@sprynet.com> NNTP-Posting-Host: hd54-186.compuserve.com Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------312D1C4B278" To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp This is a multi-part message in MIME format. --------------312D1C4B278 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Hello every body, I am Ardy and I want to know how to optimize this function "Transform". The source code is attached to this letter. If you have any suggestions please send to ssfcpa AT sprynet DOT com Thanks, Ardy --------------312D1C4B278 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="FIXED.CC" #include #include #include #define DEPTH 1000 //Max Z depth struct Point3D { long X; long Y; long Z; }; struct Point2D { int X; int Y; }; long Z_Tbl[DEPTH]; // (1/Z)*100 Table //Makes Table (1/Z)*100 void TableMake(void) { float Z,zpos; Z=0; for(long I=0;I>8,100*(unsigned long)(val & 0x00ff)/256); } //Convert 3D cordinates to 2D cordinates inline Point2D Transform(Point3D Pts3D) { Point2D Pts2D; long Z=Z_Tbl[(Pts3D.Z>>8)]; // Pts2D.X=(((Z*Pts3D.X)>>16)+160); __asm__ __volatile__(" Imul %%edx\n Sar $16,%%eax\n Add $160,%%eax" : "=a" (Pts2D.X) : "a" (Z),"d"(Pts3D.X) :"eax","edx","memory" ); // Pts2D.Y=(((Z*Pts3D.Y)>>16)+100); __asm__ __volatile__(" Imul %%edx\n Sar $16,%%eax\n Add $100,%%eax" : "=a" (Pts2D.Y) : "a" (Z),"d"(Pts3D.Y) :"eax","edx","memory" ); return (Pts2D); } void Speed_Test(void) { Point3D Pts1; Point2D Pts2; Pts1.X=(50<<8);Pts1.Y=(40<<8);Pts1.Z=(60<<8); for(unsigned int a=0;a<64000;a++) { Pts2=Transform(Pts1); } } void main(void) { clrscr(); TableMake(); Speed_Test(); } --------------312D1C4B278--