SIMD improvement.

This commit is contained in:
scorpioblood 2024-06-07 17:34:35 +02:00
parent a2c176750d
commit e894b55748
10 changed files with 1655 additions and 84 deletions

@ -0,0 +1,280 @@
#pragma once
#include "Core/public/Math/Boilerplate.h"
namespace Phanes::Core::Math::Detail
{
template<IntType T, bool S>
struct construct_ivec3 {};
template<IntType T, bool S>
struct compute_ivec3_add {};
template<IntType T, bool S>
struct compute_ivec3_sub {};
template<IntType T, bool S>
struct compute_ivec3_mul {};
template<IntType T, bool S>
struct compute_ivec3_div {};
template<IntType T, bool S>
struct compute_ivec3_mod {};
template<IntType T, bool S>
struct compute_ivec3_eq {};
template<IntType T, bool S>
struct compute_ivec3_ieq {};
template<IntType T, bool S>
struct compute_ivec3_inc {};
template<IntType T, bool S>
struct compute_ivec3_dec {};
template<IntType T, bool S>
struct compute_ivec3_and {};
template<IntType T, bool S>
struct compute_ivec3_or {};
template<IntType T, bool S>
struct compute_ivec3_xor {};
template<IntType T, bool S>
struct compute_ivec3_left_shift {};
template<IntType T, bool S>
struct compute_ivec3_right_shift {};
template<IntType T, bool S>
struct compute_ivec3_bnot {};
template<IntType T>
struct construct_ivec3<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& v1, const TIntVector2<T, false>& v2)
{
v1.x = v2.x;
v1.y = v2.y;
v1.z = v2.z;
}
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& v1, T s)
{
v1.x = s;
v1.y = s;
}
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& v1, T x, T y)
{
v1.x = x;
v1.y = y;
}
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& v1, const T* comp)
{
v1.x = comp[0];
v1.y = comp[1];
}
};
template<IntType T>
struct compute_ivec3_add<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1, const Phanes::Core::Math::TIntVector2<T, false>& v2)
{
r.x = v1.x + v2.x;
r.y = v1.y + v2.y;
}
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1, T s)
{
r.x = v1.x + s;
r.y = v1.y + s;
}
};
template<IntType T>
struct compute_ivec3_sub<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1, const Phanes::Core::Math::TIntVector2<T, false>& v2)
{
r.x = v1.x - v2.x;
r.y = v1.y - v2.y;
}
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1, T s)
{
r.x = v1.x - s;
r.y = v1.y - s;
}
};
template<IntType T>
struct compute_ivec3_mul<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1, const Phanes::Core::Math::TIntVector2<T, false>& v2)
{
r.x = v1.x * v2.x;
r.y = v1.y * v2.y;
}
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1, T s)
{
r.x = v1.x * s;
r.y = v1.y * s;
}
};
template<IntType T>
struct compute_ivec3_div<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1, const Phanes::Core::Math::TIntVector2<T, false>& v2)
{
r.x = v1.x / v2.x;
r.y = v1.y / v2.y;
}
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1, T s)
{
s = (T)1.0 / s;
r.x = v1.x * s;
r.y = v1.y * s;
}
};
template<IntType T>
struct compute_ivec3_mod<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1, const Phanes::Core::Math::TIntVector2<T, false>& v2)
{
r.x = v1.x % v2.x;
r.y = v1.y % v2.y;
}
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1, T s)
{
r.x = v1.x % s;
r.y = v1.y % s;
}
};
template<IntType T>
struct compute_ivec3_eq<T, false>
{
static constexpr bool map(const Phanes::Core::Math::TIntVector2<T, false>& v1, const Phanes::Core::Math::TIntVector2<T, false>& v2)
{
return (Phanes::Core::Math::Abs(v1.x - v2.x) < P_FLT_INAC &&
Phanes::Core::Math::Abs(v1.y - v2.y) < P_FLT_INAC);
}
};
template<IntType T>
struct compute_ivec3_ieq<T, false>
{
static constexpr bool map(const Phanes::Core::Math::TIntVector2<T, false>& v1, const Phanes::Core::Math::TIntVector2<T, false>& v2)
{
return (Phanes::Core::Math::Abs(v1.x - v2.x) > P_FLT_INAC ||
Phanes::Core::Math::Abs(v1.y - v2.y) > P_FLT_INAC);
}
};
template<IntType T>
struct compute_ivec3_inc<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1)
{
r.x = v1.x + 1;
r.y = v1.y + 1;
}
};
template<IntType T>
struct compute_ivec3_dec<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1)
{
r.x = v1.x - 1;
r.y = v1.y - 1;
}
};
template<IntType T>
struct compute_ivec3_and<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1, const Phanes::Core::Math::TIntVector2<T, false>& v2)
{
r.x = v1.x & v2.x;
r.y = v1.y & v2.y;
}
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1, T s)
{
r.x = v1.x & s;
r.y = v1.y & s;
}
};
template<IntType T>
struct compute_ivec3_or<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1, const Phanes::Core::Math::TIntVector2<T, false>& v2)
{
r.x = v1.x | v2.x;
r.y = v1.y | v2.y;
}
};
template<IntType T>
struct compute_ivec3_xor<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1, const Phanes::Core::Math::TIntVector2<T, false>& v2)
{
r.x = v1.x ^ v2.x;
r.y = v1.y ^ v2.y;
}
};
template<IntType T>
struct compute_ivec3_left_shift<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1, const Phanes::Core::Math::TIntVector2<T, false>& v2)
{
r.x = v1.x << v2.x;
r.y = v1.y << v2.y;
}
};
template<IntType T>
struct compute_ivec3_right_shift<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1, const Phanes::Core::Math::TIntVector2<T, false>& v2)
{
r.x = v1.x >> v2.x;
r.y = v1.y >> v2.y;
}
};
template<IntType T>
struct compute_ivec3_bnot<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector2<T, false>& r, const Phanes::Core::Math::TIntVector2<T, false>& v1)
{
r.x = ~v1.x;
r.y = ~v1.y;
}
};
}

