include/scene.h
branchpyrit
changeset 95 ca7d4c665531
parent 94 4c8abb8977dc
child 98 64638385798a
--- a/include/scene.h	Thu May 08 09:21:25 2008 +0200
+++ b/include/scene.h	Sat May 10 14:29:37 2008 +0200
@@ -94,6 +94,11 @@
 		v = cross(p, u);
 	};
 
+#ifndef NO_SIMD
+	void *operator new(size_t size) { return _mm_malloc(size, 16); };
+	void operator delete(void *p) { _mm_free(p); };
+#endif
+
 	const Vector &getEye() const { return eye; };
 	const Vector &getp() const { return p; };
 	const Vector &getu() const { return u; };
@@ -122,18 +127,18 @@
 		mfloat4 m;
 
 		// m1(xyz) = u * samples[i].x
-		m1x = mset1(u.x);
-		m1y = mset1(u.y);
-		m1z = mset1(u.z);
+		m1x = mshuffle(u.mf4, u.mf4, mShuffle0); // u.x
+		m1y = mshuffle(u.mf4, u.mf4, mShuffle1); // u.y
+		m1z = mshuffle(u.mf4, u.mf4, mShuffle2); // u.z
 		m = mset(samples[3].x, samples[2].x, samples[1].x, samples[0].x);
 		m1x = mmul(m1x, m);
 		m1y = mmul(m1y, m);
 		m1z = mmul(m1z, m);
 
 		// m2(xyz) = v * samples[i].y
-		m2x = mset1(v.x);
-		m2y = mset1(v.y);
-		m2z = mset1(v.z);
+		m2x = mshuffle(v.mf4, v.mf4, mShuffle0); // v.x
+		m2y = mshuffle(v.mf4, v.mf4, mShuffle1); // v.y
+		m2z = mshuffle(v.mf4, v.mf4, mShuffle2); // v.z
 		m = mset(samples[3].y, samples[2].y, samples[1].y, samples[0].y);
 		m2x = mmul(m2x, m);
 		m2y = mmul(m2y, m);
@@ -151,20 +156,20 @@
 		m1z = mmul(m1z, m);
 
 		// m1(xyz) = p - m1 = p - (u*samples[i].x + v*samples[i].y)*F = dir
-		m2x = mset1(p.x);
-		m2y = mset1(p.y);
-		m2z = mset1(p.z);
+		m2x = mshuffle(p.mf4, p.mf4, mShuffle0); // p.x
+		m2y = mshuffle(p.mf4, p.mf4, mShuffle1); // p.y
+		m2z = mshuffle(p.mf4, p.mf4, mShuffle2); // p.z
 		rays.dir.mx = msub(m2x, m1x);
 		rays.dir.my = msub(m2y, m1y);
 		rays.dir.mz = msub(m2z, m1z);
 
 		// copy origin
-		rays.o.mx = mset1(eye.x);
-		rays.o.my = mset1(eye.y);
-		rays.o.mz = mset1(eye.z);
+		rays.o.mx = mshuffle(eye.mf4, eye.mf4, mShuffle0); // eye.x
+		rays.o.my = mshuffle(eye.mf4, eye.mf4, mShuffle1); // eye.y
+		rays.o.mz = mshuffle(eye.mf4, eye.mf4, mShuffle2); // eye.z
 
 		rays.dir.normalize();
-		rays.invdir = mOne/rays.dir;
+		rays.invdir = mOne / rays.dir;
 	};
 #endif
 };