include/vector.h
branchpyrit
changeset 95 ca7d4c665531
parent 94 4c8abb8977dc
equal deleted inserted replaced
94:4c8abb8977dc 95:ca7d4c665531
    34 #include "common.h"
    34 #include "common.h"
    35 #include "simd.h"
    35 #include "simd.h"
    36 
    36 
    37 using namespace std;
    37 using namespace std;
    38 
    38 
       
    39 #define NO_SIMD_VECTOR
       
    40 
    39 /**
    41 /**
    40  * three cell vector
    42  * three (four) cell vector
    41  */
    43  */
    42 class Vector
    44 class Vector
    43 {
    45 {
    44 public:
    46 public:
    45 	// data
    47 	// data
    90 	Vector operator-() const { return Vector(-x, -y, -z); };
    92 	Vector operator-() const { return Vector(-x, -y, -z); };
    91 
    93 
    92 	/** Accumulate. Useful for colors. */
    94 	/** Accumulate. Useful for colors. */
    93 	Vector operator+=(const Vector &v)
    95 	Vector operator+=(const Vector &v)
    94 	{
    96 	{
    95 #ifdef NO_SIMD
    97 #ifdef NO_SIMD_VECTOR
    96 		x += v.x;
    98 		x += v.x;
    97 		y += v.y;
    99 		y += v.y;
    98 		z += v.z;
   100 		z += v.z;
    99 #else
   101 #else
   100 		mf4 = madd(mf4, v.mf4);
   102 		mf4 = madd(mf4, v.mf4);
   122 	};
   124 	};
   123 
   125 
   124 	/** Sum of two vectors */
   126 	/** Sum of two vectors */
   125 	friend Vector operator+(const Vector &a, const Vector &b)
   127 	friend Vector operator+(const Vector &a, const Vector &b)
   126 	{
   128 	{
   127 #ifdef NO_SIMD
   129 #ifdef NO_SIMD_VECTOR
   128 		return Vector(a.x + b.x, a.y + b.y, a.z + b.z);
   130 		return Vector(a.x + b.x, a.y + b.y, a.z + b.z);
   129 #else
   131 #else
   130 		return Vector(madd(a.mf4, b.mf4));
   132 		return Vector(madd(a.mf4, b.mf4));
   131 #endif
   133 #endif
   132 	};
   134 	};
   133 
   135 
   134 	/** Difference of two vectors */
   136 	/** Difference of two vectors */
   135 	friend Vector operator-(const Vector &a, const Vector &b)
   137 	friend Vector operator-(const Vector &a, const Vector &b)
   136 	{
   138 	{
   137 #if defined(NO_SIMD) || defined(MSVC)
   139 #ifdef NO_SIMD_VECTOR
   138 		return Vector(a.x - b.x, a.y - b.y, a.z - b.z);
   140 		return Vector(a.x - b.x, a.y - b.y, a.z - b.z);
   139 #else
   141 #else
   140 		// this faults in MSVC, for unknown reason
       
   141 		return Vector(msub(a.mf4, b.mf4));
   142 		return Vector(msub(a.mf4, b.mf4));
   142 #endif
   143 #endif
   143 	};
   144 	};
   144 
   145 
   145 	/** Dot product */
   146 	/** Dot product */
   176 	};
   177 	};
   177 
   178 
   178 	/** Get f/v, i.e. inverted vector multiplied by scalar */
   179 	/** Get f/v, i.e. inverted vector multiplied by scalar */
   179 	friend Vector operator/(const Float &f, const Vector &v)
   180 	friend Vector operator/(const Float &f, const Vector &v)
   180 	{
   181 	{
   181 #ifdef NO_SIMD
   182 #ifdef NO_SIMD_VECTOR
   182 		return Vector(f / v.x, f / v.y, f / v.z);
   183 		return Vector(f / v.x, f / v.y, f / v.z);
   183 #else
   184 #else
   184 		return Vector(mdiv(mset1(f), v.mf4));
   185 		return Vector(mdiv(mset1(f), v.mf4));
   185 #endif
   186 #endif
   186 	};
   187 	};
   198 	};
   199 	};
   199 
   200 
   200 	/** Cell by cell product (only useful for colors) */
   201 	/** Cell by cell product (only useful for colors) */
   201 	friend Vector operator*(const Vector &a, const Vector &b)
   202 	friend Vector operator*(const Vector &a, const Vector &b)
   202 	{
   203 	{
   203 #ifdef NO_SIMD
   204 #ifdef NO_SIMD_VECTOR
   204 		return Vector(a.x * b.x, a.y * b.y, a.z * b.z);
   205 		return Vector(a.x * b.x, a.y * b.y, a.z * b.z);
   205 #else
   206 #else
   206 		return Vector(mmul(a.mf4, b.mf4));
   207 		return Vector(mmul(a.mf4, b.mf4));
   207 #endif
   208 #endif
   208 	};
   209 	};