@ -0,0 +1,359 @@
#pragma once
#include "Core/public/Math/Boilerplate.h"
namespace Phanes::Core::Math::Detail
{
template<IntType T, bool S>
struct construct_ivec4 {};
template<IntType T, bool S>
struct compute_ivec4_add {};
template<IntType T, bool S>
struct compute_ivec4_sub {};
template<IntType T, bool S>
struct compute_ivec4_mul {};
template<IntType T, bool S>
struct compute_ivec4_div {};
template<IntType T, bool S>
struct compute_ivec4_mod {};
template<IntType T, bool S>
struct compute_ivec4_eq {};
template<IntType T, bool S>
struct compute_ivec4_ieq {};
template<IntType T, bool S>
struct compute_ivec4_inc {};
template<IntType T, bool S>
struct compute_ivec4_dec {};
template<IntType T, bool S>
struct compute_ivec4_and {};
template<IntType T, bool S>
struct compute_ivec4_or {};
template<IntType T, bool S>
struct compute_ivec4_xor {};
template<IntType T, bool S>
struct compute_ivec4_left_shift {};
template<IntType T, bool S>
struct compute_ivec4_right_shift {};
template<IntType T, bool S>
struct compute_ivec4_bnot {};
template<IntType T>
struct construct_ivec4<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector4<T, false>& v1, const TIntVector4<T, false>& v2)
{
v1.x = v2.x;
v1.y = v2.y;
v1.z = v2.z;
v1.w = v2.w;
}
static constexpr void map(Phanes::Core::Math::TIntVector4<T, false>& v1, T s)
{
v1.x = s;
v1.y = s;
v1.z = s;
v1.w = s;
}
static constexpr void map(Phanes::Core::Math::TIntVector4<T, false>& v1, T x, T y, T z, T w)
{
v1.x = x;
v1.y = y;
v1.y = z;
v1.y = w;
}
static constexpr void map(Phanes::Core::Math::TIntVector4<T, false>& v1, const T* comp)
{
v1.x = comp[0];
v1.y = comp[1];
v1.z = comp[2];
v1.w = comp[3];
}
};
template<IntType T>
struct compute_ivec4_add<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector4<T, false>& r, const Phanes::Core::Math::TIntVector4<T, false>& v1, const Phanes::Core::Math::TIntVector4<T, false>& v2)
{
r.x = v1.x + v2.x;
r.y = v1.y + v2.y;
r.z = v1.z + v2.z;
r.w = v1.w + v2.w;
}
static constexpr void map(Phanes::Core::Math::TIntVector4<T, false>& r, const Phanes::Core::Math::TIntVector4<T, false>& v1, T s)
{
r.x = v1.x + s;
r.y = v1.y + s;
r.z = v1.z + s;
r.w = v1.w + s;
}
};
template<IntType T>
struct compute_ivec4_sub<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector4<T, false>& r, const Phanes::Core::Math::TIntVector4<T, false>& v1, const Phanes::Core::Math::TIntVector4<T, false>& v2)
{
r.x = v1.x - v2.x;
r.y = v1.y - v2.y;
r.z = v1.z - v2.z;
r.w = v1.w - v2.w;
}
static constexpr void map(Phanes::Core::Math::TIntVector4<T, false>& r, const Phanes::Core::Math::TIntVector4<T, false>& v1, T s)
{
r.x = v1.x - s;
r.y = v1.y - s;
r.z = v1.z - s;
r.w = v1.w - s;
}
};
template<IntType T>
struct compute_ivec4_mul<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector4<T, false>& r, const Phanes::Core::Math::TIntVector4<T, false>& v1, const Phanes::Core::Math::TIntVector4<T, false>& v2)
{
r.x = v1.x * v2.x;
r.y = v1.y * v2.y;
r.z = v1.z * v2.z;
r.w = v1.w * v2.w;
}
static constexpr void map(Phanes::Core::Math::TIntVector4<T, false>& r, const Phanes::Core::Math::TIntVector4<T, false>& v1, T s)
{
r.x = v1.x * s;
r.y = v1.y * s;
r.z = v1.z * s;
r.w = v1.w * s;
}
};
template<IntType T>
struct compute_ivec4_div<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector4<T, false>& r, const Phanes::Core::Math::TIntVector4<T, false>& v1, const Phanes::Core::Math::TIntVector4<T, false>& v2)
{
r.x = v1.x / v2.x;
r.y = v1.y / v2.y;
r.z = v1.z / v2.z;
r.w = v1.w / v2.w;
}
static constexpr void map(Phanes::Core::Math::TIntVector4<T, false>& r, const Phanes::Core::Math::TIntVector4<T, false>& v1, T s)
{
s = (T)1.0 / s;
r.x = v1.x * s;
r.y = v1.y * s;
r.z = v1.z * s;
r.w = v1.w * s;
}
};
template<IntType T>
struct compute_ivec4_mod<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector4<T, false>& r, const Phanes::Core::Math::TIntVector4<T, false>& v1, const Phanes::Core::Math::TIntVector4<T, false>& v2)
{
r.x = v1.x % v2.x;
r.y = v1.y % v2.y;
r.z = v1.z % v2.z;
r.w = v1.w % v2.w;
}
static constexpr void map(Phanes::Core::Math::TIntVector4<T, false>& r, const Phanes::Core::Math::TIntVector4<T, false>& v1, T s)
{
r.x = v1.x % s;
r.y = v1.y % s;
r.z = v1.z % s;
r.w = v1.w % s;
}
};
template<IntType T>
struct compute_ivec4_eq<T, false>
{
static constexpr bool map(const Phanes::Core::Math::TIntVector4<T, false>& v1, const Phanes::Core::Math::TIntVector4<T, false>& v2)
{
return (v1.x == v2.x &&
v1.y == v2.y &&
v1.z == v2.z &&
v1.w == v2.w);
}
};
template<IntType T>
struct compute_ivec4_ieq<T, false>
{
static constexpr bool map(const Phanes::Core::Math::TIntVector4<T, false>& v1, const Phanes::Core::Math::TIntVector4<T, false>& v2)
{
return (v1.x != v2.x ||
v1.y != v2.y ||
v1.z != v2.z ||
v1.w != v2.w);
}
};
template<IntType T>
struct compute_ivec4_inc<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector4<T, false>& r, const Phanes::Core::Math::TIntVector4<T, false>& v1)
{
r.x = v1.x + 1;
r.y = v1.y + 1;
r.z = v1.z + 1;
r.w = v1.w + 1;
}
};
template<IntType T>
struct compute_ivec4_dec<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector4<T, false>& r, const Phanes::Core::Math::TIntVector4<T, false>& v1)
{
r.x = v1.x - 1;
r.y = v1.y - 1;
r.z = v1.z - 1;
r.w = v1.w - 1;
}
};
template<IntType T>
struct compute_ivec4_and<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector4<T, false>& r, const Phanes::Core::Math::TIntVector4<T, false>& v1, const Phanes::Core::Math::TIntVector4<T, false>& v2)
{
r.x = v1.x & v2.x;
r.y = v1.y & v2.y;
r.z = v1.z & v2.z;
r.w = v1.w & v2.w;
}
static constexpr void map(Phanes::Core::Math::TIntVector4<T, false>& r, const Phanes::Core::Math::TIntVector4<T, false>& v1, T s)
{
r.x = v1.x & s;
r.y = v1.y & s;
r.z = v1.z & s;
r.w = v1.w & s;
}
};
template<IntType T>
struct compute_ivec4_or<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector4<T, false>& r, const Phanes::Core::Math::TIntVector4<T, false>& v1, const Phanes::Core::Math::TIntVector4<T, false>& v2)
{
r.x = v1.x | v2.x;
r.y = v1.y | v2.y;
r.z = v1.z | v2.z;
r.w = v1.w | v2.w;
}
static constexpr void map(Phanes::Core::Math::TIntVector4<T, false>& r, const Phanes::Core::Math::TIntVector4<T, false>& v1, T s)
{
r.x = v1.x | s;
r.y = v1.y | s;
r.z = v1.z | s;
r.w = v1.w | s;
}
};
template<IntType T>
struct compute_ivec4_xor<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector4<T, false>& r, const Phanes::Core::Math::TIntVector4<T, false>& v1, const Phanes::Core::Math::TIntVector4<T, false>& v2)
{
r.x = v1.x ^ v2.x;
r.y = v1.y ^ v2.y;
r.z = v1.z ^ v2.z;
r.w = v1.w ^ v2.w;
}
static constexpr void map(Phanes::Core::Math::TIntVector4<T, false>& r, const Phanes::Core::Math::TIntVector4<T, false>& v1, T s)
{
r.x = v1.x ^ s;
r.y = v1.y ^ s;
r.z = v1.z ^ s;
r.w = v1.w ^ s;
}
};
template<IntType T>
struct compute_ivec4_left_shift<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector4<T, false>& r, const Phanes::Core::Math::TIntVector4<T, false>& v1, const Phanes::Core::Math::TIntVector4<T, false>& v2)
{
r.x = v1.x << v2.x;
r.y = v1.y << v2.y;
r.z = v1.z << v2.z;
r.w = v1.w << v2.w;
}
static constexpr void map(Phanes::Core::Math::TIntVector4<T, false>& r, const Phanes::Core::Math::TIntVector4<T, false>& v1, T s)
{
r.x = v1.x << s;
r.y = v1.y << s;
r.z = v1.z << s;
r.w = v1.w << s;
}
};
template<IntType T>
struct compute_ivec4_right_shift<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector4<T, false>& r, const Phanes::Core::Math::TIntVector4<T, false>& v1, const Phanes::Core::Math::TIntVector4<T, false>& v2)
{
r.x = v1.x >> v2.x;
r.y = v1.y >> v2.y;
r.z = v1.z >> v2.z;
r.w = v1.w >> v2.w;
}
static constexpr void map(Phanes::Core::Math::TIntVector4<T, false>& r, const Phanes::Core::Math::TIntVector4<T, false>& v1, T s)
{
r.x = v1.x >> s;
r.y = v1.y >> s;
r.z = v1.z >> s;
r.w = v1.w >> s;
}
};
template<IntType T>
struct compute_ivec4_bnot<T, false>
{
static constexpr void map(Phanes::Core::Math::TIntVector4<T, false>& r, const Phanes::Core::Math::TIntVector4<T, false>& v1)
{
r.x = ~v1.x;
r.y = ~v1.y;
}
};
}

