RE: memory alignment vs passing by value

"Andras Balogh" <[email protected]> Wed, 1 Dec 2004 16:22:28 -0800
Newsgroups gmane.games.devel.windows
Message-ID <[email protected]>
> Post your function if you can... its kinda hard to figure it out with what
> you say.

Sure, here's a simple sample :)

//______________________________________________________________
template <class T>
class Vector
{
public:
	union {
		T v[4];
		struct {
			T	x;
			T	y;
			T	z;
			T	w;
		};
	};

	Vector() {}
	Vector(T f): x(f), y(f), z(f), w(f) {}
	Vector(T ix, T iy, T iz = 0, T iw = 0): x(ix), y(iy), z(iz), w(iw)
{}
	operator T* () {return v;}
	__forceinline inline T dprod(const Vector u) const { return x*u.x +
y*u.y + z*u.z + w*u.w;}
};

//______________________________________________________________
typedef float f32;
typedef unsigned long int u32;
typedef Vector<float> v4f;

//______________________________________________________________
inline v4f interpolate_CPP_1(const f32 x, const f32 y, const v4f v[])
{
	f32 xy = x*y;
	v4f c(1-x-y+xy, x-xy, y-xy, xy);
	return v4f(
		c.dprod(v[0]),
		c.dprod(v[1]),
		c.dprod(v[2]),
		c.dprod(v[3])
	);
}
//______________________________________________________________

I measured the time of computing 100 million bilinear interpolation using
dot products, and changing the dprod operation to accept a const reference
instead of the const value makes the test run an order of magnitude slower!!
And I also did the same change in a vector math heavy graphics demo, and the
speed difference was remarkable!


Andras 





-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now. 
http://productguide.itmanagersjournal.com/
_______________________________________________
Gamedevlists-windows mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gamedevlists-windows
Archives:
http://sourceforge.net/mailarchive/forum.php?forum_id=555