www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/01/27/02:19:39

From: Steven Scott Falls <ssfcpa AT sprynet DOT com>
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
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 <stdio.h>
#include <conio.h>
#include <iostream.h>
#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<DEPTH;I++) {
      Z++;
      zpos=((1/(Z+100))*100);    //Generate floating point number
      Z_Tbl[I]=(long)(zpos*256); //Store as fixed point
      zpos++;
   }
}

void Print_Fixed(long val)
{
   printf("%ld.%ld\n",val>>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--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019