@ -3,4 +3,5 @@
// --- Vectors ------------------------
#include "Core/public/Math/Vector2.hpp" // <-- Includes Vector3/4 automatically
#include "Core/public/Math/IntVector2.hpp"
#include "Core/public/Math/IntVector2.hpp"
#include "Core/public/Math/IntVector4.hpp"

@ -3,9 +3,12 @@
#include "Core/public/Math/Boilerplate.h"
#include "Core/public/Math/MathCommon.hpp"
#include "Core/public/Math/MathAbstractTypes.h"
#include "Core/public/Math/MathFwd.h"
#include "Core/public/Math/SIMD/Storage.h"
#include "Core/public/Math/IntVector4.hpp"
#ifndef P_DEBUG
#pragma warning(disable : 4244)
#endif
@ -28,54 +31,8 @@ namespace Phanes::Core::Math {
* A 3D Vector with components x, y and z with integer precision.
*/
template<IntType T>
struct TIntVector3 {
public:
// Using in combination with a struct and an array allows us the reflect changes of the x and y variables in the comp array and vise versa.
union
{
struct
{
/** X component of Vector
*
* @ref [FIELD]components
* @note x does not hold the component, but is a reference two the second item in the components array. The varibale exists wholly for convenience.
*/
T x;
/** Y component of Vector
*
* @ref [FIELD]components
*
* @note y does not hold the component, but is a reference two the second item in the components array. The varibale exists wholly for convenience.
*/
T y;
/** Z component of Vector
*
* @ref [FIELD]components
*
* @note Z does not hold the component, but is a reference two the second item in the components array. The varibale exists wholly for convenience.
*/
T z;
};
/** Components array holding the data
*
* @ref [FIELD]x
* @ref [FIELD]y
* @ref [FIELD]z
*
* @note Components are split into x, y and z. Access and manipulation is possible by these variables.
*/
T comp[3];
};
template<IntType T, bool A>
struct TIntVector3 : public TIntVector4<T, A> {
public:
@ -96,24 +53,7 @@ namespace Phanes::Core::Math {
}
/**
* Move constructor
*/
TIntVector3(TIntVector3<T>&& v)
{
this->comp = v.comp;
v.comp = nullptr;
}
/**
* Convert other type of vector
*/
template<IntType OtherIntType>
explicit TIntVector3(const TIntVector3<OtherIntType>& v) : x((T)v.x), y((T)v.y) {};
/**
* Construct Vector from xy components.
* Construct Vector from xyz components.
*
* @param(x) X component
* @param(y) Y component

@ -0,0 +1,443 @@
#pragma once
#include "Core/public/Math/Boilerplate.h"
#include "Core/public/Math/MathCommon.hpp"
#include "Core/public/Math/MathFwd.h"
#include "Core/public/Math/SIMD/Storage.h"
#ifndef P_DEBUG
#pragma warning(disable : 4244)
#endif
#ifndef INTVECTOR4_H
#define INTVECTOR4_H
namespace Phanes::Core::Math {
/**
* A 4D Vector with components x, y, z and w with integer precision.
*/
template<IntType T, bool A>
struct TIntVector4 {
public:
union
{
struct
{
/** X component of Vector
*
* @ref [FIELD]components
*
* @note x does not hold the component, but is a reference two the second item in the components array. The varibale exists wholly for convenience.
*/
T x;
/** Y component of Vector
*
* @ref [FIELD]components
*
* @note y does not hold the component, but is a reference two the second item in the components array. The varibale exists wholly for convenience.
*/
T y;
/** Z component of Vector
*
* @ref [FIELD]components
*
* @note z does not hold the component, but is a reference two the second item in the components array. The varibale exists wholly for convenience.
*/
T z;
/** W component of Vector
*
* @ref [FIELD]components
*
* @note w does not hold the component, but is a reference two the second item in the components array. The varibale exists wholly for convenience.
*/
T w;
};
union
{
typename SIMD::Storage<4, T, SIMD::use_simd<T, 4, A>::value>::type comp;
typename SIMD::Storage<4, T, SIMD::use_simd<T, 4, A>::value>::type data;
};
};
public:
/**
* Default constructor without initialization
*/
TIntVector4() = default;
/// <summary>
/// Copy constructor.
/// </summary>
/// <param name="v"></param>
TIntVector4(const TIntVector4<T, A>& v);
/// <summary>
/// Construct vector from x, y, z, w components.
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="z"></param>
/// <param name="w"></param>
TIntVector4(const T x, const T y, const T z, const T w);
/// <summary>
/// Broadcast s into all components.
/// </summary>
/// <param name="s"></param>
TIntVector4(T s);
/**
* Construct Vector from two component array.
*
* @param comp Array of components
*/
TIntVector4(const T *comp);
/// <summary>
/// Construct vector from two 2d vectors
/// <param>
/// x,y = v1.x, v2.y
/// </param>
/// z,w = v2.x, v2.y
/// </summary>
/// <param name="v1"></param>
/// <param name="v2"></param>
TIntVector4(const TIntVector2<T, A>& v1, const TIntVector2<T, A>& v2);
};
/**
* Addition operation on same TIntVector4<T, A> (this) by a scalar value.
*
* @param(v1) Vector to add to
* @param(s) Scalar
*/
template<IntType T, bool A>
TIntVector4<T, A> operator+= (TIntVector4<T, A>& v1, T s);
/**
* Addition operation on same TIntVector4<T, A> (this) by a another TIntVector4<T, A>.
*
* @param(v1) Vector to add to
* @param(v2) Vector to add
*/
template<IntType T, bool A>
TIntVector4<T, A> operator+= (TIntVector4<T, A>& v1, const TIntVector4<T, A>& v2);
/**
* Substraction operation on same TIntVector4<T, A> (this) by a floating point.
*
* @param(v1) Vector to substract from
* @param(v2) Floating point to substract
*/
template<IntType T, bool A>
TIntVector4<T, A> operator-= (TIntVector4<T, A>& v1, T s);
/**
* Substraction operation on same TIntVector4<T, A> (this) by a another TIntVector4<T, A>.
*
* @param(v1) Vector to substract from
* @param(v2) Vector to substract
*/
template<IntType T, bool A>
TIntVector4<T, A> operator-= (TIntVector4<T, A>& v1, const TIntVector4<T, A>& v2);
/**
* Multiplication of TIntVector4<T, A> (this) with a floating point.
*
* @param(v1) Vector to multiply with
* @param(s Floating point to multiply with
*/
template<IntType T, bool A>
TIntVector4<T, A> operator*= (TIntVector4<T, A>& v1, T s);
/**
* Devision of Vector
*
* @param(v1) Vector to divide with
* @param(s) Scalar to divide with
*
* @note Result is rounded (obviously)
*/
template<IntType T, bool A>
TIntVector4<T, A> operator/= (TIntVector4<T, A>& v1, T s);
/**
* Stores the remainder of division by a scalar.
*
* @param(v1) Vector to divide with
* @param(s) Scalar to divide with
*/
template<IntType T, bool A>
TIntVector4<T, A> operator%= (TIntVector4<T, A>& v1, const TIntVector4<T, A>& v2);
template<IntType T, bool A>
TIntVector4<T, A> operator%= (TIntVector4<T, A>& v1, T s);
template<IntType T, bool A>
inline TIntVector4<T, A> operator&= (TIntVector4<T, A>& v1, const TIntVector4<T, A>& v2);
template<IntType T, bool A>
inline TIntVector4<T, A> operator&= (TIntVector4<T, A>& v1, T s);
template<IntType T, bool A>
inline TIntVector4<T, A> operator|= (TIntVector4<T, A>& v1, const TIntVector4<T, A>& v2);
template<IntType T, bool A>
inline TIntVector4<T, A> operator|= (TIntVector4<T, A>& v1, T s);
template<IntType T, bool A>
inline TIntVector4<T, A> operator^= (TIntVector4<T, A>& v1, const TIntVector4<T, A>& v2);
template<IntType T, bool A>
inline TIntVector4<T, A> operator^= (TIntVector4<T, A>& v1, T s);
template<IntType T, bool A>
inline TIntVector4<T, A> operator<<= (TIntVector4<T, A>& v1, const TIntVector4<T, A>& v2);
template<IntType T, bool A>
inline TIntVector4<T, A> operator<<= (TIntVector4<T, A>& v1, T s);
template<IntType T, bool A>
inline TIntVector4<T, A> operator>>= (TIntVector4<T, A>& v1, const TIntVector4<T, A>& v2);
template<IntType T, bool A>
inline TIntVector4<T, A> operator>>= (TIntVector4<T, A>& v1, T s);
/**
* Scale of Vector by floating point. (> Creates a new TIntVector4<T, A>)
*
* @param(v1) Vector to multiply with
* @param(s Floating point to multiply with
*
* @return Result Vector
*/
template<IntType T, bool A>
TIntVector4<T, A> operator* (const TIntVector4<T, A>& v1, T s);
/**
* Division of Vector by floating point. (> Creates another TIntVector4<T, A>)
*
* @see [FUNC]DivideFloat
*
* @param(v1) Vector to multiply with
* @param(s Floating point to divide with
*
* @return Result Vector
* @note Deleted, because the returntype might not implicitly be obvious, when using in code or reading.
*/
template<IntType T, bool A>
TIntVector4<T, A> operator/ (const TIntVector4<T, A>& v1, T s);
/**
* Scale of Vector by floating point. (> Creates a new TIntVector4<T, A>)
*
* @param(v1) Vector to multiply with
* @param(s Floating point to multiply with
*
* @return Result Vector
*/
template<IntType T, bool A>
FORCEINLINE TIntVector4<T, A> operator* (T s, const TIntVector4<T, A>& v1) { return v1 * s; };
/**
* Division of Vector by floating point. (> For convenience not arithmethicaly correct. Works like overloaded counterpart.)
*
* @see [FUNC]DivideFloat
*
* @param(v1) Vector to multiply with
* @param(s Floating point to divide with
*
* @return Result Vector
*
* @note Deleted, because the returntype might not implicitly be obvious, when using in code or reading.
*/
template<IntType T, bool A>
FORCEINLINE TIntVector4<T, A> operator/ (T s, const TIntVector4<T, A>& v1) { return v1 / s; };
/**
* Dot product between two Vectors.
*
* @see [FUNC]DotP
*
* @param(v1) Vector one
* @param(v2) Vector two
*
* @result Dot product
*/
template<IntType T, bool A>
T operator* (const TIntVector4<T, A>& v1, const TIntVector4<T, A>& v2);
/**
* Componentwise addition of Vector with floating point.
*
* @param(v1) Vector to add to
* @param(s Floating point to add
*
* @return Result Vector
*/
template<IntType T, bool A>
TIntVector4<T, A> operator+ (const TIntVector4<T, A>& v1, T s);
/**
* Componentwise addition of Vector with floating point.
*
* @param(v1) Vector to add to
* @param(s Floating point to add
*
* @return Result Vector
*/
template<IntType T, bool A>
TIntVector4<T, A> operator+ (const TIntVector4<T, A>& v1, const TIntVector4<T, A>& v2);
/**
* Componentwise substraction of Vector with floating point.
*
* @param(v1) Vector to substract from
* @param(s Floating point to substract
*
* @return Result Vector
*/
template<IntType T, bool A>
TIntVector4<T, A> operator- (const TIntVector4<T, A>& v1, T s);
/**
* Componentwise substraction of Vector with Vector.
*
* @param(v1) Vector to substract from
* @param(s Floating point to substract
*
* @return Result Vector
*/
template<IntType T, bool A>
TIntVector4<T, A> operator- (const TIntVector4<T, A>& v1, const TIntVector4<T, A>& v2);
/**
* Scale of Vector by floating point. (> Creates a new TIntVector4<T, A>)
*
* @param(v1) Vector to multiply with
* @param(s Floating point to multiply with
*
* @return Result Vector
*/
template<IntType T, bool A>
FORCEINLINE TIntVector4<T, A> operator% (const TIntVector4<T, A>& v1, const TIntVector4<T, A>& v2);
template<IntType T, bool A>
FORCEINLINE TIntVector4<T, A> operator% (const TIntVector4<T, A>& v1, T s);
template<IntType T, bool A>
inline TIntVector4<T, A> operator& (TIntVector4<T, A>& v1, const TIntVector4<T, A>& v2);
template<IntType T, bool A>
inline TIntVector4<T, A> operator& (TIntVector4<T, A>& v1, T s);
template<IntType T, bool A>
inline TIntVector4<T, A> operator| (TIntVector4<T, A>& v1, const TIntVector4<T, A>& v2);
template<IntType T, bool A>
inline TIntVector4<T, A> operator| (TIntVector4<T, A>& v1, T s);
template<IntType T, bool A>
inline TIntVector4<T, A> operator^ (TIntVector4<T, A>& v1, const TIntVector4<T, A>& v2);
template<IntType T, bool A>
inline TIntVector4<T, A> operator^ (TIntVector4<T, A>& v1, T s);
template<IntType T, bool A>
inline TIntVector4<T, A> operator<< (TIntVector4<T, A>& v1, const TIntVector4<T, A>& v2);
template<IntType T, bool A>
inline TIntVector4<T, A> operator<< (TIntVector4<T, A>& v1, T s);
template<IntType T, bool A>
inline TIntVector4<T, A> operator>> (TIntVector4<T, A>& v1, const TIntVector4<T, A>& v2);
template<IntType T, bool A>
inline TIntVector4<T, A> operator>> (TIntVector4<T, A>& v1, T s);
template<IntType T, bool A>
inline TIntVector4<T, A> operator~ (TIntVector4<T, A>& v1);
/**
* Compare Vector for equality.
*
* @see [FUNC]Equals
*
* @param(v1) Vector to negate
*
* @return true if equal, false if inequal
*/
template<IntType T, bool A>
bool operator== (const TIntVector4<T, A>& v1, const TIntVector4<T, A>& v2);
/**
* Compare Vector for inequality.
*
* @see [FUNC]Equals
*
* @param(v1) Vector to negate
*
* @return true if inequal, false if equal
*/
template<IntType T, bool A>
bool operator!= (const TIntVector4<T, A>& v1, const TIntVector4<T, A>& v2);
} // phanes::core::math::coretypes
#endif // !INTVECTOR3_H
#include "Core/public/Math/IntVector4.inl"

@ -0,0 +1,409 @@
#pragma once
#include "Core/public/Math/Boilerplate.h"
#include "Core/public/Math/Detail/IntVector4Decl.inl"
#include "Core/public/Math/SIMD/SIMDIntrinsics.h"
#include "Core/public/Math/SIMD/PhanesSIMDTypes.h"
#include "IntVector4.hpp"
namespace Phanes::Core::Math
{
template<IntType T, bool A>
TIntVector4<T, A>::TIntVector4(const TIntVector4<T, A>& v)
{
Detail::construct_ivec4<T, SIMD::use_simd<T, 4, A>::value>::map(*this, v);
}
template<IntType T, bool A>
TIntVector4<T, A>::TIntVector4(const T _x, const T _y, const T _z, const T _w)
{
Detail::construct_ivec4<T, SIMD::use_simd<T, 4, A>::value>::map(*this, _x, _y, _z, _w);
}
template<IntType T, bool A>
TIntVector4<T, A>::TIntVector4(const T s)
{
Detail::construct_ivec4<T, SIMD::use_simd<T, 4, A>::value>::map(*this, s);
}
template<IntType T, bool A>
TIntVector4<T, A>::TIntVector4(const T* comp)
{
Detail::construct_ivec4<T, SIMD::use_simd<T, 4, A>::value>::map(*this, comp);
}
template<IntType T, bool A>
TIntVector4<T, A>::TIntVector4(const TIntVector2<T, A>& v1, const TIntVector2<T, A>& v2)
{
Detail::construct_ivec4<T, SIMD::use_simd<T, 4, A>::value>::map(*this, v1, v2);
}
template<IntType T, bool A>
TIntVector4<T, A> operator+=(TIntVector4<T, A>& v1, const TIntVector4<T, A>& v2)
{
Detail::compute_ivec4_add<T, SIMD::use_simd<T, 4, A>::value>::map(v1, v1, v2);
return v1;
}
template<IntType T, bool A>
TIntVector4<T, A> operator+=(TIntVector4<T, A>& v1, T s)
{
Detail::compute_ivec4_add<T, SIMD::use_simd<T, 4, A>::value>::map(v1, v1, s);
return v1;
}
template<IntType T, bool A>
TIntVector4<T, A> operator-=(TIntVector4<T, A>& v1, const TIntVector4<T, A>& v2)
{
Detail::compute_ivec4_sub<T, SIMD::use_simd<T, 4, A>::value>::map(v1, v1, v2);
return v1;
}
template<IntType T, bool A>
TIntVector4<T, A> operator-=(TIntVector4<T, A>& v1, T s)
{
Detail::compute_ivec4_sub<T, SIMD::use_simd<T, 4, A>::value>::map(v1, v1, s);
return v1;
}
template<IntType T, bool A>
TIntVector4<T, A> operator*=(TIntVector4<T, A>& v1, const TIntVector4<T, A>& v2)
{
Detail::compute_ivec4_mul<T, SIMD::use_simd<T, 4, A>::value>::map(v1, v1, v2);
return v1;
}
template<IntType T, bool A>
TIntVector4<T, A> operator*=(TIntVector4<T, A>& v1, T s)
{
Detail::compute_ivec4_mul<T, SIMD::use_simd<T, 4, A>::value>::map(v1, v1, s);
return v1;
}
template<IntType T, bool A>
TIntVector4<T, A> operator/=(TIntVector4<T, A>& v1, const TIntVector4<T, A>& v2)
{
Detail::compute_ivec4_div<T, SIMD::use_simd<T, 4, A>::value>::map(v1, v1, v2);
return v1;
}
template<IntType T, bool A>
TIntVector4<T, A> operator/=(TIntVector4<T, A>& v1, T s)
{
Detail::compute_ivec4_div<T, SIMD::use_simd<T, 4, A>::value>::map(v1, v1, s);
return v1;
}
template<IntType T, bool A>
TIntVector4<T, A> operator%=(TIntVector4<T, A>& v1, const TIntVector4<T, A>& v2)
{
Detail::compute_ivec4_mod<T, SIMD::use_simd<T, 4, A>::value>::map(v1, v1, v2);
return v1;
}
template<IntType T, bool A>
TIntVector4<T, A> operator%=(TIntVector4<T, A>& v1, T s)
{
Detail::compute_ivec4_mod<T, SIMD::use_simd<T, 4, A>::value>::map(v1, v1, s);
return v1;
}
template<IntType T, bool A>
TIntVector4<T, A> operator+(TIntVector4<T, A>& v1, const TIntVector4<T, A>& v2)
{
TIntVector4<T, A> r;
Detail::compute_ivec4_add<T, SIMD::use_simd<T, 4, A>::value>::map(r, v1, v2);
return r;
}
template<IntType T, bool A>
TIntVector4<T, A> operator+(TIntVector4<T, A>& v1, T s)
{
TIntVector4<T, A> r;
Detail::compute_ivec4_add<T, SIMD::use_simd<T, 4, A>::value>::map(r, v1, s);
return r;
}
template<IntType T, bool A>
TIntVector4<T, A> operator-(TIntVector4<T, A>& v1, const TIntVector4<T, A>& v2)
{
TIntVector4<T, A> r;
Detail::compute_ivec4_sub<T, SIMD::use_simd<T, 4, A>::value>::map(r, v1, v2);
return r;
}
template<IntType T, bool A>
TIntVector4<T, A> operator-(TIntVector4<T, A>& v1, T s)
{
TIntVector4<T, A> r;
Detail::compute_ivec4_sub<T, SIMD::use_simd<T, 4, A>::value>::map(r, v1, s);
return r;
}
template<IntType T, bool A>
TIntVector4<T, A> operator*(TIntVector4<T, A>& v1, const TIntVector4<T, A>& v2)
{
TIntVector4<T, A> r;
Detail::compute_ivec4_mul<T, SIMD::use_simd<T, 4, A>::value>::map(r, v1, v2);
return r;
}
template<IntType T, bool A>
TIntVector4<T, A> operator*(TIntVector4<T, A>& v1, T s)
{
TIntVector4<T, A> r;
Detail::compute_ivec4_mul<T, SIMD::use_simd<T, 4, A>::value>::map(r, v1, s);
return r;
}
template<IntType T, bool A>
TIntVector4<T, A> operator/(TIntVector4<T, A>& v1, const TIntVector4<T, A>& v2)
{
TIntVector4<T, A> r;
Detail::compute_ivec4_div<T, SIMD::use_simd<T, 4, A>::value>::map(r, v1, v2);
return r;
}
template<IntType T, bool A>
TIntVector4<T, A> operator/(TIntVector4<T, A>& v1, T s)
{
TIntVector4<T, A> r;
Detail::compute_ivec4_div<T, SIMD::use_simd<T, 4, A>::value>::map(r, v1, s);
return r;
}
template<IntType T, bool A>
TIntVector4<T, A> operator%(TIntVector4<T, A>& v1, const TIntVector4<T, A>& v2)
{
TIntVector4<T, A> r;
Detail::compute_ivec4_mod<T, SIMD::use_simd<T, 4, A>::value>::map(r, v1, v2);
return r;
}
template<IntType T, bool A>
TIntVector4<T, A> operator%(TIntVector4<T, A>& v1, T s)
{
TIntVector4<T, A> r;
Detail::compute_ivec4_mod<T, SIMD::use_simd<T, 4, A>::value>::map(r, v1, s);
return r;
}
// Bitwise operators
template<IntType T, bool A>
TIntVector4<T, A> operator&=(TIntVector4<T, A>& v1, const TIntVector4<T, A>& v2)
{
Detail::compute_ivec4_and<T, SIMD::use_simd<T, 4, A>::value>::map(v1, v1, v2);
return v1;
}
template<IntType T, bool A>
TIntVector4<T, A> operator&=(TIntVector4<T, A>& v1, T s)
{
Detail::compute_ivec4_and<T, SIMD::use_simd<T, 4, A>::value>::map(v1, v1, s);
return v1;
}
template<IntType T, bool A>
TIntVector4<T, A> operator|=(TIntVector4<T, A>& v1, const TIntVector4<T, A>& v2)
{
Detail::compute_ivec4_or<T, SIMD::use_simd<T, 4, A>::value>::map(v1, v1, v2);
return v1;
}
template<IntType T, bool A>
TIntVector4<T, A> operator|=(TIntVector4<T, A>& v1, T s)
{
Detail::compute_ivec4_or<T, SIMD::use_simd<T, 4, A>::value>::map(v1, v1, s);
return v1;
}
template<IntType T, bool A>
TIntVector4<T, A> operator^=(TIntVector4<T, A>& v1, const TIntVector4<T, A>& v2)
{
Detail::compute_ivec4_xor<T, SIMD::use_simd<T, 4, A>::value>::map(v1, v1, v2);
return v1;
}
template<IntType T, bool A>
TIntVector4<T, A> operator^=(TIntVector4<T, A>& v1, T s)
{
Detail::compute_ivec4_xor<T, SIMD::use_simd<T, 4, A>::value>::map(v1, v1, s);
return v1;
}
template<IntType T, bool A>
TIntVector4<T, A> operator<<=(TIntVector4<T, A>& v1, const TIntVector4<T, A>& v2)
{
Detail::compute_ivec4_left_shift<T, SIMD::use_simd<T, 4, A>::value>::map(v1, v1, v2);
return v1;
}
template<IntType T, bool A>
TIntVector4<T, A> operator<<=(TIntVector4<T, A>& v1, T s)
{
Detail::compute_ivec4_left_shift<T, SIMD::use_simd<T, 4, A>::value>::map(v1, v1, s);
return v1;
}
template<IntType T, bool A>
TIntVector4<T, A> operator>>=(TIntVector4<T, A>& v1, const TIntVector4<T, A>& v2)
{
Detail::compute_ivec4_right_shift<T, SIMD::use_simd<T, 4, A>::value>::map(v1, v1, v2);
return v1;
}
template<IntType T, bool A>
TIntVector4<T, A> operator>>=(TIntVector4<T, A>& v1, T s)
{
Detail::compute_ivec4_right_shift<T, SIMD::use_simd<T, 4, A>::value>::map(v1, v1, s);
return v1;
}
template<IntType T, bool A>
TIntVector4<T, A> operator&(TIntVector4<T, A>& v1, const TIntVector4<T, A>& v2)
{
TVector2<T, A> r;
Detail::compute_ivec4_and<T, SIMD::use_simd<T, 4, A>::value>::map(r, v1, v2);
return r;
}
template<IntType T, bool A>
TIntVector4<T, A> operator&(TIntVector4<T, A>& v1, T s)
{
TVector2<T, A> r;
Detail::compute_ivec4_and<T, SIMD::use_simd<T, 4, A>::value>::map(r, v1, s);
return r;
}
template<IntType T, bool A>
TIntVector4<T, A> operator|(TIntVector4<T, A>& v1, const TIntVector4<T, A>& v2)
{
TVector2<T, A> r;
Detail::compute_ivec4_or<T, SIMD::use_simd<T, 4, A>::value>::map(r, v1, v2);
return r;
}
template<IntType T, bool A>
TIntVector4<T, A> operator|(TIntVector4<T, A>& v1, T s)
{
TVector2<T, A> r;
Detail::compute_ivec4_or<T, SIMD::use_simd<T, 4, A>::value>::map(r, v1, s);
return r;
}
template<IntType T, bool A>
TIntVector4<T, A> operator^(TIntVector4<T, A>& v1, const TIntVector4<T, A>& v2)
{
TVector2<T, A> r;
Detail::compute_ivec4_xor<T, SIMD::use_simd<T, 4, A>::value>::map(r, v1, v2);
return r;
}
template<IntType T, bool A>
TIntVector4<T, A> operator^(TIntVector4<T, A>& v1, T s)
{
TVector2<T, A> r;
Detail::compute_ivec4_xor<T, SIMD::use_simd<T, 4, A>::value>::map(r, v1, s);
return r;
}
template<IntType T, bool A>
TIntVector4<T, A> operator<<(TIntVector4<T, A>& v1, const TIntVector4<T, A>& v2)
{
TVector2<T, A> r;
Detail::compute_ivec4_left_shift<T, SIMD::use_simd<T, 4, A>::value>::map(r, v1, v2);
return r;
}
template<IntType T, bool A>
TIntVector4<T, A> operator<<(TIntVector4<T, A>& v1, T s)
{
TVector2<T, A> r;
Detail::compute_ivec4_left_shift<T, SIMD::use_simd<T, 4, A>::value>::map(r, v1, s);
return r;
}
template<IntType T, bool A>
TIntVector4<T, A> operator>>(TIntVector4<T, A>& v1, const TIntVector4<T, A>& v2)
{
TVector2<T, A> r;
Detail::compute_ivec4_right_shift<T, SIMD::use_simd<T, 4, A>::value>::map(r, v1, v2);
return r;
}
template<IntType T, bool A>
TIntVector4<T, A> operator>>(TIntVector4<T, A>& v1, T s)
{
TVector2<T, A> r;
Detail::compute_ivec4_right_shift<T, SIMD::use_simd<T, 4, A>::value>::map(r, v1, s);
return r;
}
template<IntType T, bool A>
TIntVector4<T, A> operator~(TIntVector4<T, A>& v1)
{
TVector2<T, A> r;
Detail::compute_ivec4_bnot<T, SIMD::use_simd<T, 4, A>::value>::map(r, v1);
return r;
}
// Comparision
template<IntType T, bool A>
bool operator==(const TIntVector4<T, A>& v1, const TIntVector4<T, A>& v2)
{
return Detail::compute_ivec4_eq<T, SIMD::use_simd<T, 4, A>::value>::map(v1, v2);
}
template<IntType T, bool A>
bool operator!=(const TIntVector4<T, A>& v1, const TIntVector4<T, A>& v2)
{
return Detail::compute_ivec4_ieq<T, SIMD::use_simd<T, 4, A>::value>::map(v1, v2);
}
// Inc- / Decrement
template<IntType T, bool A>
TIntVector4<T, A>& operator++(TIntVector4<T, A>& v1)
{
Detail::compute_ivec4_inc<T, SIMD::use_simd<T, 4, A>::value>::map(v1);
return v1;
}
template<IntType T, bool A>
TIntVector4<T, A>& operator--(TIntVector4<T, A>& v1)
{
Detail::compute_ivec4_inc<T, SIMD::use_simd<T, 4, A>::value>::map(v1);
return v1;
}
template<IntType T, bool A>
TIntVector4<T, A>& operator++(TIntVector4<T, A>& v1, int)
{
return ++v1;
}
template<IntType T, bool A>
TIntVector4<T, A>& operator--(TIntVector4<T, A>& v1, int)
{
return --v1;
}
}

@ -37,29 +37,20 @@ namespace Phanes::Core::Math {
template<RealType T> struct TPoint2;
template<RealType T> struct TPoint3;
template<RealType T> struct TPoint4;
template<IntType T> struct TIntVector3;
template<IntType T> struct TIntVector4;
template<IntType T> struct TIntPoint2;
template<IntType T> struct TIntPoint3;
template<IntType T> struct TIntPoint4;
template<IntType T, bool A> struct TIntVector2;
template<RealType T, bool A> struct TVector2;
template<RealType T, bool A> struct TVector3;
template<RealType T, bool A> struct TVector4;
template<IntType T, bool A> struct TIntVector2;
template<IntType T, bool A> struct TIntVector3;
template<IntType T, bool A> struct TIntVector4;
/**
* Specific instantiation of forward declarations.
*/
// TIntVector3
typedef TIntVector3<int> IntVector3;
typedef TIntVector3<long> IntVector3l;
typedef std::vector<IntVector3> IntVector3List;
typedef std::vector<IntVector3l> IntVector3Listl;
// TMatrix2
typedef TMatrix2<float> Matrix2;
typedef TMatrix2<double> Matrix2d;

@ -494,4 +494,152 @@ namespace Phanes::Core::Math::Detail
r.comp = _mm_srl_epi64(v1.comp, _mm_set1_epi64x(s));
}
};
// =============== //
// TIntVector4 //
// =============== //
template<>
struct construct_ivec4<int, true>
{
static FORCEINLINE void map(Phanes::Core::Math::TIntVector4<int, true>& v1, const TIntVector4<int, true>& v2)
{
v1.comp = _mm_setr_epi32(v2.x, v2.y, v2.z, v2.w);
}
static FORCEINLINE void map(Phanes::Core::Math::TIntVector4<int, true>& v1, int s)
{
v1.comp = _mm_set1_epi32(s);
}
static FORCEINLINE void map(Phanes::Core::Math::TIntVector4<int, true>& v1, int x, int y, int z, int w)
{
v1.comp = _mm_setr_epi32(x, y, z, w);
}
static FORCEINLINE void map(Phanes::Core::Math::TIntVector4<int, true>& v1, const int* comp)
{
v1.comp = _mm_loadu_epi32(comp);
}
};
template<>
struct compute_ivec4_add<int, true>
{
static FORCEINLINE void map(Phanes::Core::Math::TIntVector4<int, true>& r, const Phanes::Core::Math::TIntVector4<int, true>& v1, const Phanes::Core::Math::TIntVector4<int, true>& v2)
{
r.comp = _mm_add_epi32(v1.comp, v2.comp);
}
static FORCEINLINE void map(Phanes::Core::Math::TIntVector4<int, true>& r, const Phanes::Core::Math::TIntVector4<int, true>& v1, T s)
{
r.comp = _mm_add_epi32(v1.comp, _mm_set1_epi32(s));
}
};
template<>
struct compute_ivec4_sub<int, true>
{
static FORCEINLINE void map(Phanes::Core::Math::TIntVector4<int, true>& r, const Phanes::Core::Math::TIntVector4<int, true>& v1, const Phanes::Core::Math::TIntVector4<int, true>& v2)
{
r.comp = _mm_sub_epi32(v1.comp, v2.comp);
}
static FORCEINLINE void map(Phanes::Core::Math::TIntVector4<int, true>& r, const Phanes::Core::Math::TIntVector4<int, true>& v1, T s)
{
r.comp = _mm_sub_epi32(v1.comp, _mm_set1_epi32(s));
}
};
template<>
struct compute_ivec4_inc<int, true>
{
static FORCEINLINE void map(Phanes::Core::Math::TIntVector4<int, true>& r, const Phanes::Core::Math::TIntVector4<int, true>& v1)
{
r.comp = _mm_add_epi32(v1.comp, _mm_set1_epi32(1));
}
};
template<>
struct compute_ivec4_dec<int, true>
{
static FORCEINLINE void map(Phanes::Core::Math::TIntVector4<int, true>& r, const Phanes::Core::Math::TIntVector4<int, true>& v1)
{
r.comp = _mm_sub_epi32(v1.comp, _mm_set1_epi32(1));
}
};
template<>
struct compute_ivec4_and<int, true>
{
static FORCEINLINE void map(Phanes::Core::Math::TIntVector4<int, true>& r, const Phanes::Core::Math::TIntVector4<int, true>& v1, const Phanes::Core::Math::TIntVector4<int, true>& v2)
{
r.comp = _mm_and_si128(v1.comp, v2.comp);
}
static FORCEINLINE void map(Phanes::Core::Math::TIntVector4<int, true>& r, const Phanes::Core::Math::TIntVector4<int, true>& v1, T s)
{
r.comp = _mm_and_si128(v1.comp, _mm_set1_epi32(s));
}
};
template<>
struct compute_ivec4_or<int, true>
{
static FORCEINLINE void map(Phanes::Core::Math::TIntVector4<int, true>& r, const Phanes::Core::Math::TIntVector4<int, true>& v1, const Phanes::Core::Math::TIntVector4<int, true>& v2)
{
r.comp = _mm_or_si128(v1.comp, v2.comp);
}
static FORCEINLINE void map(Phanes::Core::Math::TIntVector4<int, true>& r, const Phanes::Core::Math::TIntVector4<int, true>& v1, T s)
{
r.comp = _mm_or_si128(v1.comp, _mm_set1_epi32(s));
}
};
template<>
struct compute_ivec4_xor<int, true>
{
static FORCEINLINE void map(Phanes::Core::Math::TIntVector4<int, true>& r, const Phanes::Core::Math::TIntVector4<int, true>& v1, const Phanes::Core::Math::TIntVector4<int, true>& v2)
{
r.comp = _mm_xor_si128(v1.comp, v2.comp);
}
static FORCEINLINE void map(Phanes::Core::Math::TIntVector4<int, true>& r, const Phanes::Core::Math::TIntVector4<int, true>& v1, T s)
{
r.comp = _mm_xor_si128(v1.comp, _mm_set1_epi32(s));
}
};
template<>
struct compute_ivec4_left_shift<int, true>
{
static FORCEINLINE void map(Phanes::Core::Math::TIntVector4<int, true>& r, const Phanes::Core::Math::TIntVector4<int, true>& v1, const Phanes::Core::Math::TIntVector4<int, true>& v2)
{
r.comp = _mm_sll_epi32(v1.comp, v2.comp);
}
static FORCEINLINE void map(Phanes::Core::Math::TIntVector4<int, true>& r, const Phanes::Core::Math::TIntVector4<int, true>& v1, T s)
{
r.comp = _mm_sll_epi32(v1.comp, _mm_set1_epi32(s));
}
};
template<>
struct compute_ivec4_right_shift<int, true>
{
static FORCEINLINE void map(Phanes::Core::Math::TIntVector4<int, true>& r, const Phanes::Core::Math::TIntVector4<int, true>& v1, const Phanes::Core::Math::TIntVector4<int, true>& v2)
{
r.comp = _mm_srl_epi32(v1.comp, v2.comp);
}
static FORCEINLINE void map(Phanes::Core::Math::TIntVector4<int, true>& r, const Phanes::Core::Math::TIntVector4<int, true>& v1, T s)
{
r.comp = _mm_srl_epi32(v1.comp, _mm_set1_epi32(s));
}
};
}

