A little function to speed things up a bit

Programming Reality Factory and Genesis3D.
Post Reply
User avatar
paradoxnj
RF2 Dev Team
Posts: 1328
Joined: Wed Mar 01, 2006 7:37 pm
Location: Brick, NJ
Contact:

A little function to speed things up a bit

Post by paradoxnj » Fri Nov 03, 2006 11:43 am

After running VTune against Jet3D, I noticed that Jet3D was spending a lot of time converting floats to DWORDs. As we all know, that is an evil operation and should have holy water sprayed all over it. Fear not, as I have exercised that demon. :) I wrote a small inline assembly function that converts a float to a DWORD without resetting the FPU each time. This little function gained us about 5 FPS. I noticed that Genesis has the same issue also which is why I am posting it here.

Code: Select all

inline DWORD FtoDW(float f)
{
	DWORD				d;

	_asm
	{
		fld			f
		lea			eax, [d]
		fistp		dword ptr[eax]
	}

	return d;
}
Just replace the FtoDW() function in the drivers with this and for any float to DWORD (or integer) conversions, use it.

Post Reply