RE: [GD-Windows] memory alignment vs passing by value
Brought to you by:
vexxed72
From: Andras B. <bn...@ma...> - 2004-12-02 00:22:33
|
> 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 |