@ -987,7 +987,7 @@ namespace Phanes::Core::Math {
TVector2<T, false> Normalize(const TVector2<T, false>& v1)
{
float vecNorm = Magnitude(v1);
return (vecNorm < P_FLT_INAC) ? PZeroVector2(T) : (v1 / vecNorm);
return (vecNorm < P_FLT_INAC) ? PZeroVector2(T, false) : (v1 / vecNorm);
}
/**

@ -675,7 +675,7 @@ namespace Phanes::Core::Math {
{
T magnitude = Magnitude(v1);
v1 = (magnitude > P_FLT_INAC) ? v1 / magnitude : PZeroVector3(T);
v1 = (magnitude > P_FLT_INAC) ? v1 / magnitude : PZeroVector3(T, false);
Clamp(magnitude, min, max);
@ -933,7 +933,7 @@ namespace Phanes::Core::Math {
TVector3<T, false> Normalize(const TVector3<T, false>& v1)
{
float vecNorm = Magnitude(v1);
return (vecNorm < P_FLT_INAC) ? PZeroVector3(T) : v1 / vecNorm;
return (vecNorm < P_FLT_INAC) ? PZeroVector3(T, false) : v1 / vecNorm;
}
/**
@ -1110,7 +1110,7 @@ namespace Phanes::Core::Math {
{
T magnitude = Magnitude(v1);
const TVector3<T, false> unitVec = (magnitude > P_FLT_INAC) ? v1 / magnitude : PZeroVector3(T);
const TVector3<T, false> unitVec = (magnitude > P_FLT_INAC) ? v1 / magnitude : PZeroVector3(T, false);
Clamp(magnitude, min, max);