New code style refactor

This commit is contained in:
Jack Andersen 2018-12-07 19:23:50 -10:00
parent e8dfecbb6e
commit e172225845
49 changed files with 712 additions and 1265 deletions

View File

@ -1,6 +1,6 @@
--- ---
IndentWidth: 2 BasedOnStyle: LLVM
ColumnLimit: 128 ColumnLimit: 120
UseTab: Never UseTab: Never
--- ---
Language: Cpp Language: Cpp
@ -8,7 +8,6 @@ DerivePointerAlignment: false
PointerAlignment: Left PointerAlignment: Left
AlignAfterOpenBracket: Align AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false AlignConsecutiveAssignments: false
BreakBeforeBraces: Allman
IndentCaseLabels: false IndentCaseLabels: false
AllowShortBlocksOnASingleLine: true AllowShortBlocksOnASingleLine: true
AlignOperands: true AlignOperands: true
@ -16,7 +15,6 @@ AlignTrailingComments: true
AlwaysBreakBeforeMultilineStrings: true AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: true AlwaysBreakTemplateDeclarations: true
BreakConstructorInitializersBeforeComma: true BreakConstructorInitializersBeforeComma: true
BreakStringLiterals: true
AlwaysBreakAfterReturnType: None AlwaysBreakAfterReturnType: None
AlwaysBreakAfterDefinitionReturnType: None AlwaysBreakAfterDefinitionReturnType: None
AllowShortFunctionsOnASingleLine: All AllowShortFunctionsOnASingleLine: All
@ -25,6 +23,6 @@ NamespaceIndentation: None
BinPackArguments: true BinPackArguments: true
BinPackParameters: true BinPackParameters: true
SortIncludes: false SortIncludes: false
AccessModifierOffset: -4 AccessModifierOffset: -2
ConstructorInitializerIndentWidth: 0 ConstructorInitializerIndentWidth: 0
ConstructorInitializerAllOnOneLineOrOnePerLine: true ConstructorInitializerAllOnOneLineOrOnePerLine: true

View File

@ -16,23 +16,9 @@
namespace zeus { namespace zeus {
class CAABox { class CAABox {
public: public:
enum class EBoxEdgeId { enum class EBoxEdgeId { Z0, X0, Z1, X1, Z2, X2, Z3, X3, Y0, Y1, Y2, Y3 };
Z0,
X0,
Z1,
X1,
Z2,
X2,
Z3,
X3,
Y0,
Y1,
Y2,
Y3
};
enum class EBoxFaceID { enum class EBoxFaceID {};
};
static const CAABox skInvertedBox; static const CAABox skInvertedBox;
static const CAABox skNullBox; static const CAABox skNullBox;
@ -48,8 +34,7 @@ public:
CAABox(float min, float max) : min(CVector3f(min)), max(CVector3f(max)) {} CAABox(float min, float max) : min(CVector3f(min)), max(CVector3f(max)) {}
CAABox(float minX, float minY, float minZ, float maxX, float maxY, float maxZ) CAABox(float minX, float minY, float minZ, float maxX, float maxY, float maxZ)
: min(minX, minY, minZ), max(maxX, maxY, maxZ) { : min(minX, minY, minZ), max(maxX, maxY, maxZ) {}
}
#if ZE_ATHENA_TYPES #if ZE_ATHENA_TYPES
@ -233,20 +218,17 @@ public:
} }
bool pointInside(const CVector3f& other) const { bool pointInside(const CVector3f& other) const {
return (min.x() <= other.x() && other.x() <= max.x() && return (min.x() <= other.x() && other.x() <= max.x() && min.y() <= other.y() && other.y() <= max.y() &&
min.y() <= other.y() && other.y() <= max.y() &&
min.z() <= other.z() && other.z() <= max.z()); min.z() <= other.z() && other.z() <= max.z());
} }
CVector3f closestPointAlongVector(const CVector3f& other) const { CVector3f closestPointAlongVector(const CVector3f& other) const {
return {(other.x() >= 0.f ? min.x() : max.x()), return {(other.x() >= 0.f ? min.x() : max.x()), (other.y() >= 0.f ? min.y() : max.y()),
(other.y() >= 0.f ? min.y() : max.y()),
(other.z() >= 0.f ? min.z() : max.z())}; (other.z() >= 0.f ? min.z() : max.z())};
} }
CVector3f furthestPointAlongVector(const CVector3f& other) const { CVector3f furthestPointAlongVector(const CVector3f& other) const {
return {(other.x() >= 0.f ? max.x() : min.x()), return {(other.x() >= 0.f ? max.x() : min.x()), (other.y() >= 0.f ? max.y() : min.y()),
(other.y() >= 0.f ? max.y() : min.y()),
(other.z() >= 0.f ? max.z() : min.z())}; (other.z() >= 0.f ? max.z() : min.z())};
} }
@ -368,5 +350,4 @@ inline bool operator==(const CAABox& left, const CAABox& right) {
inline bool operator!=(const CAABox& left, const CAABox& right) { inline bool operator!=(const CAABox& left, const CAABox& right) {
return (left.min != right.min || left.max != right.max); return (left.min != right.min || left.max != right.max);
} }
} } // namespace zeus

View File

@ -14,5 +14,4 @@ struct CAxisAngle : CVector3f {
const CVector3f& getVector() const { return *this; } const CVector3f& getVector() const { return *this; }
static const CAxisAngle sIdentity; static const CAxisAngle sIdentity;
}; };
} } // namespace zeus

View File

@ -18,8 +18,9 @@
#undef max #undef max
#if BYTE_ORDER == __ORDER_LITTLE_ENDIAN__ #if BYTE_ORDER == __ORDER_LITTLE_ENDIAN__
#define COLOR(rgba) \ #define COLOR(rgba) \
(unsigned)(((rgba)&0x000000FF) << 24 | ((rgba)&0x0000FF00) << 8 | ((rgba)&0x00FF0000) >> 8 | ((rgba)&0xFF000000) >> 24) (unsigned)(((rgba)&0x000000FF) << 24 | ((rgba)&0x0000FF00) << 8 | ((rgba)&0x00FF0000) >> 8 | \
((rgba)&0xFF000000) >> 24)
#else #else
#define COLOR(rgba) rgba #define COLOR(rgba) rgba
#endif #endif
@ -136,37 +137,21 @@ public:
bool operator!=(const CColor& rhs) const { return !(*this == rhs); } bool operator!=(const CColor& rhs) const { return !(*this == rhs); }
CColor operator+(const CColor& rhs) const { CColor operator+(const CColor& rhs) const { return mSimd + rhs.mSimd; }
return mSimd + rhs.mSimd;
}
CColor operator-(const CColor& rhs) const { CColor operator-(const CColor& rhs) const { return mSimd - rhs.mSimd; }
return mSimd - rhs.mSimd;
}
CColor operator*(const CColor& rhs) const { CColor operator*(const CColor& rhs) const { return mSimd * rhs.mSimd; }
return mSimd * rhs.mSimd;
}
CColor operator/(const CColor& rhs) const { CColor operator/(const CColor& rhs) const { return mSimd / rhs.mSimd; }
return mSimd / rhs.mSimd;
}
CColor operator+(float val) const { CColor operator+(float val) const { return mSimd + simd<float>(val); }
return mSimd + simd<float>(val);
}
CColor operator-(float val) const { CColor operator-(float val) const { return mSimd - simd<float>(val); }
return mSimd - simd<float>(val);
}
CColor operator*(float val) const { CColor operator*(float val) const { return mSimd * simd<float>(val); }
return mSimd * simd<float>(val);
}
CColor operator/(float val) const { CColor operator/(float val) const { return mSimd / simd<float>(val); }
return mSimd / simd<float>(val);
}
const CColor& operator+=(const CColor& rhs) { const CColor& operator+=(const CColor& rhs) {
mSimd += rhs.mSimd; mSimd += rhs.mSimd;
@ -220,9 +205,7 @@ public:
return *this * mag; return *this * mag;
} }
float magSquared() const { float magSquared() const { return mSimd.dot4(mSimd); }
return mSimd.dot4(mSimd);
}
float magnitude() const { return std::sqrt(magSquared()); } float magnitude() const { return std::sqrt(magSquared()); }
@ -247,9 +230,7 @@ public:
mSimd[3] = a; mSimd[3] = a;
} }
float rgbDot(const CColor& rhs) const { float rgbDot(const CColor& rhs) const { return mSimd.dot3(rhs.mSimd); }
return mSimd.dot3(rhs.mSimd);
}
void fromRGBA8(const Comp8 ri, const Comp8 gi, const Comp8 bi, const Comp8 ai) { void fromRGBA8(const Comp8 ri, const Comp8 gi, const Comp8 bi, const Comp8 ai) {
mSimd = simd<float>(ri * OneOver255, gi * OneOver255, bi * OneOver255, ai * OneOver255); mSimd = simd<float>(ri * OneOver255, gi * OneOver255, bi * OneOver255, ai * OneOver255);
@ -320,19 +301,11 @@ public:
simd<float>::reference a() { return mSimd[3]; } simd<float>::reference a() { return mSimd[3]; }
}; };
static inline CColor operator+(float lhs, const CColor& rhs) { static inline CColor operator+(float lhs, const CColor& rhs) { return simd<float>(lhs) + rhs.mSimd; }
return simd<float>(lhs) + rhs.mSimd;
}
static inline CColor operator-(float lhs, const CColor& rhs) { static inline CColor operator-(float lhs, const CColor& rhs) { return simd<float>(lhs) - rhs.mSimd; }
return simd<float>(lhs) - rhs.mSimd;
}
static inline CColor operator*(float lhs, const CColor& rhs) { static inline CColor operator*(float lhs, const CColor& rhs) { return simd<float>(lhs) * rhs.mSimd; }
return simd<float>(lhs) * rhs.mSimd;
}
static inline CColor operator/(float lhs, const CColor& rhs) { static inline CColor operator/(float lhs, const CColor& rhs) { return simd<float>(lhs) / rhs.mSimd; }
return simd<float>(lhs) / rhs.mSimd; } // namespace zeus
}
}

View File

@ -12,5 +12,4 @@ public:
CEulerAngles(const CTransform& xf); CEulerAngles(const CTransform& xf);
}; };
} } // namespace zeus

View File

@ -16,4 +16,4 @@ public:
bool sphereFrustumTest(const CSphere& sphere) const; bool sphereFrustumTest(const CSphere& sphere) const;
bool pointFrustumTest(const CVector3f& point) const; bool pointFrustumTest(const CVector3f& point) const;
}; };
} } // namespace zeus

View File

@ -11,5 +11,4 @@ public:
CVector3f origin; CVector3f origin;
CVector3f dir; CVector3f dir;
}; };
} } // namespace zeus

View File

@ -18,5 +18,4 @@ public:
CVector3f xc_dir; CVector3f xc_dir;
CVector3f x18_end; CVector3f x18_end;
}; };
} } // namespace zeus

View File

@ -7,13 +7,13 @@
namespace zeus { namespace zeus {
struct CMRay { struct CMRay {
CMRay(const CVector3f& start, const CVector3f& dirin, float len) CMRay(const CVector3f& start, const CVector3f& dirin, float len)
: start(start), length(len), invLength(1.f / len), dir(dirin) { : start(start), length(len), invLength(1.f / len), dir(dirin) {
end = start + (len * dirin); end = start + (len * dirin);
delta = end - start; delta = end - start;
} }
CMRay(const CVector3f& start, const CVector3f& end, float len, float invLen) CMRay(const CVector3f& start, const CVector3f& end, float len, float invLen)
: start(start), end(end), length(len), invLength(invLen) { : start(start), end(end), length(len), invLength(invLen) {
delta = end - start; delta = end - start;
dir = invLen * delta; dir = invLen * delta;
} }
@ -24,11 +24,10 @@ struct CMRay {
} }
CVector3f start; // x0 CVector3f start; // x0
CVector3f end; // xc CVector3f end; // xc
CVector3f delta; // x18 CVector3f delta; // x18
float length; // x24 float length; // x24
float invLength; // x28 float invLength; // x28
CVector3f dir; // x2c CVector3f dir; // x2c
}; };
} } // namespace zeus

View File

@ -11,7 +11,6 @@ class CQuaternion;
class CMatrix3f { class CMatrix3f {
public: public:
explicit CMatrix3f(bool zero = false) { explicit CMatrix3f(bool zero = false) {
m[0] = simd<float>(0.f); m[0] = simd<float>(0.f);
m[1] = simd<float>(0.f); m[1] = simd<float>(0.f);
@ -23,12 +22,8 @@ public:
} }
} }
CMatrix3f(float m00, float m01, float m02, CMatrix3f(float m00, float m01, float m02, float m10, float m11, float m12, float m20, float m21, float m22)
float m10, float m11, float m12, : m{{m00, m10, m20}, {m01, m11, m21}, {m02, m12, m22}} {}
float m20, float m21, float m22)
: m{{m00, m10, m20},
{m01, m11, m21},
{m02, m12, m22}} {}
CMatrix3f(const CVector3f& scaleVec) { CMatrix3f(const CVector3f& scaleVec) {
m[0] = simd<float>(0.f); m[0] = simd<float>(0.f);
@ -99,8 +94,7 @@ public:
} }
CVector3f operator*(const CVector3f& other) const { CVector3f operator*(const CVector3f& other) const {
return m[0].mSimd * other.mSimd.shuffle<0, 0, 0, 0>() + return m[0].mSimd * other.mSimd.shuffle<0, 0, 0, 0>() + m[1].mSimd * other.mSimd.shuffle<1, 1, 1, 1>() +
m[1].mSimd * other.mSimd.shuffle<1, 1, 1, 1>() +
m[2].mSimd * other.mSimd.shuffle<2, 2, 2, 2>(); m[2].mSimd * other.mSimd.shuffle<2, 2, 2, 2>();
} }
@ -147,32 +141,27 @@ public:
static CMatrix3f RotateX(float theta) { static CMatrix3f RotateX(float theta) {
float sinT = std::sin(theta); float sinT = std::sin(theta);
float cosT = std::cos(theta); float cosT = std::cos(theta);
return CMatrix3f(simd<float>{1.f, 0.f, 0.f, 0.f}, return CMatrix3f(simd<float>{1.f, 0.f, 0.f, 0.f}, simd<float>{0.f, cosT, sinT, 0.f},
simd<float>{0.f, cosT, sinT, 0.f},
simd<float>{0.f, -sinT, cosT, 0.f}); simd<float>{0.f, -sinT, cosT, 0.f});
} }
static CMatrix3f RotateY(float theta) { static CMatrix3f RotateY(float theta) {
float sinT = std::sin(theta); float sinT = std::sin(theta);
float cosT = std::cos(theta); float cosT = std::cos(theta);
return CMatrix3f(simd<float>{cosT, 0.f, -sinT, 0.f}, return CMatrix3f(simd<float>{cosT, 0.f, -sinT, 0.f}, simd<float>{0.f, 1.f, 0.f, 0.f},
simd<float>{0.f, 1.f, 0.f, 0.f},
simd<float>{sinT, 0.f, cosT, 0.f}); simd<float>{sinT, 0.f, cosT, 0.f});
} }
static CMatrix3f RotateZ(float theta) { static CMatrix3f RotateZ(float theta) {
float sinT = std::sin(theta); float sinT = std::sin(theta);
float cosT = std::cos(theta); float cosT = std::cos(theta);
return CMatrix3f(simd<float>{cosT, sinT, 0.f, 0.f}, return CMatrix3f(simd<float>{cosT, sinT, 0.f, 0.f}, simd<float>{-sinT, cosT, 0.f, 0.f},
simd<float>{-sinT, cosT, 0.f, 0.f},
simd<float>{0.f, 0.f, 1.f, 0.f}); simd<float>{0.f, 0.f, 1.f, 0.f});
} }
float determinant() const { float determinant() const {
return return m[1][0] * (m[2][1] * m[0][2] - m[0][1] * m[2][2]) + m[0][0] * (m[1][1] * m[2][2] - m[2][1] * m[1][2]) +
m[1][0] * (m[2][1] * m[0][2] - m[0][1] * m[2][2]) + m[2][0] * (m[0][1] * m[1][2] - m[1][1] * m[0][2]);
m[0][0] * (m[1][1] * m[2][2] - m[2][1] * m[1][2]) +
m[2][0] * (m[0][1] * m[1][2] - m[1][1] * m[0][2]);
} }
CVector3f m[3]; CVector3f m[3];
@ -181,10 +170,8 @@ public:
static inline CMatrix3f operator*(const CMatrix3f& lhs, const CMatrix3f& rhs) { static inline CMatrix3f operator*(const CMatrix3f& lhs, const CMatrix3f& rhs) {
simd<float> v[3]; simd<float> v[3];
for (int i = 0; i < 3; ++i) for (int i = 0; i < 3; ++i)
v[i] = lhs.m[0].mSimd * rhs[i].mSimd.shuffle<0, 0, 0, 0>() + v[i] = lhs.m[0].mSimd * rhs[i].mSimd.shuffle<0, 0, 0, 0>() + lhs.m[1].mSimd * rhs[i].mSimd.shuffle<1, 1, 1, 1>() +
lhs.m[1].mSimd * rhs[i].mSimd.shuffle<1, 1, 1, 1>() +
lhs.m[2].mSimd * rhs[i].mSimd.shuffle<2, 2, 2, 2>(); lhs.m[2].mSimd * rhs[i].mSimd.shuffle<2, 2, 2, 2>();
return CMatrix3f(v[0], v[1], v[2]); return CMatrix3f(v[0], v[1], v[2]);
} }
} } // namespace zeus

View File

@ -18,14 +18,9 @@ public:
} }
} }
CMatrix4f(float m00, float m01, float m02, float m03, CMatrix4f(float m00, float m01, float m02, float m03, float m10, float m11, float m12, float m13, float m20,
float m10, float m11, float m12, float m13, float m21, float m22, float m23, float m30, float m31, float m32, float m33)
float m20, float m21, float m22, float m23, : m{{m00, m10, m20, m30}, {m01, m11, m21, m31}, {m02, m12, m22, m32}, {m03, m13, m23, m33}} {}
float m30, float m31, float m32, float m33)
: m{{m00, m10, m20, m30},
{m01, m11, m21, m31},
{m02, m12, m22, m32},
{m03, m13, m23, m33}} {}
CMatrix4f(const CVector3f& scaleVec) { CMatrix4f(const CVector3f& scaleVec) {
m[0][0] = scaleVec[0]; m[0][0] = scaleVec[0];
@ -47,7 +42,7 @@ public:
m[2] = other.m[2]; m[2] = other.m[2];
m[3] = other.m[3]; m[3] = other.m[3];
} }
CMatrix4f(const simd<float>& r0, const simd<float>& r1, const simd<float>& r2, const simd<float>& r3) { CMatrix4f(const simd<float>& r0, const simd<float>& r1, const simd<float>& r2, const simd<float>& r3) {
m[0].mSimd = r0; m[0].mSimd = r0;
m[1].mSimd = r1; m[1].mSimd = r1;
@ -71,10 +66,8 @@ public:
} }
CVector4f operator*(const CVector4f& other) const { CVector4f operator*(const CVector4f& other) const {
return m[0].mSimd * other.mSimd.shuffle<0, 0, 0, 0>() + return m[0].mSimd * other.mSimd.shuffle<0, 0, 0, 0>() + m[1].mSimd * other.mSimd.shuffle<1, 1, 1, 1>() +
m[1].mSimd * other.mSimd.shuffle<1, 1, 1, 1>() + m[2].mSimd * other.mSimd.shuffle<2, 2, 2, 2>() + m[3].mSimd * other.mSimd.shuffle<3, 3, 3, 3>();
m[2].mSimd * other.mSimd.shuffle<2, 2, 2, 2>() +
m[3].mSimd * other.mSimd.shuffle<3, 3, 3, 3>();
} }
CVector4f& operator[](size_t i) { CVector4f& operator[](size_t i) {
@ -106,11 +99,8 @@ public:
static inline CMatrix4f operator*(const CMatrix4f& lhs, const CMatrix4f& rhs) { static inline CMatrix4f operator*(const CMatrix4f& lhs, const CMatrix4f& rhs) {
simd<float> v[4]; simd<float> v[4];
for (int i = 0; i < 4; ++i) for (int i = 0; i < 4; ++i)
v[i] = lhs.m[0].mSimd * rhs[i].mSimd.shuffle<0, 0, 0, 0>() + v[i] = lhs.m[0].mSimd * rhs[i].mSimd.shuffle<0, 0, 0, 0>() + lhs.m[1].mSimd * rhs[i].mSimd.shuffle<1, 1, 1, 1>() +
lhs.m[1].mSimd * rhs[i].mSimd.shuffle<1, 1, 1, 1>() + lhs.m[2].mSimd * rhs[i].mSimd.shuffle<2, 2, 2, 2>() + lhs.m[3].mSimd * rhs[i].mSimd.shuffle<3, 3, 3, 3>();
lhs.m[2].mSimd * rhs[i].mSimd.shuffle<2, 2, 2, 2>() +
lhs.m[3].mSimd * rhs[i].mSimd.shuffle<3, 3, 3, 3>();
return CMatrix4f(v[0], v[1], v[2], v[3]); return CMatrix4f(v[0], v[1], v[2], v[3]);
} }
} } // namespace zeus

View File

@ -42,9 +42,6 @@ public:
bool OBBIntersectsBox(const COBBox& other) const; bool OBBIntersectsBox(const COBBox& other) const;
bool AABoxIntersectsBox(const CAABox& other) { bool AABoxIntersectsBox(const CAABox& other) { return OBBIntersectsBox(FromAABox(other, CTransform::Identity())); }
return OBBIntersectsBox(FromAABox(other, CTransform::Identity()));
}
}; };
} } // namespace zeus

View File

@ -36,9 +36,7 @@ public:
mSimd[3] = nd * mag; mSimd[3] = nd * mag;
} }
float pointToPlaneDist(const CVector3f& pos) const { float pointToPlaneDist(const CVector3f& pos) const { return pos.dot(normal()) - d(); }
return pos.dot(normal()) - d();
}
bool rayPlaneIntersection(const CVector3f& from, const CVector3f& to, CVector3f& point) const; bool rayPlaneIntersection(const CVector3f& from, const CVector3f& to, CVector3f& point) const;
@ -66,5 +64,4 @@ public:
zeus::simd<float> mSimd; zeus::simd<float> mSimd;
}; };
} } // namespace zeus

View File

@ -7,11 +7,7 @@
#include <cmath> #include <cmath>
namespace zeus { namespace zeus {
enum class EProjType { enum class EProjType { None = 0, Orthographic = 1, Perspective = 2 };
None = 0,
Orthographic = 1,
Perspective = 2
};
class SProjOrtho { class SProjOrtho {
public: public:
@ -19,16 +15,14 @@ public:
explicit SProjOrtho(float p_top = 1.0f, float p_bottom = -1.0f, float p_left = -1.0f, float p_right = 1.0f, explicit SProjOrtho(float p_top = 1.0f, float p_bottom = -1.0f, float p_left = -1.0f, float p_right = 1.0f,
float p_near = 1.0f, float p_far = -1.0f) float p_near = 1.0f, float p_far = -1.0f)
: top(p_top), bottom(p_bottom), left(p_left), right(p_right), znear(p_near), zfar(p_far) { : top(p_top), bottom(p_bottom), left(p_left), right(p_right), znear(p_near), zfar(p_far) {}
}
}; };
struct SProjPersp { struct SProjPersp {
float fov, aspect, znear, zfar; float fov, aspect, znear, zfar;
SProjPersp(float p_fov = degToRad(55.0f), float p_aspect = 1.0f, float p_near = 0.1f, float p_far = 4096.f) SProjPersp(float p_fov = degToRad(55.0f), float p_aspect = 1.0f, float p_near = 0.1f, float p_far = 4096.f)
: fov(p_fov), aspect(p_aspect), znear(p_near), zfar(p_far) { : fov(p_fov), aspect(p_aspect), znear(p_near), zfar(p_far) {}
}
}; };
extern const SProjOrtho kOrthoIdentity; extern const SProjOrtho kOrthoIdentity;
@ -101,13 +95,11 @@ protected:
/* Projection intermediate */ /* Projection intermediate */
union { union {
#ifdef _MSC_VER #ifdef _MSC_VER
struct struct {
{ SProjOrtho m_ortho;
SProjOrtho m_ortho;
}; };
struct struct {
{ SProjPersp m_persp;
SProjPersp m_persp;
}; };
#else #else
SProjOrtho m_ortho; SProjOrtho m_ortho;
@ -118,5 +110,4 @@ protected:
/* Cached projection matrix */ /* Cached projection matrix */
CMatrix4f m_mtx; CMatrix4f m_mtx;
}; };
} } // namespace zeus

View File

@ -37,9 +37,7 @@ public:
CQuaternion(float xi, float yi, float zi) { fromVector3f(CVector3f(xi, yi, zi)); } CQuaternion(float xi, float yi, float zi) { fromVector3f(CVector3f(xi, yi, zi)); }
CQuaternion(float wi, const CVector3f& vec) : mSimd(vec.mSimd.shuffle<0, 0, 1, 2>()) { CQuaternion(float wi, const CVector3f& vec) : mSimd(vec.mSimd.shuffle<0, 0, 1, 2>()) { mSimd[0] = wi; }
mSimd[0] = wi;
}
template <typename T> template <typename T>
CQuaternion(const simd<T>& s) : mSimd(s) {} CQuaternion(const simd<T>& s) : mSimd(s) {}
@ -57,13 +55,9 @@ public:
CQuaternion(const atVec4f& vec) : mSimd(vec.simd) {} CQuaternion(const atVec4f& vec) : mSimd(vec.simd) {}
operator atVec4f&() { operator atVec4f&() { return *reinterpret_cast<atVec4f*>(this); }
return *reinterpret_cast<atVec4f*>(this);
}
operator const atVec4f&() const { operator const atVec4f&() const { return *reinterpret_cast<const atVec4f*>(this); }
return *reinterpret_cast<const atVec4f*>(this);
}
#endif #endif
@ -158,9 +152,7 @@ public:
CTransform toTransform(const zeus::CVector3f& origin) const { return CTransform(CMatrix3f(*this), origin); } CTransform toTransform(const zeus::CVector3f& origin) const { return CTransform(CMatrix3f(*this), origin); }
float dot(const CQuaternion& rhs) const { float dot(const CQuaternion& rhs) const { return mSimd.dot4(rhs.mSimd); }
return mSimd.dot4(rhs.mSimd);
}
static CQuaternion lerp(const CQuaternion& a, const CQuaternion& b, double t); static CQuaternion lerp(const CQuaternion& a, const CQuaternion& b, double t);
@ -177,7 +169,7 @@ public:
float roll() const { float roll() const {
simd_floats f(mSimd); simd_floats f(mSimd);
return std::atan2(2.f * (f[1] * f[2] + f[0] * f[3]), f[0] * f[0] + f[1] * f[1] - f[2] * f[2] - f[3] * f[3]); return std::asin(-2.f * (f[1] * f[3] - f[0] * f[2]));
} }
float pitch() const { float pitch() const {
@ -187,7 +179,7 @@ public:
float yaw() const { float yaw() const {
simd_floats f(mSimd); simd_floats f(mSimd);
return std::asin(-2.f * (f[1] * f[3] - f[0] * f[2])); return std::atan2(2.f * (f[1] * f[2] + f[0] * f[3]), f[0] * f[0] + f[1] * f[1] - f[2] * f[2] - f[3] * f[3]);
} }
CQuaternion buildEquivalent() const; CQuaternion buildEquivalent() const;
@ -238,9 +230,7 @@ public:
CNUQuaternion(float wi, float xi, float yi, float zi) : mSimd(wi, xi, yi, zi) {} CNUQuaternion(float wi, float xi, float yi, float zi) : mSimd(wi, xi, yi, zi) {}
CNUQuaternion(float win, const zeus::CVector3f& vec) : mSimd(vec.mSimd.shuffle<0, 0, 1, 2>()) { CNUQuaternion(float win, const zeus::CVector3f& vec) : mSimd(vec.mSimd.shuffle<0, 0, 1, 2>()) { w() = win; }
w() = win;
}
CNUQuaternion(const CQuaternion& other) : mSimd(other.mSimd) {} CNUQuaternion(const CQuaternion& other) : mSimd(other.mSimd) {}
@ -307,4 +297,4 @@ CQuaternion operator-(float lhs, const CQuaternion& rhs);
CQuaternion operator*(float lhs, const CQuaternion& rhs); CQuaternion operator*(float lhs, const CQuaternion& rhs);
CNUQuaternion operator*(float lhs, const CNUQuaternion& rhs); CNUQuaternion operator*(float lhs, const CNUQuaternion& rhs);
} } // namespace zeus

View File

@ -26,5 +26,4 @@ public:
CVector2f position; CVector2f position;
CVector2f size; CVector2f size;
}; };
} } // namespace zeus

View File

@ -91,5 +91,4 @@ struct CRelAngle {
return *this; return *this;
} }
}; };
} } // namespace zeus

View File

@ -17,5 +17,4 @@ public:
CVector3f position; CVector3f position;
float radius; float radius;
}; };
} } // namespace zeus

View File

@ -13,14 +13,12 @@ class CTransform {
public: public:
CTransform() : basis(false) {} CTransform() : basis(false) {}
CTransform(const CMatrix3f& basis, const CVector3f& offset = CVector3f::skZero) CTransform(const CMatrix3f& basis, const CVector3f& offset = CVector3f::skZero) : basis(basis), origin(offset) {}
: basis(basis), origin(offset) {}
#if ZE_ATHENA_TYPES #if ZE_ATHENA_TYPES
CTransform(const atVec4f* mtx) CTransform(const atVec4f* mtx)
: basis(mtx[0], mtx[1], mtx[2]) : basis(mtx[0], mtx[1], mtx[2]), origin(mtx[0].simd[3], mtx[1].simd[3], mtx[2].simd[3]) {}
, origin(mtx[0].simd[3], mtx[1].simd[3], mtx[2].simd[3]) {}
void read34RowMajor(athena::io::IStreamReader& r) { void read34RowMajor(athena::io::IStreamReader& r) {
atVec4f r0 = r.readVec4fBig(); atVec4f r0 = r.readVec4fBig();
@ -37,13 +35,9 @@ public:
CTransform(const CVector3f& c0, const CVector3f& c1, const CVector3f& c2, const CVector3f& c3) CTransform(const CVector3f& c0, const CVector3f& c1, const CVector3f& c2, const CVector3f& c3)
: basis(c0, c1, c2), origin(c3) {} : basis(c0, c1, c2), origin(c3) {}
static CTransform Identity() { static CTransform Identity() { return CTransform(CMatrix3f::skIdentityMatrix3f); }
return CTransform(CMatrix3f::skIdentityMatrix3f);
}
bool operator==(const CTransform& other) const { bool operator==(const CTransform& other) const { return origin == other.origin && basis == other.basis; }
return origin == other.origin && basis == other.basis;
}
CTransform operator*(const CTransform& rhs) const { CTransform operator*(const CTransform& rhs) const {
return CTransform(basis * rhs.basis, origin + (basis * rhs.origin)); return CTransform(basis * rhs.basis, origin + (basis * rhs.origin));
@ -54,57 +48,44 @@ public:
return CTransform(inv, inv * -origin); return CTransform(inv, inv * -origin);
} }
static CTransform Translate(const CVector3f& position) { static CTransform Translate(const CVector3f& position) { return {CMatrix3f::skIdentityMatrix3f, position}; }
return {CMatrix3f::skIdentityMatrix3f, position};
}
static CTransform Translate(float x, float y, float z) { static CTransform Translate(float x, float y, float z) { return Translate({x, y, z}); }
return Translate({x, y, z});
}
CTransform operator+(const CVector3f& other) { CTransform operator+(const CVector3f& other) { return CTransform(basis, origin + other); }
return CTransform(basis, origin + other);
}
CTransform& operator+=(const CVector3f& other) { CTransform& operator+=(const CVector3f& other) {
origin += other; origin += other;
return *this; return *this;
} }
CTransform operator-(const CVector3f& other) { CTransform operator-(const CVector3f& other) { return CTransform(basis, origin - other); }
return CTransform(basis, origin - other);
}
CTransform& operator-=(const CVector3f& other) { CTransform& operator-=(const CVector3f& other) {
origin -= other; origin -= other;
return *this; return *this;
} }
zeus::CVector3f rotate(const CVector3f& vec) const { zeus::CVector3f rotate(const CVector3f& vec) const { return basis * vec; }
return basis * vec;
}
static CTransform RotateX(float theta) { static CTransform RotateX(float theta) {
float sinT = std::sin(theta); float sinT = std::sin(theta);
float cosT = std::cos(theta); float cosT = std::cos(theta);
return CTransform(CMatrix3f(simd<float>{1.f, 0.f, 0.f, 0.f}, return CTransform(CMatrix3f(simd<float>{1.f, 0.f, 0.f, 0.f}, simd<float>{0.f, cosT, sinT, 0.f},
simd<float>{0.f, cosT, sinT, 0.f},
simd<float>{0.f, -sinT, cosT, 0.f})); simd<float>{0.f, -sinT, cosT, 0.f}));
} }
static CTransform RotateY(float theta) { static CTransform RotateY(float theta) {
float sinT = std::sin(theta); float sinT = std::sin(theta);
float cosT = std::cos(theta); float cosT = std::cos(theta);
return CTransform(CMatrix3f(simd<float>{cosT, 0.f, -sinT, 0.f}, return CTransform(CMatrix3f(simd<float>{cosT, 0.f, -sinT, 0.f}, simd<float>{0.f, 1.f, 0.f, 0.f},
simd<float>{0.f, 1.f, 0.f, 0.f},
simd<float>{sinT, 0.f, cosT, 0.f})); simd<float>{sinT, 0.f, cosT, 0.f}));
} }
static CTransform RotateZ(float theta) { static CTransform RotateZ(float theta) {
float sinT = std::sin(theta); float sinT = std::sin(theta);
float cosT = std::cos(theta); float cosT = std::cos(theta);
return CTransform(CMatrix3f(simd<float>{cosT, sinT, 0.f, 0.f}, return CTransform(CMatrix3f(simd<float>{cosT, sinT, 0.f, 0.f}, simd<float>{-sinT, cosT, 0.f, 0.f},
simd<float>{-sinT, cosT, 0.f, 0.f},
simd<float>{0.f, 0.f, 1.f, 0.f})); simd<float>{0.f, 0.f, 1.f, 0.f}));
} }
@ -163,20 +144,17 @@ public:
} }
static CTransform Scale(const CVector3f& factor) { static CTransform Scale(const CVector3f& factor) {
return CTransform(CMatrix3f(simd<float>{factor.x(), 0.f, 0.f, 0.f}, return CTransform(CMatrix3f(simd<float>{factor.x(), 0.f, 0.f, 0.f}, simd<float>{0.f, factor.y(), 0.f, 0.f},
simd<float>{0.f, factor.y(), 0.f, 0.f},
simd<float>{0.f, 0.f, factor.z(), 0.f})); simd<float>{0.f, 0.f, factor.z(), 0.f}));
} }
static CTransform Scale(float x, float y, float z) { static CTransform Scale(float x, float y, float z) {
return CTransform(CMatrix3f(simd<float>{x, 0.f, 0.f, 0.f}, return CTransform(
simd<float>{0.f, y, 0.f, 0.f}, CMatrix3f(simd<float>{x, 0.f, 0.f, 0.f}, simd<float>{0.f, y, 0.f, 0.f}, simd<float>{0.f, 0.f, z, 0.f}));
simd<float>{0.f, 0.f, z, 0.f}));
} }
static CTransform Scale(float factor) { static CTransform Scale(float factor) {
return CTransform(CMatrix3f(simd<float>{factor, 0.f, 0.f, 0.f}, return CTransform(CMatrix3f(simd<float>{factor, 0.f, 0.f, 0.f}, simd<float>{0.f, factor, 0.f, 0.f},
simd<float>{0.f, factor, 0.f, 0.f},
simd<float>{0.f, 0.f, factor, 0.f})); simd<float>{0.f, 0.f, factor, 0.f}));
} }
@ -192,26 +170,18 @@ public:
return ret; return ret;
} }
void setRotation(const CMatrix3f& mat) { void setRotation(const CMatrix3f& mat) { basis = mat; }
basis = mat;
}
void setRotation(const CTransform& xfrm) { void setRotation(const CTransform& xfrm) { setRotation(xfrm.basis); }
setRotation(xfrm.basis);
}
/** /**
* @brief buildMatrix3f Returns the stored matrix * @brief buildMatrix3f Returns the stored matrix
* buildMatrix3f is here for compliance with Retro's Math API * buildMatrix3f is here for compliance with Retro's Math API
* @return The Matrix (Neo, you are the one) * @return The Matrix (Neo, you are the one)
*/ */
const CMatrix3f& buildMatrix3f() const { const CMatrix3f& buildMatrix3f() const { return basis; }
return basis;
}
CVector3f operator*(const CVector3f& other) const { CVector3f operator*(const CVector3f& other) const { return origin + basis * other; }
return origin + basis * other;
}
CMatrix4f toMatrix4f() const { CMatrix4f toMatrix4f() const {
CMatrix4f ret(basis[0], basis[1], basis[2], origin); CMatrix4f ret(basis[0], basis[1], basis[2], origin);
@ -222,17 +192,11 @@ public:
return ret; return ret;
} }
CVector3f upVector() const { CVector3f upVector() const { return basis.m[2]; }
return basis.m[2];
}
CVector3f frontVector() const { CVector3f frontVector() const { return basis.m[1]; }
return basis.m[1];
}
CVector3f rightVector() const { CVector3f rightVector() const { return basis.m[0]; }
return basis.m[0];
}
void orthonormalize() { void orthonormalize() {
basis[0].normalize(); basis[0].normalize();
@ -242,14 +206,13 @@ public:
} }
void printMatrix() const { void printMatrix() const {
printf("%f %f %f %f\n" printf(
"%f %f %f %f\n" "%f %f %f %f\n"
"%f %f %f %f\n" "%f %f %f %f\n"
"%f %f %f %f\n", "%f %f %f %f\n"
basis[0][0], basis[1][0], basis[2][0], origin[0], "%f %f %f %f\n",
basis[0][1], basis[1][1], basis[2][1], origin[1], basis[0][0], basis[1][0], basis[2][0], origin[0], basis[0][1], basis[1][1], basis[2][1], origin[1], basis[0][2],
basis[0][2], basis[1][2], basis[2][2], origin[2], basis[1][2], basis[2][2], origin[2], 0.f, 0.f, 0.f, 1.f);
0.f, 0.f, 0.f, 1.f);
} }
static zeus::CTransform MakeRotationsBasedOnY(const CUnitVector3f& uVec) { static zeus::CTransform MakeRotationsBasedOnY(const CUnitVector3f& uVec) {
@ -269,9 +232,7 @@ public:
CVector3f origin; CVector3f origin;
}; };
static inline CTransform CTransformFromScaleVector(const CVector3f& scale) { static inline CTransform CTransformFromScaleVector(const CVector3f& scale) { return CTransform(CMatrix3f(scale)); }
return CTransform(CMatrix3f(scale));
}
CTransform CTransformFromEditorEuler(const CVector3f& eulerVec); CTransform CTransformFromEditorEuler(const CVector3f& eulerVec);
@ -280,5 +241,4 @@ CTransform CTransformFromEditorEulers(const CVector3f& eulerVec, const CVector3f
CTransform CTransformFromAxisAngle(const CVector3f& axis, float angle); CTransform CTransformFromAxisAngle(const CVector3f& axis, float angle);
CTransform lookAt(const CVector3f& pos, const CVector3f& lookPos, const CVector3f& up = CVector3f::skUp); CTransform lookAt(const CVector3f& pos, const CVector3f& lookPos, const CVector3f& up = CVector3f::skUp);
} } // namespace zeus

View File

@ -17,4 +17,4 @@ public:
normalize(); normalize();
} }
}; };
} } // namespace zeus

View File

@ -13,18 +13,14 @@ public:
template <typename T> template <typename T>
CVector2f(const simd<T>& s) : mSimd(s) {} CVector2f(const simd<T>& s) : mSimd(s) {}
#if ZE_ATHENA_TYPES #if ZE_ATHENA_TYPES
CVector2f(const atVec2f& vec) : mSimd(vec.simd) {} CVector2f(const atVec2f& vec) : mSimd(vec.simd) {}
operator atVec2f&() { operator atVec2f&() { return *reinterpret_cast<atVec2f*>(this); }
return *reinterpret_cast<atVec2f*>(this);
}
operator const atVec2f&() const { operator const atVec2f&() const { return *reinterpret_cast<const atVec2f*>(this); }
return *reinterpret_cast<const atVec2f*>(this);
}
void readBig(athena::io::IStreamReader& input) { void readBig(athena::io::IStreamReader& input) {
mSimd[0] = input.readFloatBig(); mSimd[0] = input.readFloatBig();
@ -52,61 +48,33 @@ public:
CVector2f(float x, float y) { assign(x, y); } CVector2f(float x, float y) { assign(x, y); }
bool operator==(const CVector2f& rhs) const { bool operator==(const CVector2f& rhs) const { return mSimd[0] == rhs.mSimd[0] && mSimd[1] == rhs.mSimd[1]; }
return mSimd[0] == rhs.mSimd[0] && mSimd[1] == rhs.mSimd[1];
}
bool operator!=(const CVector2f& rhs) const { bool operator!=(const CVector2f& rhs) const { return mSimd[0] != rhs.mSimd[0] || mSimd[1] != rhs.mSimd[1]; }
return mSimd[0] != rhs.mSimd[0] || mSimd[1] != rhs.mSimd[1];
}
bool operator<(const CVector2f& rhs) const { bool operator<(const CVector2f& rhs) const { return mSimd[0] < rhs.mSimd[0] && mSimd[1] < rhs.mSimd[1]; }
return mSimd[0] < rhs.mSimd[0] && mSimd[1] < rhs.mSimd[1];
}
bool operator<=(const CVector2f& rhs) const { bool operator<=(const CVector2f& rhs) const { return mSimd[0] <= rhs.mSimd[0] && mSimd[1] <= rhs.mSimd[1]; }
return mSimd[0] <= rhs.mSimd[0] && mSimd[1] <= rhs.mSimd[1];
}
bool operator>(const CVector2f& rhs) const { bool operator>(const CVector2f& rhs) const { return mSimd[0] > rhs.mSimd[0] && mSimd[1] > rhs.mSimd[1]; }
return mSimd[0] > rhs.mSimd[0] && mSimd[1] > rhs.mSimd[1];
}
bool operator>=(const CVector2f& rhs) const { bool operator>=(const CVector2f& rhs) const { return mSimd[0] >= rhs.mSimd[0] && mSimd[1] >= rhs.mSimd[1]; }
return mSimd[0] >= rhs.mSimd[0] && mSimd[1] >= rhs.mSimd[1];
}
CVector2f operator+(const CVector2f& rhs) const { CVector2f operator+(const CVector2f& rhs) const { return mSimd + rhs.mSimd; }
return mSimd + rhs.mSimd;
}
CVector2f operator-(const CVector2f& rhs) const { CVector2f operator-(const CVector2f& rhs) const { return mSimd - rhs.mSimd; }
return mSimd - rhs.mSimd;
}
CVector2f operator-() const { CVector2f operator-() const { return -mSimd; }
return -mSimd;
}
CVector2f operator*(const CVector2f& rhs) const { CVector2f operator*(const CVector2f& rhs) const { return mSimd * rhs.mSimd; }
return mSimd * rhs.mSimd;
}
CVector2f operator/(const CVector2f& rhs) const { CVector2f operator/(const CVector2f& rhs) const { return mSimd / rhs.mSimd; }
return mSimd / rhs.mSimd;
}
CVector2f operator+(float val) const { CVector2f operator+(float val) const { return mSimd + simd<float>(val); }
return mSimd + simd<float>(val);
}
CVector2f operator-(float val) const { CVector2f operator-(float val) const { return mSimd - simd<float>(val); }
return mSimd - simd<float>(val);
}
CVector2f operator*(float val) const { CVector2f operator*(float val) const { return mSimd * simd<float>(val); }
return mSimd * simd<float>(val);
}
CVector2f operator/(float val) const { CVector2f operator/(float val) const {
float ooval = 1.f / val; float ooval = 1.f / val;
@ -170,25 +138,15 @@ public:
float cross(const CVector2f& rhs) const { return (x() * rhs.y()) - (y() * rhs.x()); } float cross(const CVector2f& rhs) const { return (x() * rhs.y()) - (y() * rhs.x()); }
float dot(const CVector2f& rhs) const { float dot(const CVector2f& rhs) const { return mSimd.dot2(rhs.mSimd); }
return mSimd.dot2(rhs.mSimd);
}
float magSquared() const { float magSquared() const { return mSimd.dot2(mSimd); }
return mSimd.dot2(mSimd);
}
float magnitude() const { float magnitude() const { return std::sqrt(magSquared()); }
return std::sqrt(magSquared());
}
void zeroOut() { void zeroOut() { *this = CVector2f::skZero; }
*this = CVector2f::skZero;
}
void splat(float xy) { void splat(float xy) { mSimd = zeus::simd<float>(xy); }
mSimd = zeus::simd<float>(xy);
}
static float getAngleDiff(const CVector2f& a, const CVector2f& b); static float getAngleDiff(const CVector2f& a, const CVector2f& b);
@ -196,15 +154,11 @@ public:
return zeus::simd<float>(1.f - t) * a.mSimd + b.mSimd * zeus::simd<float>(t); return zeus::simd<float>(1.f - t) * a.mSimd + b.mSimd * zeus::simd<float>(t);
} }
static CVector2f nlerp(const CVector2f& a, const CVector2f& b, float t) { static CVector2f nlerp(const CVector2f& a, const CVector2f& b, float t) { return lerp(a, b, t).normalized(); }
return lerp(a, b, t).normalized();
}
static CVector2f slerp(const CVector2f& a, const CVector2f& b, float t); static CVector2f slerp(const CVector2f& a, const CVector2f& b, float t);
bool isNormalized() const { bool isNormalized() const { return std::fabs(1.f - magSquared()) < 0.01f; }
return std::fabs(1.f - magSquared()) < 0.01f;
}
bool canBeNormalized() const { bool canBeNormalized() const {
if (std::isinf(x()) || std::isinf(y())) if (std::isinf(x()) || std::isinf(y()))
@ -212,9 +166,7 @@ public:
return std::fabs(x()) >= FLT_EPSILON || std::fabs(y()) >= FLT_EPSILON; return std::fabs(x()) >= FLT_EPSILON || std::fabs(y()) >= FLT_EPSILON;
} }
bool isZero() const { bool isZero() const { return magSquared() <= FLT_EPSILON; }
return magSquared() <= FLT_EPSILON;
}
bool isEqu(const CVector2f& other, float epsilon = FLT_EPSILON) { bool isEqu(const CVector2f& other, float epsilon = FLT_EPSILON) {
const CVector2f diffVec = other - *this; const CVector2f diffVec = other - *this;
@ -242,20 +194,11 @@ public:
static const CVector2f skZero; static const CVector2f skZero;
}; };
static inline CVector2f operator+(float lhs, const CVector2f& rhs) { static inline CVector2f operator+(float lhs, const CVector2f& rhs) { return zeus::simd<float>(lhs) + rhs.mSimd; }
return zeus::simd<float>(lhs) + rhs.mSimd;
}
static inline CVector2f operator-(float lhs, const CVector2f& rhs) { static inline CVector2f operator-(float lhs, const CVector2f& rhs) { return zeus::simd<float>(lhs) - rhs.mSimd; }
return zeus::simd<float>(lhs) - rhs.mSimd;
}
static inline CVector2f operator*(float lhs, const CVector2f& rhs) { static inline CVector2f operator*(float lhs, const CVector2f& rhs) { return zeus::simd<float>(lhs) * rhs.mSimd; }
return zeus::simd<float>(lhs) * rhs.mSimd;
}
static inline CVector2f operator/(float lhs, const CVector2f& rhs) {
return zeus::simd<float>(lhs) / rhs.mSimd;
}
}
static inline CVector2f operator/(float lhs, const CVector2f& rhs) { return zeus::simd<float>(lhs) / rhs.mSimd; }
} // namespace zeus

View File

@ -29,33 +29,18 @@ public:
CVector2f toVec2f() const { return CVector2f(x, y); } CVector2f toVec2f() const { return CVector2f(x, y); }
CVector2i operator+(const CVector2i& val) const { CVector2i operator+(const CVector2i& val) const { return CVector2i(x + val.x, y + val.y); }
return CVector2i(x + val.x, y + val.y);
}
CVector2i operator-(const CVector2i& val) const { CVector2i operator-(const CVector2i& val) const { return CVector2i(x - val.x, y - val.y); }
return CVector2i(x - val.x, y - val.y);
}
CVector2i operator*(const CVector2i& val) const { CVector2i operator*(const CVector2i& val) const { return CVector2i(x * val.x, y * val.y); }
return CVector2i(x * val.x, y * val.y);
}
CVector2i operator/(const CVector2i& val) const { CVector2i operator/(const CVector2i& val) const { return CVector2i(x / val.x, y / val.y); }
return CVector2i(x / val.x, y / val.y);
}
bool operator==(const CVector2i& other) const { bool operator==(const CVector2i& other) const { return x == other.x && y == other.y; }
return x == other.x && y == other.y;
}
bool operator!=(const CVector2i& other) const { bool operator!=(const CVector2i& other) const { return x != other.x || y != other.y; }
return x != other.x || y != other.y;
}
CVector2i operator*(int val) const { CVector2i operator*(int val) const { return CVector2i(x * val, y * val); }
return CVector2i(x * val, y * val);
}
}; };
} } // namespace zeus

View File

@ -14,7 +14,7 @@ public:
template <typename T> template <typename T>
CVector3d(const simd<T>& s) : mSimd(s) {} CVector3d(const simd<T>& s) : mSimd(s) {}
#if ZE_ATHENA_TYPES #if ZE_ATHENA_TYPES
CVector3d(const atVec3d& vec) : mSimd(vec.simd) {} CVector3d(const atVec3d& vec) : mSimd(vec.simd) {}
#endif #endif
@ -25,27 +25,17 @@ public:
CVector3d(double x, double y, double z) : mSimd(x, y, z) {} CVector3d(double x, double y, double z) : mSimd(x, y, z) {}
CVector3f asCVector3f() { CVector3f asCVector3f() { return mSimd; }
return mSimd;
}
double magSquared() const { double magSquared() const { return mSimd.dot3(mSimd); }
return mSimd.dot3(mSimd);
}
double magnitude() const { double magnitude() const { return sqrt(magSquared()); }
return sqrt(magSquared());
}
CVector3d cross(const CVector3d& rhs) const { CVector3d cross(const CVector3d& rhs) const {
return {y() * rhs.z() - z() * rhs.y(), return {y() * rhs.z() - z() * rhs.y(), z() * rhs.x() - x() * rhs.z(), x() * rhs.y() - y() * rhs.x()};
z() * rhs.x() - x() * rhs.z(),
x() * rhs.y() - y() * rhs.x()};
} }
double dot(const CVector3d& rhs) const { double dot(const CVector3d& rhs) const { return mSimd.dot3(rhs.mSimd); }
return mSimd.dot3(rhs.mSimd);
}
CVector3d asNormalized() { CVector3d asNormalized() {
double mag = magnitude(); double mag = magnitude();
@ -53,29 +43,17 @@ public:
return mSimd * zeus::simd<double>(mag); return mSimd * zeus::simd<double>(mag);
} }
void splat(double xyz) { void splat(double xyz) { mSimd = zeus::simd<double>(xyz); }
mSimd = zeus::simd<double>(xyz);
}
void zeroOut() { void zeroOut() { *this = skZero; }
*this = skZero;
}
CVector3d operator+(const CVector3d& rhs) const { CVector3d operator+(const CVector3d& rhs) const { return mSimd + rhs.mSimd; }
return mSimd + rhs.mSimd;
}
CVector3d operator-(const CVector3d& rhs) const { CVector3d operator-(const CVector3d& rhs) const { return mSimd - rhs.mSimd; }
return mSimd - rhs.mSimd;
}
CVector3d operator*(const CVector3d& rhs) const { CVector3d operator*(const CVector3d& rhs) const { return mSimd * rhs.mSimd; }
return mSimd * rhs.mSimd;
}
CVector3d operator/(const CVector3d& rhs) const { CVector3d operator/(const CVector3d& rhs) const { return mSimd / rhs.mSimd; }
return mSimd / rhs.mSimd;
}
zeus::simd<double>::reference operator[](size_t idx) { zeus::simd<double>::reference operator[](size_t idx) {
assert(idx < 3); assert(idx < 3);
@ -98,21 +76,12 @@ public:
static const CVector3d skZero; static const CVector3d skZero;
}; };
static inline CVector3d operator+(double lhs, const CVector3d& rhs) { static inline CVector3d operator+(double lhs, const CVector3d& rhs) { return zeus::simd<double>(lhs) + rhs.mSimd; }
return zeus::simd<double>(lhs) + rhs.mSimd;
}
static inline CVector3d operator-(double lhs, const CVector3d& rhs) { static inline CVector3d operator-(double lhs, const CVector3d& rhs) { return zeus::simd<double>(lhs) - rhs.mSimd; }
return zeus::simd<double>(lhs) - rhs.mSimd;
}
static inline CVector3d operator*(double lhs, const CVector3d& rhs) { static inline CVector3d operator*(double lhs, const CVector3d& rhs) { return zeus::simd<double>(lhs) * rhs.mSimd; }
return zeus::simd<double>(lhs) * rhs.mSimd;
}
static inline CVector3d operator/(double lhs, const CVector3d& rhs) { static inline CVector3d operator/(double lhs, const CVector3d& rhs) { return zeus::simd<double>(lhs) / rhs.mSimd; }
return zeus::simd<double>(lhs) / rhs.mSimd;
}
}
} // namespace zeus

View File

@ -23,13 +23,9 @@ public:
CVector3f(const atVec3f& vec) : mSimd(vec.simd) {} CVector3f(const atVec3f& vec) : mSimd(vec.simd) {}
operator atVec3f&() { operator atVec3f&() { return *reinterpret_cast<atVec3f*>(this); }
return *reinterpret_cast<atVec3f*>(this);
}
operator const atVec3f&() const { operator const atVec3f&() const { return *reinterpret_cast<const atVec3f*>(this); }
return *reinterpret_cast<const atVec3f*>(this);
}
void readBig(athena::io::IStreamReader& input) { void readBig(athena::io::IStreamReader& input) {
simd_floats f; simd_floats f;
@ -52,9 +48,7 @@ public:
explicit CVector3f(float xyz) : mSimd(xyz) {} explicit CVector3f(float xyz) : mSimd(xyz) {}
void assign(float x, float y, float z) { void assign(float x, float y, float z) { mSimd = zeus::simd<float>(x, y, z); }
mSimd = zeus::simd<float>(x, y, z);
}
CVector3f(float x, float y, float z) : mSimd(x, y, z) {} CVector3f(float x, float y, float z) : mSimd(x, y, z) {}
@ -66,9 +60,7 @@ public:
mSimd[3] = 0.0f; mSimd[3] = 0.0f;
} }
CVector2f toVec2f() const { CVector2f toVec2f() const { return CVector2f(mSimd); }
return CVector2f(mSimd);
}
bool operator==(const CVector3f& rhs) const { bool operator==(const CVector3f& rhs) const {
return mSimd[0] == rhs.mSimd[0] && mSimd[1] == rhs.mSimd[1] && mSimd[2] == rhs.mSimd[2]; return mSimd[0] == rhs.mSimd[0] && mSimd[1] == rhs.mSimd[1] && mSimd[2] == rhs.mSimd[2];
@ -76,37 +68,21 @@ public:
bool operator!=(const CVector3f& rhs) const { return !(*this == rhs); } bool operator!=(const CVector3f& rhs) const { return !(*this == rhs); }
CVector3f operator+(const CVector3f& rhs) const { CVector3f operator+(const CVector3f& rhs) const { return mSimd + rhs.mSimd; }
return mSimd + rhs.mSimd;
}
CVector3f operator-(const CVector3f& rhs) const { CVector3f operator-(const CVector3f& rhs) const { return mSimd - rhs.mSimd; }
return mSimd - rhs.mSimd;
}
CVector3f operator-() const { CVector3f operator-() const { return -mSimd; }
return -mSimd;
}
CVector3f operator*(const CVector3f& rhs) const { CVector3f operator*(const CVector3f& rhs) const { return mSimd * rhs.mSimd; }
return mSimd * rhs.mSimd;
}
CVector3f operator/(const CVector3f& rhs) const { CVector3f operator/(const CVector3f& rhs) const { return mSimd / rhs.mSimd; }
return mSimd / rhs.mSimd;
}
CVector3f operator+(float val) const { CVector3f operator+(float val) const { return mSimd + zeus::simd<float>(val); }
return mSimd + zeus::simd<float>(val);
}
CVector3f operator-(float val) const { CVector3f operator-(float val) const { return mSimd - zeus::simd<float>(val); }
return mSimd - zeus::simd<float>(val);
}
CVector3f operator*(float val) const { CVector3f operator*(float val) const { return mSimd * zeus::simd<float>(val); }
return mSimd * zeus::simd<float>(val);
}
CVector3f operator/(float val) const { CVector3f operator/(float val) const {
float ooval = 1.f / val; float ooval = 1.f / val;
@ -144,38 +120,22 @@ public:
} }
CVector3f cross(const CVector3f& rhs) const { CVector3f cross(const CVector3f& rhs) const {
return CVector3f(y() * rhs.z() - z() * rhs.y(), return CVector3f(y() * rhs.z() - z() * rhs.y(), z() * rhs.x() - x() * rhs.z(), x() * rhs.y() - y() * rhs.x());
z() * rhs.x() - x() * rhs.z(),
x() * rhs.y() - y() * rhs.x());
} }
float dot(const CVector3f& rhs) const { float dot(const CVector3f& rhs) const { return mSimd.dot3(rhs.mSimd); }
return mSimd.dot3(rhs.mSimd);
}
float magSquared() const { float magSquared() const { return mSimd.dot3(mSimd); }
return mSimd.dot3(mSimd);
}
float magnitude() const { float magnitude() const { return std::sqrt(magSquared()); }
return std::sqrt(magSquared());
}
bool isNotInf() const { bool isNotInf() const { return !(std::isinf(x()) || std::isinf(y()) || std::isinf(z())); }
return !(std::isinf(x()) || std::isinf(y()) || std::isinf(z()));
}
bool isMagnitudeSafe() const { bool isMagnitudeSafe() const { return isNotInf() && magSquared() >= 9.9999994e-29; }
return isNotInf() && magSquared() >= 9.9999994e-29;
}
void zeroOut() { void zeroOut() { *this = CVector3f::skZero; }
*this = CVector3f::skZero;
}
void splat(float xyz) { void splat(float xyz) { mSimd = zeus::simd<float>(xyz); }
mSimd = zeus::simd<float>(xyz);
}
static float getAngleDiff(const CVector3f& a, const CVector3f& b); static float getAngleDiff(const CVector3f& a, const CVector3f& b);
@ -183,15 +143,11 @@ public:
return zeus::simd<float>(1.f - t) * a.mSimd + b.mSimd * zeus::simd<float>(t); return zeus::simd<float>(1.f - t) * a.mSimd + b.mSimd * zeus::simd<float>(t);
} }
static CVector3f nlerp(const CVector3f& a, const CVector3f& b, float t) { static CVector3f nlerp(const CVector3f& a, const CVector3f& b, float t) { return lerp(a, b, t).normalized(); }
return lerp(a, b, t).normalized();
}
static CVector3f slerp(const CVector3f& a, const CVector3f& b, float t); static CVector3f slerp(const CVector3f& a, const CVector3f& b, float t);
bool isNormalized() const { bool isNormalized() const { return std::fabs(1.f - magSquared()) < 0.01f; }
return std::fabs(1.f - magSquared()) < 0.01f;
}
bool canBeNormalized() const { bool canBeNormalized() const {
if (std::isinf(x()) || std::isinf(y()) || std::isinf(z())) if (std::isinf(x()) || std::isinf(y()) || std::isinf(z()))
@ -199,9 +155,7 @@ public:
return std::fabs(x()) >= FLT_EPSILON || std::fabs(y()) >= FLT_EPSILON || std::fabs(z()) >= FLT_EPSILON; return std::fabs(x()) >= FLT_EPSILON || std::fabs(y()) >= FLT_EPSILON || std::fabs(z()) >= FLT_EPSILON;
} }
bool isZero() const { bool isZero() const { return magSquared() <= FLT_EPSILON; }
return magSquared() <= FLT_EPSILON;
}
void scaleToLength(float newLength) { void scaleToLength(float newLength) {
float length = magSquared(); float length = magSquared();
@ -261,21 +215,12 @@ public:
static CVector3f degToRad(const CVector3f& deg) { return deg * skDegToRadVec; } static CVector3f degToRad(const CVector3f& deg) { return deg * skDegToRadVec; }
}; };
static inline CVector3f operator+(float lhs, const CVector3f& rhs) { static inline CVector3f operator+(float lhs, const CVector3f& rhs) { return zeus::simd<float>(lhs) + rhs.mSimd; }
return zeus::simd<float>(lhs) + rhs.mSimd;
}
static inline CVector3f operator-(float lhs, const CVector3f& rhs) { static inline CVector3f operator-(float lhs, const CVector3f& rhs) { return zeus::simd<float>(lhs) - rhs.mSimd; }
return zeus::simd<float>(lhs) - rhs.mSimd;
}
static inline CVector3f operator*(float lhs, const CVector3f& rhs) { static inline CVector3f operator*(float lhs, const CVector3f& rhs) { return zeus::simd<float>(lhs) * rhs.mSimd; }
return zeus::simd<float>(lhs) * rhs.mSimd;
}
static inline CVector3f operator/(float lhs, const CVector3f& rhs) { static inline CVector3f operator/(float lhs, const CVector3f& rhs) { return zeus::simd<float>(lhs) / rhs.mSimd; }
return zeus::simd<float>(lhs) / rhs.mSimd;
}
}
} // namespace zeus

View File

@ -29,13 +29,9 @@ public:
CVector4f(const atVec4f& vec) : mSimd(vec.simd) {} CVector4f(const atVec4f& vec) : mSimd(vec.simd) {}
operator atVec4f&() { operator atVec4f&() { return *reinterpret_cast<atVec4f*>(this); }
return *reinterpret_cast<atVec4f*>(this);
}
operator const atVec4f&() const { operator const atVec4f&() const { return *reinterpret_cast<const atVec4f*>(this); }
return *reinterpret_cast<const atVec4f*>(this);
}
void readBig(athena::io::IStreamReader& input) { void readBig(athena::io::IStreamReader& input) {
simd_floats f; simd_floats f;
@ -50,25 +46,17 @@ public:
explicit CVector4f(float xyzw) : mSimd(xyzw) {} explicit CVector4f(float xyzw) : mSimd(xyzw) {}
void assign(float x, float y, float z, float w) { void assign(float x, float y, float z, float w) { mSimd = simd<float>(x, y, z, w); }
mSimd = simd<float>(x, y, z, w);
}
CVector4f(float x, float y, float z, float w) : mSimd(x, y, z, w) {} CVector4f(float x, float y, float z, float w) : mSimd(x, y, z, w) {}
CVector4f(const CColor& other); CVector4f(const CColor& other);
CVector4f(const CVector3f& other, float wIn = 1.f) : mSimd(other.mSimd) { CVector4f(const CVector3f& other, float wIn = 1.f) : mSimd(other.mSimd) { mSimd[3] = wIn; }
mSimd[3] = wIn;
}
static CVector4f ToClip(const zeus::CVector3f& v, float w) { static CVector4f ToClip(const zeus::CVector3f& v, float w) { return CVector4f(v * w, w); }
return CVector4f(v * w, w);
}
CVector3f toVec3f() const { CVector3f toVec3f() const { return CVector3f(mSimd); }
return CVector3f(mSimd);
}
CVector4f& operator=(const CColor& other); CVector4f& operator=(const CColor& other);
@ -102,37 +90,21 @@ public:
return eq_mask[0] && eq_mask[1] && eq_mask[2] && eq_mask[3]; return eq_mask[0] && eq_mask[1] && eq_mask[2] && eq_mask[3];
} }
CVector4f operator+(const CVector4f& rhs) const { CVector4f operator+(const CVector4f& rhs) const { return mSimd + rhs.mSimd; }
return mSimd + rhs.mSimd;
}
CVector4f operator-(const CVector4f& rhs) const { CVector4f operator-(const CVector4f& rhs) const { return mSimd - rhs.mSimd; }
return mSimd - rhs.mSimd;
}
CVector4f operator-() const { CVector4f operator-() const { return -mSimd; }
return -mSimd;
}
CVector4f operator*(const CVector4f& rhs) const { CVector4f operator*(const CVector4f& rhs) const { return mSimd * rhs.mSimd; }
return mSimd * rhs.mSimd;
}
CVector4f operator/(const CVector4f& rhs) const { CVector4f operator/(const CVector4f& rhs) const { return mSimd / rhs.mSimd; }
return mSimd / rhs.mSimd;
}
CVector4f operator+(float val) const { CVector4f operator+(float val) const { return mSimd + zeus::simd<float>(val); }
return mSimd + zeus::simd<float>(val);
}
CVector4f operator-(float val) const { CVector4f operator-(float val) const { return mSimd - zeus::simd<float>(val); }
return mSimd - zeus::simd<float>(val);
}
CVector4f operator*(float val) const { CVector4f operator*(float val) const { return mSimd * zeus::simd<float>(val); }
return mSimd * zeus::simd<float>(val);
}
CVector4f operator/(float val) const { CVector4f operator/(float val) const {
float ooval = 1.f / val; float ooval = 1.f / val;
@ -171,49 +143,34 @@ public:
return *this * mag; return *this * mag;
} }
float dot(const CVector4f& rhs) const { float dot(const CVector4f& rhs) const { return mSimd.dot4(rhs.mSimd); }
return mSimd.dot4(rhs.mSimd);
}
float magSquared() const { float magSquared() const { return mSimd.dot4(mSimd); }
return mSimd.dot4(mSimd);
}
float magnitude() const { float magnitude() const { return std::sqrt(magSquared()); }
return std::sqrt(magSquared());
}
void zeroOut() { void zeroOut() { *this = CVector4f::skZero; }
*this = CVector4f::skZero;
}
void splat(float xyzw) { void splat(float xyzw) { mSimd = zeus::simd<float>(xyzw); }
mSimd = zeus::simd<float>(xyzw);
}
static CVector4f lerp(const CVector4f& a, const CVector4f& b, float t) { static CVector4f lerp(const CVector4f& a, const CVector4f& b, float t) {
return zeus::simd<float>(1.f - t) * a.mSimd + b.mSimd * zeus::simd<float>(t); return zeus::simd<float>(1.f - t) * a.mSimd + b.mSimd * zeus::simd<float>(t);
} }
static CVector4f nlerp(const CVector4f& a, const CVector4f& b, float t) { static CVector4f nlerp(const CVector4f& a, const CVector4f& b, float t) { return lerp(a, b, t).normalized(); }
return lerp(a, b, t).normalized();
}
bool isNormalized() const { bool isNormalized() const { return std::fabs(1.f - magSquared()) < 0.01f; }
return std::fabs(1.f - magSquared()) < 0.01f;
}
bool canBeNormalized() const { bool canBeNormalized() const {
if (std::isinf(x()) || std::isinf(y()) || std::isinf(z()) || std::isinf(w())) if (std::isinf(x()) || std::isinf(y()) || std::isinf(z()) || std::isinf(w()))
return false; return false;
return std::fabs(x()) >= FLT_EPSILON || std::fabs(y()) >= FLT_EPSILON || return std::fabs(x()) >= FLT_EPSILON || std::fabs(y()) >= FLT_EPSILON || std::fabs(z()) >= FLT_EPSILON ||
std::fabs(z()) >= FLT_EPSILON || std::fabs(w()) >= FLT_EPSILON; std::fabs(w()) >= FLT_EPSILON;
} }
bool isEqu(const CVector4f& other, float epsilon = FLT_EPSILON) { bool isEqu(const CVector4f& other, float epsilon = FLT_EPSILON) {
const CVector4f diffVec = other - *this; const CVector4f diffVec = other - *this;
return (diffVec.x() <= epsilon && diffVec.y() <= epsilon && return (diffVec.x() <= epsilon && diffVec.y() <= epsilon && diffVec.z() <= epsilon && diffVec.w() <= epsilon);
diffVec.z() <= epsilon && diffVec.w() <= epsilon);
} }
zeus::simd<float>::reference operator[](size_t idx) { zeus::simd<float>::reference operator[](size_t idx) {
@ -241,21 +198,12 @@ public:
static const CVector4f skZero; static const CVector4f skZero;
}; };
static CVector4f operator+(float lhs, const CVector4f& rhs) { static CVector4f operator+(float lhs, const CVector4f& rhs) { return zeus::simd<float>(lhs) + rhs.mSimd; }
return zeus::simd<float>(lhs) + rhs.mSimd;
}
static CVector4f operator-(float lhs, const CVector4f& rhs) { static CVector4f operator-(float lhs, const CVector4f& rhs) { return zeus::simd<float>(lhs) - rhs.mSimd; }
return zeus::simd<float>(lhs) - rhs.mSimd;
}
static CVector4f operator*(float lhs, const CVector4f& rhs) { static CVector4f operator*(float lhs, const CVector4f& rhs) { return zeus::simd<float>(lhs) * rhs.mSimd; }
return zeus::simd<float>(lhs) * rhs.mSimd;
}
static CVector4f operator/(float lhs, const CVector4f& rhs) { static CVector4f operator/(float lhs, const CVector4f& rhs) { return zeus::simd<float>(lhs) / rhs.mSimd; }
return zeus::simd<float>(lhs) / rhs.mSimd;
}
}
} // namespace zeus

View File

@ -9,12 +9,12 @@
namespace zeus { namespace zeus {
#if ZE_ATHENA_TYPES #if ZE_ATHENA_TYPES
template<typename T> using simd = athena::simd<T>; template <typename T>
using simd = athena::simd<T>;
using simd_floats = athena::simd_floats; using simd_floats = athena::simd_floats;
using simd_doubles = athena::simd_doubles; using simd_doubles = athena::simd_doubles;
#endif #endif
} } // namespace zeus
inline int rotr(int x, int n) { return ((x >> n) | (x << (32 - n))); } inline int rotr(int x, int n) { return ((x >> n) | (x << (32 - n))); }
inline int rotl(int x, int n) { return ((x << n) | (x >> (32 - n))); } inline int rotl(int x, int n) { return ((x << n) | (x >> (32 - n))); }

View File

@ -21,7 +21,7 @@
#undef M_SQRT2 #undef M_SQRT2
#define M_SQRT2 1.41421356237309504880 /* sqrt(2) */ #define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
#undef M_SQRT1_2 #undef M_SQRT1_2
#define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */ #define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
#define M_SQRT1_2F 0.70710678118654752440f /* 1/sqrt(2) */ #define M_SQRT1_2F 0.70710678118654752440f /* 1/sqrt(2) */
#include <cmath> #include <cmath>
@ -80,23 +80,23 @@ class CVector2f;
class CTransform; class CTransform;
template<typename T> template <typename T>
inline constexpr T min(const T& a, const T& b) { inline constexpr T min(const T& a, const T& b) {
return a < b ? a : b; return a < b ? a : b;
} }
template<typename T> template <typename T>
inline constexpr T max(const T& a, const T& b) { inline constexpr T max(const T& a, const T& b) {
return a > b ? a : b; return a > b ? a : b;
} }
template<> template <>
CVector3f min(const CVector3f& a, const CVector3f& b); CVector3f min(const CVector3f& a, const CVector3f& b);
template<> template <>
CVector3f max(const CVector3f& a, const CVector3f& b); CVector3f max(const CVector3f& a, const CVector3f& b);
template<typename T> template <typename T>
inline constexpr T clamp(const T& a, const T& val, const T& b) { inline constexpr T clamp(const T& a, const T& val, const T& b) {
return max<T>(a, min<T>(b, val)); return max<T>(a, min<T>(b, val));
} }
@ -115,8 +115,8 @@ CVector3f getBezierPoint(const CVector3f& a, const CVector3f& b, const CVector3f
float getCatmullRomSplinePoint(float a, float b, float c, float d, float t); float getCatmullRomSplinePoint(float a, float b, float c, float d, float t);
CVector3f CVector3f getCatmullRomSplinePoint(const CVector3f& a, const CVector3f& b, const CVector3f& c, const CVector3f& d,
getCatmullRomSplinePoint(const CVector3f& a, const CVector3f& b, const CVector3f& c, const CVector3f& d, float t); float t);
CVector3f getRoundCatmullRomSplinePoint(const CVector3f& a, const CVector3f& b, const CVector3f& c, const CVector3f& d, CVector3f getRoundCatmullRomSplinePoint(const CVector3f& a, const CVector3f& b, const CVector3f& c, const CVector3f& d,
float t); float t);
@ -135,7 +135,7 @@ int floorPowerOfTwo(int x);
int ceilingPowerOfTwo(int x); int ceilingPowerOfTwo(int x);
template<typename U> template <typename U>
typename std::enable_if<!std::is_enum<U>::value && std::is_integral<U>::value, int>::type PopCount(U x) { typename std::enable_if<!std::is_enum<U>::value && std::is_integral<U>::value, int>::type PopCount(U x) {
#if __GNUC__ >= 4 #if __GNUC__ >= 4
return __builtin_popcountll(x); return __builtin_popcountll(x);
@ -152,12 +152,11 @@ typename std::enable_if<!std::is_enum<U>::value && std::is_integral<U>::value, i
#endif #endif
} }
template<typename E> template <typename E>
typename std::enable_if<std::is_enum<E>::value, int>::type PopCount(E e) { typename std::enable_if<std::is_enum<E>::value, int>::type PopCount(E e) {
return PopCount(static_cast<typename std::underlying_type<E>::type>(e)); return PopCount(static_cast<typename std::underlying_type<E>::type>(e));
} }
bool close_enough(const CVector3f& a, const CVector3f& b, float epsilon = 0.000099999997f); bool close_enough(const CVector3f& a, const CVector3f& b, float epsilon = 0.000099999997f);
bool close_enough(const CVector2f& a, const CVector2f& b, float epsilon = 0.000099999997f); bool close_enough(const CVector2f& a, const CVector2f& b, float epsilon = 0.000099999997f);
@ -169,5 +168,4 @@ inline bool close_enough(float a, float b, double epsilon = 0.000009999999747378
inline bool close_enough(double a, double b, double epsilon = 0.000009999999747378752) { inline bool close_enough(double a, double b, double epsilon = 0.000009999999747378752) {
return std::fabs(a - b) < epsilon; return std::fabs(a - b) < epsilon;
} }
} } // namespace zeus

View File

@ -688,21 +688,16 @@ class __simd_storage<_Tp, __simd_abi<_StorageKind::_Scalar, 1>> {
public: public:
_Tp __get(size_t __index) const noexcept { return (&__storage_)[__index]; }; _Tp __get(size_t __index) const noexcept { return (&__storage_)[__index]; };
void __set(size_t __index, _Tp __val) noexcept { void __set(size_t __index, _Tp __val) noexcept { (&__storage_)[__index] = __val; }
(&__storage_)[__index] = __val;
}
}; };
#ifndef _LIBCPP_HAS_NO_VECTOR_EXTENSION #ifndef _LIBCPP_HAS_NO_VECTOR_EXTENSION
constexpr size_t __floor_pow_of_2(size_t __val) { constexpr size_t __floor_pow_of_2(size_t __val) {
return ((__val - 1) & __val) == 0 ? __val return ((__val - 1) & __val) == 0 ? __val : __floor_pow_of_2((__val - 1) & __val);
: __floor_pow_of_2((__val - 1) & __val);
} }
constexpr size_t __ceil_pow_of_2(size_t __val) { constexpr size_t __ceil_pow_of_2(size_t __val) { return __val == 1 ? 1 : __floor_pow_of_2(__val - 1) << 1; }
return __val == 1 ? 1 : __floor_pow_of_2(__val - 1) << 1;
}
template <class _Tp, size_t __bytes> template <class _Tp, size_t __bytes>
struct __vec_ext_traits { struct __vec_ext_traits {
@ -712,45 +707,44 @@ struct __vec_ext_traits {
}; };
#if defined(_LIBCPP_COMPILER_CLANG) #if defined(_LIBCPP_COMPILER_CLANG)
#define _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, _NUM_ELEMENT) \ #define _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, _NUM_ELEMENT) \
template <> \ template <> \
struct __vec_ext_traits<_TYPE, sizeof(_TYPE) * _NUM_ELEMENT> { \ struct __vec_ext_traits<_TYPE, sizeof(_TYPE) * _NUM_ELEMENT> { \
using type = \ using type = _TYPE __attribute__((vector_size(sizeof(_TYPE) * _NUM_ELEMENT))); \
_TYPE __attribute__((vector_size(sizeof(_TYPE) * _NUM_ELEMENT))); \
} }
#define _LIBCPP_SPECIALIZE_VEC_EXT_32(_TYPE) \ #define _LIBCPP_SPECIALIZE_VEC_EXT_32(_TYPE) \
_LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 1); \ _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 1); \
_LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 2); \ _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 2); \
_LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 3); \ _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 3); \
_LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 4); \ _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 4); \
_LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 5); \ _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 5); \
_LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 6); \ _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 6); \
_LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 7); \ _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 7); \
_LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 8); \ _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 8); \
_LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 9); \ _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 9); \
_LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 10); \ _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 10); \
_LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 11); \ _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 11); \
_LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 12); \ _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 12); \
_LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 13); \ _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 13); \
_LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 14); \ _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 14); \
_LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 15); \ _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 15); \
_LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 16); \ _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 16); \
_LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 17); \ _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 17); \
_LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 18); \ _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 18); \
_LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 19); \ _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 19); \
_LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 20); \ _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 20); \
_LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 21); \ _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 21); \
_LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 22); \ _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 22); \
_LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 23); \ _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 23); \
_LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 24); \ _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 24); \
_LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 25); \ _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 25); \
_LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 26); \ _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 26); \
_LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 27); \ _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 27); \
_LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 28); \ _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 28); \
_LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 29); \ _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 29); \
_LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 30); \ _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 30); \
_LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 31); \ _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 31); \
_LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 32); _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, 32);
_LIBCPP_SPECIALIZE_VEC_EXT_32(char); _LIBCPP_SPECIALIZE_VEC_EXT_32(char);
@ -777,8 +771,7 @@ _LIBCPP_SPECIALIZE_VEC_EXT_32(long double);
template <class _Tp, int __num_element> template <class _Tp, int __num_element>
class __simd_storage<_Tp, __simd_abi<_StorageKind::_VecExt, __num_element>> { class __simd_storage<_Tp, __simd_abi<_StorageKind::_VecExt, __num_element>> {
using _StorageType = using _StorageType = typename __vec_ext_traits<_Tp, sizeof(_Tp) * __num_element>::type;
typename __vec_ext_traits<_Tp, sizeof(_Tp) * __num_element>::type;
_StorageType __storage_; _StorageType __storage_;
@ -790,9 +783,7 @@ class __simd_storage<_Tp, __simd_abi<_StorageKind::_VecExt, __num_element>> {
public: public:
_Tp __get(size_t __index) const noexcept { return __storage_[__index]; }; _Tp __get(size_t __index) const noexcept { return __storage_[__index]; };
void __set(size_t __index, _Tp __val) noexcept { void __set(size_t __index, _Tp __val) noexcept { __storage_[__index] = __val; }
__storage_[__index] = __val;
}
}; };
#endif // _LIBCPP_HAS_NO_VECTOR_EXTENSION #endif // _LIBCPP_HAS_NO_VECTOR_EXTENSION
@ -810,8 +801,7 @@ class __simd_reference {
__simd_storage<_Tp, _Abi>* __ptr_; __simd_storage<_Tp, _Abi>* __ptr_;
size_t __index_; size_t __index_;
__simd_reference(__simd_storage<_Tp, _Abi>* __ptr, size_t __index) __simd_reference(__simd_storage<_Tp, _Abi>* __ptr, size_t __index) : __ptr_(__ptr), __index_(__index) {}
: __ptr_(__ptr), __index_(__index) {}
__simd_reference(const __simd_reference&) = default; __simd_reference(const __simd_reference&) = default;
@ -826,9 +816,7 @@ public:
return *this; return *this;
} }
__simd_reference operator++() && { __simd_reference operator++() && { return std::move(*this) = __ptr_->__get(__index_) + 1; }
return std::move(*this) = __ptr_->__get(__index_) + 1;
}
_Vp operator++(int) && { _Vp operator++(int) && {
auto __val = __ptr_->__get(__index_); auto __val = __ptr_->__get(__index_);
@ -836,9 +824,7 @@ public:
return __val; return __val;
} }
__simd_reference operator--() && { __simd_reference operator--() && { return std::move(*this) = __ptr_->__get(__index_) - 1; }
return std::move(*this) = __ptr_->__get(__index_) - 1;
}
_Vp operator--(int) && { _Vp operator--(int) && {
auto __val = __ptr_->__get(__index_); auto __val = __ptr_->__get(__index_);
@ -846,69 +832,37 @@ public:
return __val; return __val;
} }
__simd_reference operator+=(_Vp __value) && { __simd_reference operator+=(_Vp __value) && { return std::move(*this) = __ptr_->__get(__index_) + __value; }
return std::move(*this) = __ptr_->__get(__index_) + __value;
}
__simd_reference operator-=(_Vp __value) && { __simd_reference operator-=(_Vp __value) && { return std::move(*this) = __ptr_->__get(__index_) - __value; }
return std::move(*this) = __ptr_->__get(__index_) - __value;
}
__simd_reference operator*=(_Vp __value) && { __simd_reference operator*=(_Vp __value) && { return std::move(*this) = __ptr_->__get(__index_) * __value; }
return std::move(*this) = __ptr_->__get(__index_) * __value;
}
__simd_reference operator/=(_Vp __value) && { __simd_reference operator/=(_Vp __value) && { return std::move(*this) = __ptr_->__get(__index_) / __value; }
return std::move(*this) = __ptr_->__get(__index_) / __value;
}
__simd_reference operator%=(_Vp __value) && { __simd_reference operator%=(_Vp __value) && { return std::move(*this) = __ptr_->__get(__index_) % __value; }
return std::move(*this) = __ptr_->__get(__index_) % __value;
}
__simd_reference operator>>=(_Vp __value) && { __simd_reference operator>>=(_Vp __value) && { return std::move(*this) = __ptr_->__get(__index_) >> __value; }
return std::move(*this) = __ptr_->__get(__index_) >> __value;
}
__simd_reference operator<<=(_Vp __value) && { __simd_reference operator<<=(_Vp __value) && { return std::move(*this) = __ptr_->__get(__index_) << __value; }
return std::move(*this) = __ptr_->__get(__index_) << __value;
}
__simd_reference operator&=(_Vp __value) && { __simd_reference operator&=(_Vp __value) && { return std::move(*this) = __ptr_->__get(__index_) & __value; }
return std::move(*this) = __ptr_->__get(__index_) & __value;
}
__simd_reference operator|=(_Vp __value) && { __simd_reference operator|=(_Vp __value) && { return std::move(*this) = __ptr_->__get(__index_) | __value; }
return std::move(*this) = __ptr_->__get(__index_) | __value;
}
__simd_reference operator^=(_Vp __value) && { __simd_reference operator^=(_Vp __value) && { return std::move(*this) = __ptr_->__get(__index_) ^ __value; }
return std::move(*this) = __ptr_->__get(__index_) ^ __value;
}
bool operator<(_Vp __value) const { bool operator<(_Vp __value) const { return __ptr_->__get(__index_) < __value; }
return __ptr_->__get(__index_) < __value;
}
bool operator<=(_Vp __value) const { bool operator<=(_Vp __value) const { return __ptr_->__get(__index_) <= __value; }
return __ptr_->__get(__index_) <= __value;
}
bool operator>(_Vp __value) const { bool operator>(_Vp __value) const { return __ptr_->__get(__index_) > __value; }
return __ptr_->__get(__index_) > __value;
}
bool operator>=(_Vp __value) const { bool operator>=(_Vp __value) const { return __ptr_->__get(__index_) >= __value; }
return __ptr_->__get(__index_) >= __value;
}
bool operator==(_Vp __value) const { bool operator==(_Vp __value) const { return __ptr_->__get(__index_) == __value; }
return __ptr_->__get(__index_) == __value;
}
bool operator!=(_Vp __value) const { bool operator!=(_Vp __value) const { return __ptr_->__get(__index_) != __value; }
return __ptr_->__get(__index_) != __value;
}
}; };
template <class _Tp, class _Abi> template <class _Tp, class _Abi>
@ -922,8 +876,7 @@ class __simd_mask_reference {
__simd_mask_storage<_Tp, _Abi>* __ptr_; __simd_mask_storage<_Tp, _Abi>* __ptr_;
size_t __index_; size_t __index_;
__simd_mask_reference(__simd_mask_storage<_Tp, _Abi>* __ptr, size_t __index) __simd_mask_reference(__simd_mask_storage<_Tp, _Abi>* __ptr, size_t __index) : __ptr_(__ptr), __index_(__index) {}
: __ptr_(__ptr), __index_(__index) {}
__simd_mask_reference(const __simd_mask_reference&) = default; __simd_mask_reference(const __simd_mask_reference&) = default;
@ -940,8 +893,7 @@ public:
}; };
template <class _To, class _From> template <class _To, class _From>
constexpr decltype(_To{std::declval<_From>()}, true) constexpr decltype(_To{std::declval<_From>()}, true) __is_non_narrowing_convertible_impl(_From) {
__is_non_narrowing_convertible_impl(_From) {
return true; return true;
} }
@ -951,17 +903,13 @@ constexpr bool __is_non_narrowing_convertible_impl(...) {
} }
template <class _From, class _To> template <class _From, class _To>
constexpr typename std::enable_if<std::is_arithmetic<_To>::value && constexpr typename std::enable_if<std::is_arithmetic<_To>::value && std::is_arithmetic<_From>::value, bool>::type
std::is_arithmetic<_From>::value,
bool>::type
__is_non_narrowing_arithmetic_convertible() { __is_non_narrowing_arithmetic_convertible() {
return __is_non_narrowing_convertible_impl<_To>(_From{}); return __is_non_narrowing_convertible_impl<_To>(_From{});
} }
template <class _From, class _To> template <class _From, class _To>
constexpr typename std::enable_if<!(std::is_arithmetic<_To>::value && constexpr typename std::enable_if<!(std::is_arithmetic<_To>::value && std::is_arithmetic<_From>::value), bool>::type
std::is_arithmetic<_From>::value),
bool>::type
__is_non_narrowing_arithmetic_convertible() { __is_non_narrowing_arithmetic_convertible() {
return false; return false;
} }
@ -983,11 +931,11 @@ struct __nodeduce {
template <class _Tp> template <class _Tp>
constexpr bool __vectorizable() { constexpr bool __vectorizable() {
return std::is_arithmetic<_Tp>::value && !std::is_const<_Tp>::value && return std::is_arithmetic<_Tp>::value && !std::is_const<_Tp>::value && !std::is_volatile<_Tp>::value &&
!std::is_volatile<_Tp>::value && !std::is_same<_Tp, bool>::value; !std::is_same<_Tp, bool>::value;
} }
} } // namespace zeus::_simd
namespace zeus::_simd::simd_abi { namespace zeus::_simd::simd_abi {
using scalar = __simd_abi<_StorageKind::_Scalar, 1>; using scalar = __simd_abi<_StorageKind::_Scalar, 1>;
@ -1006,11 +954,10 @@ template <class _Tp>
using native = __simd_abi<_StorageKind::_VecExt, 16 / sizeof(_Tp)>; using native = __simd_abi<_StorageKind::_VecExt, 16 / sizeof(_Tp)>;
#else #else
template <class _Tp> template <class _Tp>
using native = using native = fixed_size<_Tp, 16 / sizeof(_Tp)>;
fixed_size<_Tp, 16 / sizeof(_Tp)>;
#endif // _LIBCPP_HAS_NO_VECTOR_EXTENSION #endif // _LIBCPP_HAS_NO_VECTOR_EXTENSION
} } // namespace zeus::_simd::simd_abi
namespace zeus::_simd { namespace zeus::_simd {
template <class _Tp, class _Abi = simd_abi::compatible<_Tp>> template <class _Tp, class _Abi = simd_abi::compatible<_Tp>>
@ -1032,8 +979,7 @@ template <class _Tp>
struct is_abi_tag : std::integral_constant<bool, false> {}; struct is_abi_tag : std::integral_constant<bool, false> {};
template <_StorageKind __kind, int _Np> template <_StorageKind __kind, int _Np>
struct is_abi_tag<__simd_abi<__kind, _Np>> struct is_abi_tag<__simd_abi<__kind, _Np>> : std::integral_constant<bool, true> {};
: std::integral_constant<bool, true> {};
template <class _Tp> template <class _Tp>
struct is_simd : std::integral_constant<bool, false> {}; struct is_simd : std::integral_constant<bool, false> {};
@ -1045,23 +991,19 @@ template <class _Tp>
struct is_simd_mask : std::integral_constant<bool, false> {}; struct is_simd_mask : std::integral_constant<bool, false> {};
template <class _Tp, class _Abi> template <class _Tp, class _Abi>
struct is_simd_mask<simd_mask<_Tp, _Abi>> : std::integral_constant<bool, true> { struct is_simd_mask<simd_mask<_Tp, _Abi>> : std::integral_constant<bool, true> {};
};
template <class _Tp> template <class _Tp>
struct is_simd_flag_type : std::integral_constant<bool, false> {}; struct is_simd_flag_type : std::integral_constant<bool, false> {};
template <> template <>
struct is_simd_flag_type<element_aligned_tag> struct is_simd_flag_type<element_aligned_tag> : std::integral_constant<bool, true> {};
: std::integral_constant<bool, true> {};
template <> template <>
struct is_simd_flag_type<vector_aligned_tag> struct is_simd_flag_type<vector_aligned_tag> : std::integral_constant<bool, true> {};
: std::integral_constant<bool, true> {};
template <size_t _Align> template <size_t _Align>
struct is_simd_flag_type<overaligned_tag<_Align>> struct is_simd_flag_type<overaligned_tag<_Align>> : std::integral_constant<bool, true> {};
: std::integral_constant<bool, true> {};
template <class _Tp> template <class _Tp>
inline constexpr bool is_abi_tag_v = is_abi_tag<_Tp>::value; inline constexpr bool is_abi_tag_v = is_abi_tag<_Tp>::value;
@ -1070,8 +1012,7 @@ inline constexpr bool is_simd_v = is_simd<_Tp>::value;
template <class _Tp> template <class _Tp>
inline constexpr bool is_simd_mask_v = is_simd_mask<_Tp>::value; inline constexpr bool is_simd_mask_v = is_simd_mask<_Tp>::value;
template <class _Tp> template <class _Tp>
inline constexpr bool is_simd_flag_type_v = inline constexpr bool is_simd_flag_type_v = is_simd_flag_type<_Tp>::value;
is_simd_flag_type<_Tp>::value;
template <class _Tp, size_t _Np> template <class _Tp, size_t _Np>
struct abi_for_size { struct abi_for_size {
using type = simd_abi::fixed_size<_Np>; using type = simd_abi::fixed_size<_Np>;
@ -1083,12 +1024,9 @@ template <class _Tp, class _Abi = simd_abi::compatible<_Tp>>
struct simd_size; struct simd_size;
template <class _Tp, _StorageKind __kind, int _Np> template <class _Tp, _StorageKind __kind, int _Np>
struct simd_size<_Tp, __simd_abi<__kind, _Np>> struct simd_size<_Tp, __simd_abi<__kind, _Np>> : std::integral_constant<size_t, _Np> {
: std::integral_constant<size_t, _Np> { static_assert(std::is_arithmetic<_Tp>::value && !std::is_same<typename std::remove_const<_Tp>::type, bool>::value,
static_assert( "Element type should be vectorizable");
std::is_arithmetic<_Tp>::value &&
!std::is_same<typename std::remove_const<_Tp>::type, bool>::value,
"Element type should be vectorizable");
}; };
// TODO: implement it. // TODO: implement it.
@ -1099,8 +1037,7 @@ template <class _Tp, class _Abi = simd_abi::compatible<_Tp>>
inline constexpr size_t simd_size_v = simd_size<_Tp, _Abi>::value; inline constexpr size_t simd_size_v = simd_size<_Tp, _Abi>::value;
template <class _Tp, class _Up = typename _Tp::value_type> template <class _Tp, class _Up = typename _Tp::value_type>
inline constexpr size_t memory_alignment_v = inline constexpr size_t memory_alignment_v = memory_alignment<_Tp, _Up>::value;
memory_alignment<_Tp, _Up>::value;
// class template simd [simd.class] // class template simd [simd.class]
template <class _Tp> template <class _Tp>
@ -1125,50 +1062,41 @@ struct __static_simd_cast_traits {
template <class _Tp, class _NewAbi> template <class _Tp, class _NewAbi>
struct __static_simd_cast_traits<simd<_Tp, _NewAbi>> { struct __static_simd_cast_traits<simd<_Tp, _NewAbi>> {
template <class _Up, class _Abi> template <class _Up, class _Abi>
static typename std::enable_if<simd<_Up, _Abi>::size() == static typename std::enable_if<simd<_Up, _Abi>::size() == simd<_Tp, _NewAbi>::size(), simd<_Tp, _NewAbi>>::type
simd<_Tp, _NewAbi>::size(),
simd<_Tp, _NewAbi>>::type
__apply(const simd<_Up, _Abi>& __v); __apply(const simd<_Up, _Abi>& __v);
}; };
template <class _Tp> template <class _Tp>
struct __simd_cast_traits { struct __simd_cast_traits {
template <class _Up, class _Abi> template <class _Up, class _Abi>
static typename std::enable_if< static typename std::enable_if<__is_non_narrowing_arithmetic_convertible<_Up, _Tp>(), simd<_Tp, _Abi>>::type
__is_non_narrowing_arithmetic_convertible<_Up, _Tp>(),
simd<_Tp, _Abi>>::type
__apply(const simd<_Up, _Abi>& __v); __apply(const simd<_Up, _Abi>& __v);
}; };
template <class _Tp, class _NewAbi> template <class _Tp, class _NewAbi>
struct __simd_cast_traits<simd<_Tp, _NewAbi>> { struct __simd_cast_traits<simd<_Tp, _NewAbi>> {
template <class _Up, class _Abi> template <class _Up, class _Abi>
static typename std::enable_if< static typename std::enable_if<__is_non_narrowing_arithmetic_convertible<_Up, _Tp>() &&
__is_non_narrowing_arithmetic_convertible<_Up, _Tp>() && simd<_Up, _Abi>::size() == simd<_Tp, _NewAbi>::size(),
simd<_Up, _Abi>::size() == simd<_Tp, _NewAbi>::size(), simd<_Tp, _NewAbi>>::type
simd<_Tp, _NewAbi>>::type
__apply(const simd<_Up, _Abi>& __v); __apply(const simd<_Up, _Abi>& __v);
}; };
template <class _Tp, class _Up, class _Abi> template <class _Tp, class _Up, class _Abi>
auto simd_cast(const simd<_Up, _Abi>& __v) auto simd_cast(const simd<_Up, _Abi>& __v) -> decltype(__simd_cast_traits<_Tp>::__apply(__v)) {
-> decltype(__simd_cast_traits<_Tp>::__apply(__v)) {
return __simd_cast_traits<_Tp>::__apply(__v); return __simd_cast_traits<_Tp>::__apply(__v);
} }
template <class _Tp, class _Up, class _Abi> template <class _Tp, class _Up, class _Abi>
auto static_simd_cast(const simd<_Up, _Abi>& __v) auto static_simd_cast(const simd<_Up, _Abi>& __v) -> decltype(__static_simd_cast_traits<_Tp>::__apply(__v)) {
-> decltype(__static_simd_cast_traits<_Tp>::__apply(__v)) {
return __static_simd_cast_traits<_Tp>::__apply(__v); return __static_simd_cast_traits<_Tp>::__apply(__v);
} }
template <class _Tp, class _Abi> template <class _Tp, class _Abi>
fixed_size_simd<_Tp, simd_size<_Tp, _Abi>::value> fixed_size_simd<_Tp, simd_size<_Tp, _Abi>::value> to_fixed_size(const simd<_Tp, _Abi>&) noexcept;
to_fixed_size(const simd<_Tp, _Abi>&) noexcept;
template <class _Tp, class _Abi> template <class _Tp, class _Abi>
fixed_size_simd_mask<_Tp, simd_size<_Tp, _Abi>::value> fixed_size_simd_mask<_Tp, simd_size<_Tp, _Abi>::value> to_fixed_size(const simd_mask<_Tp, _Abi>&) noexcept;
to_fixed_size(const simd_mask<_Tp, _Abi>&) noexcept;
template <class _Tp, size_t _Np> template <class _Tp, size_t _Np>
native_simd<_Tp> to_native(const fixed_size_simd<_Tp, _Np>&) noexcept; native_simd<_Tp> to_native(const fixed_size_simd<_Tp, _Np>&) noexcept;
@ -1186,26 +1114,21 @@ template <size_t... __sizes, class _Tp, class _Abi>
tuple<simd<_Tp, abi_for_size_t<_Tp, __sizes>>...> split(const simd<_Tp, _Abi>&); tuple<simd<_Tp, abi_for_size_t<_Tp, __sizes>>...> split(const simd<_Tp, _Abi>&);
template <size_t... __sizes, class _Tp, class _Abi> template <size_t... __sizes, class _Tp, class _Abi>
tuple<simd_mask<_Tp, abi_for_size_t<_Tp, __sizes>>...> tuple<simd_mask<_Tp, abi_for_size_t<_Tp, __sizes>>...> split(const simd_mask<_Tp, _Abi>&);
split(const simd_mask<_Tp, _Abi>&);
template <class _SimdType, class _Abi> template <class _SimdType, class _Abi>
array<_SimdType, simd_size<typename _SimdType::value_type, _Abi>::value / array<_SimdType, simd_size<typename _SimdType::value_type, _Abi>::value / _SimdType::size()>
_SimdType::size()>
split(const simd<typename _SimdType::value_type, _Abi>&); split(const simd<typename _SimdType::value_type, _Abi>&);
template <class _SimdType, class _Abi> template <class _SimdType, class _Abi>
array<_SimdType, simd_size<typename _SimdType::value_type, _Abi>::value / array<_SimdType, simd_size<typename _SimdType::value_type, _Abi>::value / _SimdType::size()>
_SimdType::size()>
split(const simd_mask<typename _SimdType::value_type, _Abi>&); split(const simd_mask<typename _SimdType::value_type, _Abi>&);
template <class _Tp, class... _Abis> template <class _Tp, class... _Abis>
simd<_Tp, abi_for_size_t<_Tp, __variadic_sum(simd_size<_Tp, _Abis>::value...)>> simd<_Tp, abi_for_size_t<_Tp, __variadic_sum(simd_size<_Tp, _Abis>::value...)>> concat(const simd<_Tp, _Abis>&...);
concat(const simd<_Tp, _Abis>&...);
template <class _Tp, class... _Abis> template <class _Tp, class... _Abis>
simd_mask<_Tp, simd_mask<_Tp, abi_for_size_t<_Tp, __variadic_sum(simd_size<_Tp, _Abis>::value...)>>
abi_for_size_t<_Tp, __variadic_sum(simd_size<_Tp, _Abis>::value...)>>
concat(const simd_mask<_Tp, _Abis>&...); concat(const simd_mask<_Tp, _Abis>&...);
// reductions [simd.mask.reductions] // reductions [simd.mask.reductions]
@ -1239,23 +1162,20 @@ class where_expression;
// masked assignment [simd.mask.where] // masked assignment [simd.mask.where]
template <class _Tp, class _Abi> template <class _Tp, class _Abi>
where_expression<simd_mask<_Tp, _Abi>, simd<_Tp, _Abi>> where_expression<simd_mask<_Tp, _Abi>, simd<_Tp, _Abi>> where(const typename simd<_Tp, _Abi>::mask_type&,
where(const typename simd<_Tp, _Abi>::mask_type&, simd<_Tp, _Abi>&) noexcept; simd<_Tp, _Abi>&) noexcept;
template <class _Tp, class _Abi> template <class _Tp, class _Abi>
const_where_expression<simd_mask<_Tp, _Abi>, const simd<_Tp, _Abi>> const_where_expression<simd_mask<_Tp, _Abi>, const simd<_Tp, _Abi>> where(const typename simd<_Tp, _Abi>::mask_type&,
where(const typename simd<_Tp, _Abi>::mask_type&, const simd<_Tp, _Abi>&) noexcept;
const simd<_Tp, _Abi>&) noexcept;
template <class _Tp, class _Abi> template <class _Tp, class _Abi>
where_expression<simd_mask<_Tp, _Abi>, simd_mask<_Tp, _Abi>> where_expression<simd_mask<_Tp, _Abi>, simd_mask<_Tp, _Abi>>
where(const typename __nodeduce<simd_mask<_Tp, _Abi>>::type&, where(const typename __nodeduce<simd_mask<_Tp, _Abi>>::type&, simd_mask<_Tp, _Abi>&) noexcept;
simd_mask<_Tp, _Abi>&) noexcept;
template <class _Tp, class _Abi> template <class _Tp, class _Abi>
const_where_expression<simd_mask<_Tp, _Abi>, const simd_mask<_Tp, _Abi>> const_where_expression<simd_mask<_Tp, _Abi>, const simd_mask<_Tp, _Abi>>
where(const typename __nodeduce<simd_mask<_Tp, _Abi>>::type&, where(const typename __nodeduce<simd_mask<_Tp, _Abi>>::type&, const simd_mask<_Tp, _Abi>&) noexcept;
const simd_mask<_Tp, _Abi>&) noexcept;
template <class _Tp> template <class _Tp>
where_expression<bool, _Tp> where(bool, _Tp&) noexcept; where_expression<bool, _Tp> where(bool, _Tp&) noexcept;
@ -1268,45 +1188,37 @@ template <class _Tp, class _Abi, class _BinaryOp = std::plus<_Tp>>
_Tp reduce(const simd<_Tp, _Abi>&, _BinaryOp = _BinaryOp()); _Tp reduce(const simd<_Tp, _Abi>&, _BinaryOp = _BinaryOp());
template <class _MaskType, class _SimdType, class _BinaryOp> template <class _MaskType, class _SimdType, class _BinaryOp>
typename _SimdType::value_type typename _SimdType::value_type reduce(const const_where_expression<_MaskType, _SimdType>&,
reduce(const const_where_expression<_MaskType, _SimdType>&, typename _SimdType::value_type neutral_element, _BinaryOp binary_op);
typename _SimdType::value_type neutral_element, _BinaryOp binary_op);
template <class _MaskType, class _SimdType> template <class _MaskType, class _SimdType>
typename _SimdType::value_type typename _SimdType::value_type reduce(const const_where_expression<_MaskType, _SimdType>&,
reduce(const const_where_expression<_MaskType, _SimdType>&, plus<typename _SimdType::value_type> binary_op = {});
plus<typename _SimdType::value_type> binary_op = {});
template <class _MaskType, class _SimdType> template <class _MaskType, class _SimdType>
typename _SimdType::value_type typename _SimdType::value_type reduce(const const_where_expression<_MaskType, _SimdType>&,
reduce(const const_where_expression<_MaskType, _SimdType>&, multiplies<typename _SimdType::value_type> binary_op);
multiplies<typename _SimdType::value_type> binary_op);
template <class _MaskType, class _SimdType> template <class _MaskType, class _SimdType>
typename _SimdType::value_type typename _SimdType::value_type reduce(const const_where_expression<_MaskType, _SimdType>&,
reduce(const const_where_expression<_MaskType, _SimdType>&, bit_and<typename _SimdType::value_type> binary_op);
bit_and<typename _SimdType::value_type> binary_op);
template <class _MaskType, class _SimdType> template <class _MaskType, class _SimdType>
typename _SimdType::value_type typename _SimdType::value_type reduce(const const_where_expression<_MaskType, _SimdType>&,
reduce(const const_where_expression<_MaskType, _SimdType>&, bit_or<typename _SimdType::value_type> binary_op);
bit_or<typename _SimdType::value_type> binary_op);
template <class _MaskType, class _SimdType> template <class _MaskType, class _SimdType>
typename _SimdType::value_type typename _SimdType::value_type reduce(const const_where_expression<_MaskType, _SimdType>&,
reduce(const const_where_expression<_MaskType, _SimdType>&, bit_xor<typename _SimdType::value_type> binary_op);
bit_xor<typename _SimdType::value_type> binary_op);
template <class _Tp, class _Abi> template <class _Tp, class _Abi>
_Tp hmin(const simd<_Tp, _Abi>&); _Tp hmin(const simd<_Tp, _Abi>&);
template <class _MaskType, class _SimdType> template <class _MaskType, class _SimdType>
typename _SimdType::value_type typename _SimdType::value_type hmin(const const_where_expression<_MaskType, _SimdType>&);
hmin(const const_where_expression<_MaskType, _SimdType>&);
template <class _Tp, class _Abi> template <class _Tp, class _Abi>
_Tp hmax(const simd<_Tp, _Abi>&); _Tp hmax(const simd<_Tp, _Abi>&);
template <class _MaskType, class _SimdType> template <class _MaskType, class _SimdType>
typename _SimdType::value_type typename _SimdType::value_type hmax(const const_where_expression<_MaskType, _SimdType>&);
hmax(const const_where_expression<_MaskType, _SimdType>&);
// algorithms [simd.alg] // algorithms [simd.alg]
template <class _Tp, class _Abi> template <class _Tp, class _Abi>
@ -1316,12 +1228,10 @@ template <class _Tp, class _Abi>
simd<_Tp, _Abi> max(const simd<_Tp, _Abi>&, const simd<_Tp, _Abi>&) noexcept; simd<_Tp, _Abi> max(const simd<_Tp, _Abi>&, const simd<_Tp, _Abi>&) noexcept;
template <class _Tp, class _Abi> template <class _Tp, class _Abi>
std::pair<simd<_Tp, _Abi>, simd<_Tp, _Abi>> std::pair<simd<_Tp, _Abi>, simd<_Tp, _Abi>> minmax(const simd<_Tp, _Abi>&, const simd<_Tp, _Abi>&) noexcept;
minmax(const simd<_Tp, _Abi>&, const simd<_Tp, _Abi>&) noexcept;
template <class _Tp, class _Abi> template <class _Tp, class _Abi>
simd<_Tp, _Abi> clamp(const simd<_Tp, _Abi>&, const simd<_Tp, _Abi>&, simd<_Tp, _Abi> clamp(const simd<_Tp, _Abi>&, const simd<_Tp, _Abi>&, const simd<_Tp, _Abi>&);
const simd<_Tp, _Abi>&);
// [simd.whereexpr] // [simd.whereexpr]
// TODO implement where expressions. // TODO implement where expressions.
@ -1387,6 +1297,7 @@ public:
auto end() { return std::end(__data_); } auto end() { return std::end(__data_); }
auto begin() const { return std::begin(__data_); } auto begin() const { return std::begin(__data_); }
auto end() const { return std::end(__data_); } auto end() const { return std::end(__data_); }
private: private:
value_type __data_[_Simd::size()]; value_type __data_[_Simd::size()];
}; };
@ -1396,6 +1307,7 @@ template <class _Tp, class _Abi>
class simd { class simd {
template <class _Up, class _UAbi> template <class _Up, class _UAbi>
friend class simd; friend class simd;
public: public:
using value_type = _Tp; using value_type = _Tp;
using reference = __simd_reference<_Tp, _Tp, _Abi>; using reference = __simd_reference<_Tp, _Tp, _Abi>;
@ -1406,34 +1318,25 @@ public:
simd(const simd&) = default; simd(const simd&) = default;
simd& operator=(const simd&) = default; simd& operator=(const simd&) = default;
static constexpr size_t size() noexcept { static constexpr size_t size() noexcept { return simd_size<_Tp, _Abi>::value; }
return simd_size<_Tp, _Abi>::value;
}
private: private:
__simd_storage<_Tp, _Abi> __s_; __simd_storage<_Tp, _Abi> __s_;
template <class _Up> template <class _Up>
static constexpr bool __can_broadcast() { static constexpr bool __can_broadcast() {
return (std::is_arithmetic<_Up>::value && return (std::is_arithmetic<_Up>::value && __is_non_narrowing_arithmetic_convertible<_Up, _Tp>()) ||
__is_non_narrowing_arithmetic_convertible<_Up, _Tp>()) || (!std::is_arithmetic<_Up>::value && std::is_convertible<_Up, _Tp>::value) ||
(!std::is_arithmetic<_Up>::value &&
std::is_convertible<_Up, _Tp>::value) ||
std::is_same<typename std::remove_const<_Up>::type, int>::value || std::is_same<typename std::remove_const<_Up>::type, int>::value ||
(std::is_same<typename std::remove_const<_Up>::type, (std::is_same<typename std::remove_const<_Up>::type, unsigned int>::value && std::is_unsigned<_Tp>::value);
unsigned int>::value &&
std::is_unsigned<_Tp>::value);
} }
template <class _Generator, size_t... __indicies> template <class _Generator, size_t... __indicies>
static constexpr decltype( static constexpr decltype(
std::forward_as_tuple(std::declval<_Generator>()( std::forward_as_tuple(std::declval<_Generator>()(std::integral_constant<size_t, __indicies>())...), bool())
std::integral_constant<size_t, __indicies>())...),
bool())
__can_generate(std::index_sequence<__indicies...>) { __can_generate(std::index_sequence<__indicies...>) {
return !__variadic_sum<bool>( return !__variadic_sum<bool>(
!__can_broadcast<decltype(std::declval<_Generator>()( !__can_broadcast<decltype(std::declval<_Generator>()(std::integral_constant<size_t, __indicies>()))>()...);
std::integral_constant<size_t, __indicies>()))>()...);
} }
template <class _Generator> template <class _Generator>
@ -1443,9 +1346,7 @@ private:
template <class _Generator, size_t... __indicies> template <class _Generator, size_t... __indicies>
void __generator_init(_Generator&& __g, std::index_sequence<__indicies...>) { void __generator_init(_Generator&& __g, std::index_sequence<__indicies...>) {
int __not_used[]{((*this)[__indicies] = int __not_used[]{((*this)[__indicies] = __g(std::integral_constant<size_t, __indicies>()), 0)...};
__g(std::integral_constant<size_t, __indicies>()),
0)...};
(void)__not_used; (void)__not_used;
} }
@ -1466,8 +1367,8 @@ public:
#endif #endif
// implicit type conversion constructor // implicit type conversion constructor
template <class _Up, class _UAbi, template <class _Up, class _UAbi,
class = typename std::enable_if<std::is_constructible< class = typename std::enable_if<
__simd_storage<_Tp, _Abi>, __simd_storage<_Up, _UAbi>>::value>> std::is_constructible<__simd_storage<_Tp, _Abi>, __simd_storage<_Up, _UAbi>>::value>>
simd(const simd<_Up, _UAbi>& __v) : __s_(__v.__s_) {} simd(const simd<_Up, _UAbi>& __v) : __s_(__v.__s_) {}
#if 0 #if 0
@ -1489,29 +1390,20 @@ public:
__s_.__broadcast(v); __s_.__broadcast(v);
} }
#endif #endif
simd(_Tp __rv) { simd(_Tp __rv) { __s_.__broadcast(__rv); }
__s_.__broadcast(__rv);
}
simd(_Tp a, _Tp b, _Tp c = {}, _Tp d = {}) { simd(_Tp a, _Tp b, _Tp c = {}, _Tp d = {}) { __s_.__set4(a, b, c, d); }
__s_.__set4(a, b, c, d);
}
// generator constructor // generator constructor
template <class _Generator, template <class _Generator,
int = typename std::enable_if< int = typename std::enable_if<__can_generate<_Generator>(std::make_index_sequence<size()>()), int>::type()>
__can_generate<_Generator>(std::make_index_sequence<size()>()),
int>::type()>
explicit simd(_Generator&& __g) { explicit simd(_Generator&& __g) {
__generator_init(std::forward<_Generator>(__g), __generator_init(std::forward<_Generator>(__g), std::make_index_sequence<size()>());
std::make_index_sequence<size()>());
} }
// load constructor // load constructor
template < template <class _Up, class _Flags, class = typename std::enable_if<__vectorizable<_Up>()>::type,
class _Up, class _Flags, class = typename std::enable_if<is_simd_flag_type<_Flags>::value>::type>
class = typename std::enable_if<__vectorizable<_Up>()>::type,
class = typename std::enable_if<is_simd_flag_type<_Flags>::value>::type>
simd(const _Up* __buffer, _Flags) { simd(const _Up* __buffer, _Flags) {
// TODO: optimize for overaligned flags // TODO: optimize for overaligned flags
for (size_t __i = 0; __i < size(); __i++) { for (size_t __i = 0; __i < size(); __i++) {
@ -1529,9 +1421,7 @@ public:
} }
#endif #endif
// loads [simd.load] // loads [simd.load]
void copy_from(const simd_data<simd>& __buffer) { void copy_from(const simd_data<simd>& __buffer) { __s_.__copy_from(__buffer); }
__s_.__copy_from(__buffer);
}
#if 0 #if 0
// stores [simd.store] // stores [simd.store]
@ -1546,9 +1436,7 @@ public:
} }
#endif #endif
// stores [simd.store] // stores [simd.store]
void copy_to(simd_data<simd>& __buffer) const { void copy_to(simd_data<simd>& __buffer) const { __s_.__copy_to(__buffer); }
__s_.__copy_to(__buffer);
}
// scalar access [simd.subscr] // scalar access [simd.subscr]
reference operator[](size_t __i) { return reference(&__s_, __i); } reference operator[](size_t __i) { return reference(&__s_, __i); }
@ -1606,7 +1494,7 @@ public:
value_type dot3(const simd& other) const { return __s_.__dot3(other.__s_); } value_type dot3(const simd& other) const { return __s_.__dot3(other.__s_); }
value_type dot4(const simd& other) const { return __s_.__dot4(other.__s_); } value_type dot4(const simd& other) const { return __s_.__dot4(other.__s_); }
template<int x, int y, int z, int w> template <int x, int y, int z, int w>
simd shuffle() const { simd shuffle() const {
simd s; simd s;
s.__s_ = __s_.template __shuffle<x, y, z, w>(); s.__s_ = __s_.template __shuffle<x, y, z, w>();
@ -1624,9 +1512,7 @@ public:
using reference = __simd_mask_reference<_Tp, _Abi>; using reference = __simd_mask_reference<_Tp, _Abi>;
using simd_type = simd<_Tp, _Abi>; using simd_type = simd<_Tp, _Abi>;
using abi_type = _Abi; using abi_type = _Abi;
static constexpr size_t size() noexcept { static constexpr size_t size() noexcept { return simd_size<_Tp, _Abi>::value; }
return simd_size<_Tp, _Abi>::value;
}
simd_mask() = default; simd_mask() = default;
// broadcast constructor // broadcast constructor
@ -1683,12 +1569,15 @@ public:
}; };
template <class _Simd> template <class _Simd>
inline simd_data<_Simd>::simd_data(const _Simd& s) { s.copy_to(*this); } inline simd_data<_Simd>::simd_data(const _Simd& s) {
s.copy_to(*this);
}
template <class _Tp, int __num_element> template <class _Tp, int __num_element>
class __simd_storage<_Tp, __simd_abi<_StorageKind::_Array, __num_element>> { class __simd_storage<_Tp, __simd_abi<_StorageKind::_Array, __num_element>> {
public: public:
using storage_type = std::array<_Tp, __num_element>; using storage_type = std::array<_Tp, __num_element>;
private: private:
storage_type __storage_; storage_type __storage_;
@ -1700,34 +1589,26 @@ private:
public: public:
_Tp __get(size_t __index) const noexcept { return __storage_[__index]; }; _Tp __get(size_t __index) const noexcept { return __storage_[__index]; };
void __set(size_t __index, _Tp __val) noexcept { void __set(size_t __index, _Tp __val) noexcept { __storage_[__index] = __val; }
__storage_[__index] = __val;
}
std::enable_if_t<__num_element >= 4> __set4(float a, float b, float c, float d) noexcept { std::enable_if_t<__num_element >= 4> __set4(float a, float b, float c, float d) noexcept {
__storage_[0] = a; __storage_[0] = a;
__storage_[1] = b; __storage_[1] = b;
__storage_[2] = c; __storage_[2] = c;
__storage_[3] = d; __storage_[3] = d;
} }
void __broadcast(float __val) noexcept { void __broadcast(float __val) noexcept { std::fill(__storage_.begin(), __storage_.end(), __val); }
std::fill(__storage_.begin(), __storage_.end(), __val);
}
std::enable_if_t<__num_element >= 2, _Tp> __dot2(const __simd_storage& other) const noexcept { std::enable_if_t<__num_element >= 2, _Tp> __dot2(const __simd_storage& other) const noexcept {
return __storage_[0] * other.__storage_[0] + return __storage_[0] * other.__storage_[0] + __storage_[1] * other.__storage_[1];
__storage_[1] * other.__storage_[1];
} }
std::enable_if_t<__num_element >= 3, _Tp> __dot3(const __simd_storage& other) const noexcept { std::enable_if_t<__num_element >= 3, _Tp> __dot3(const __simd_storage& other) const noexcept {
return __storage_[0] * other.__storage_[0] + return __storage_[0] * other.__storage_[0] + __storage_[1] * other.__storage_[1] +
__storage_[1] * other.__storage_[1] +
__storage_[2] * other.__storage_[2]; __storage_[2] * other.__storage_[2];
} }
std::enable_if_t<__num_element >= 4, _Tp> __dot4(const __simd_storage& other) const noexcept { std::enable_if_t<__num_element >= 4, _Tp> __dot4(const __simd_storage& other) const noexcept {
return __storage_[0] * other.__storage_[0] + return __storage_[0] * other.__storage_[0] + __storage_[1] * other.__storage_[1] +
__storage_[1] * other.__storage_[1] + __storage_[2] * other.__storage_[2] + __storage_[3] * other.__storage_[3];
__storage_[2] * other.__storage_[2] +
__storage_[3] * other.__storage_[3];
} }
template<int x, int y, int z, int w> template <int x, int y, int z, int w>
std::enable_if_t<__num_element >= 4, __simd_storage> __shuffle() const noexcept { std::enable_if_t<__num_element >= 4, __simd_storage> __shuffle() const noexcept {
__simd_storage s; __simd_storage s;
s.__storage_[0] = __storage_[x]; s.__storage_[0] = __storage_[x];
@ -1756,13 +1637,10 @@ public:
template <class _Tp, int __num_element> template <class _Tp, int __num_element>
class __simd_mask_storage<_Tp, __simd_abi<_StorageKind::_Array, __num_element>> { class __simd_mask_storage<_Tp, __simd_abi<_StorageKind::_Array, __num_element>> {
std::bitset<__num_element> __storage_; std::bitset<__num_element> __storage_;
public: public:
bool __get(size_t __index) const noexcept { bool __get(size_t __index) const noexcept { return __storage_.test(__index); }
return __storage_.test(__index); void __set(size_t __index, bool __val) noexcept { __storage_.set(__index, __val); }
}
void __set(size_t __index, bool __val) noexcept {
__storage_.set(__index, __val);
}
}; };
} } // namespace zeus::_simd

View File

@ -1,6 +1,8 @@
#pragma once #pragma once
#define _ZEUS_SIMD_INCLUDED #define _ZEUS_SIMD_INCLUDED
namespace zeus::_simd { using namespace std; } namespace zeus::_simd {
using namespace std;
}
#include "parallelism_v2_simd.hpp" #include "parallelism_v2_simd.hpp"
#if _M_IX86_FP >= 1 || _M_X64 #if _M_IX86_FP >= 1 || _M_X64
#define __SSE__ 1 #define __SSE__ 1
@ -11,16 +13,23 @@ namespace zeus::_simd { using namespace std; }
#include "simd_sse.hpp" #include "simd_sse.hpp"
#else #else
namespace simd_abi { namespace simd_abi {
template<typename T> struct zeus_native {}; template <typename T>
template<> struct zeus_native<float> { using type = fixed_size<4>; }; struct zeus_native {};
template<> struct zeus_native<double> { using type = fixed_size<4>; }; template <>
} struct zeus_native<float> {
using type = fixed_size<4>;
};
template <>
struct zeus_native<double> {
using type = fixed_size<4>;
};
} // namespace simd_abi
#endif #endif
namespace zeus { namespace zeus {
template<typename T> using simd = _simd::simd<T, template <typename T>
typename _simd::simd_abi::zeus_native<T>::type>; using simd = _simd::simd<T, typename _simd::simd_abi::zeus_native<T>::type>;
template<typename T> template <typename T>
using simd_values = _simd::simd_data<simd<T>>; using simd_values = _simd::simd_data<simd<T>>;
using simd_floats = simd_values<float>; using simd_floats = simd_values<float>;
using simd_doubles = simd_values<double>; using simd_doubles = simd_values<double>;
} } // namespace zeus

View File

@ -6,7 +6,7 @@
#include <immintrin.h> #include <immintrin.h>
namespace zeus::_simd { namespace zeus::_simd {
// __m256d storage for AVX // __m256d storage for AVX
template<> template <>
class __simd_storage<double, m256d_abi> { class __simd_storage<double, m256d_abi> {
public: public:
using storage_type = __m256d; using storage_type = __m256d;
@ -22,12 +22,8 @@ public:
sse_data[__index] = __val; sse_data[__index] = __val;
__storage_ = _mm256_load_pd(sse_data.data()); __storage_ = _mm256_load_pd(sse_data.data());
} }
void __set4(double a, double b, double c, double d) noexcept { void __set4(double a, double b, double c, double d) noexcept { __storage_ = _mm256_set_pd(d, c, b, a); }
__storage_ = _mm256_set_pd(d, c, b, a); void __broadcast(double __val) noexcept { __storage_ = _mm256_set1_pd(__val); }
}
void __broadcast(double __val) noexcept {
__storage_ = _mm256_set1_pd(__val);
}
double __dot2(const __simd_storage<double, m256d_abi>& other) const noexcept { double __dot2(const __simd_storage<double, m256d_abi>& other) const noexcept {
alignas(32) std::array<double, 4> sse_data; alignas(32) std::array<double, 4> sse_data;
_mm256_store_pd(sse_data.data(), _mm256_mul_pd(__storage_, other.__storage_)); _mm256_store_pd(sse_data.data(), _mm256_mul_pd(__storage_, other.__storage_));
@ -61,7 +57,7 @@ public:
const storage_type& __native() const { return __storage_; } const storage_type& __native() const { return __storage_; }
}; };
// __m256d mask storage for AVX // __m256d mask storage for AVX
template<> template <>
class __simd_mask_storage<double, m256d_abi> : public __simd_storage<double, m256d_abi> { class __simd_mask_storage<double, m256d_abi> : public __simd_storage<double, m256d_abi> {
public: public:
bool __get(size_t __index) const noexcept { bool __get(size_t __index) const noexcept {
@ -83,95 +79,87 @@ inline simd<double, m256d_abi> simd<double, m256d_abi>::operator-() const {
return _mm256_xor_pd(__s_.__storage_, _mm256_set1_pd(-0.0)); return _mm256_xor_pd(__s_.__storage_, _mm256_set1_pd(-0.0));
} }
inline simd<double, m256d_abi> inline simd<double, m256d_abi> operator+(const simd<double, m256d_abi>& a, const simd<double, m256d_abi>& b) {
operator+(const simd<double, m256d_abi>& a, const simd<double, m256d_abi>& b) {
simd<double, m256d_abi> ret; simd<double, m256d_abi> ret;
ret.__s_.__storage_ = _mm256_add_pd(a.__s_.__storage_, b.__s_.__storage_); ret.__s_.__storage_ = _mm256_add_pd(a.__s_.__storage_, b.__s_.__storage_);
return ret; return ret;
} }
inline simd<double, m256d_abi> inline simd<double, m256d_abi> operator-(const simd<double, m256d_abi>& a, const simd<double, m256d_abi>& b) {
operator-(const simd<double, m256d_abi>& a, const simd<double, m256d_abi>& b) {
simd<double, m256d_abi> ret; simd<double, m256d_abi> ret;
ret.__s_.__storage_ = _mm256_sub_pd(a.__s_.__storage_, b.__s_.__storage_); ret.__s_.__storage_ = _mm256_sub_pd(a.__s_.__storage_, b.__s_.__storage_);
return ret; return ret;
} }
inline simd<double, m256d_abi> inline simd<double, m256d_abi> operator*(const simd<double, m256d_abi>& a, const simd<double, m256d_abi>& b) {
operator*(const simd<double, m256d_abi>& a, const simd<double, m256d_abi>& b) {
simd<double, m256d_abi> ret; simd<double, m256d_abi> ret;
ret.__s_.__storage_ = _mm256_mul_pd(a.__s_.__storage_, b.__s_.__storage_); ret.__s_.__storage_ = _mm256_mul_pd(a.__s_.__storage_, b.__s_.__storage_);
return ret; return ret;
} }
inline simd<double, m256d_abi> inline simd<double, m256d_abi> operator/(const simd<double, m256d_abi>& a, const simd<double, m256d_abi>& b) {
operator/(const simd<double, m256d_abi>& a, const simd<double, m256d_abi>& b) {
simd<double, m256d_abi> ret; simd<double, m256d_abi> ret;
ret.__s_.__storage_ = _mm256_div_pd(a.__s_.__storage_, b.__s_.__storage_); ret.__s_.__storage_ = _mm256_div_pd(a.__s_.__storage_, b.__s_.__storage_);
return ret; return ret;
} }
inline simd<double, m256d_abi>& inline simd<double, m256d_abi>& operator+=(simd<double, m256d_abi>& a, const simd<double, m256d_abi>& b) {
operator+=(simd<double, m256d_abi>& a, const simd<double, m256d_abi>& b) {
a.__s_.__storage_ = _mm256_add_pd(a.__s_.__storage_, b.__s_.__storage_); a.__s_.__storage_ = _mm256_add_pd(a.__s_.__storage_, b.__s_.__storage_);
return a; return a;
} }
inline simd<double, m256d_abi>& inline simd<double, m256d_abi>& operator-=(simd<double, m256d_abi>& a, const simd<double, m256d_abi>& b) {
operator-=(simd<double, m256d_abi>& a, const simd<double, m256d_abi>& b) {
a.__s_.__storage_ = _mm256_sub_pd(a.__s_.__storage_, b.__s_.__storage_); a.__s_.__storage_ = _mm256_sub_pd(a.__s_.__storage_, b.__s_.__storage_);
return a; return a;
} }
inline simd<double, m256d_abi>& inline simd<double, m256d_abi>& operator*=(simd<double, m256d_abi>& a, const simd<double, m256d_abi>& b) {
operator*=(simd<double, m256d_abi>& a, const simd<double, m256d_abi>& b) {
a.__s_.__storage_ = _mm256_mul_pd(a.__s_.__storage_, b.__s_.__storage_); a.__s_.__storage_ = _mm256_mul_pd(a.__s_.__storage_, b.__s_.__storage_);
return a; return a;
} }
inline simd<double, m256d_abi>& inline simd<double, m256d_abi>& operator/=(simd<double, m256d_abi>& a, const simd<double, m256d_abi>& b) {
operator/=(simd<double, m256d_abi>& a, const simd<double, m256d_abi>& b) {
a.__s_.__storage_ = _mm256_div_pd(a.__s_.__storage_, b.__s_.__storage_); a.__s_.__storage_ = _mm256_div_pd(a.__s_.__storage_, b.__s_.__storage_);
return a; return a;
} }
inline simd<double, m256d_abi>::mask_type inline simd<double, m256d_abi>::mask_type operator==(const simd<double, m256d_abi>& a,
operator==(const simd<double, m256d_abi>& a, const simd<double, m256d_abi>& b) { const simd<double, m256d_abi>& b) {
simd<double, m256d_abi>::mask_type ret; simd<double, m256d_abi>::mask_type ret;
ret.__s_.__storage_ = _mm256_cmp_pd(a.__s_.__storage_, b.__s_.__storage_, _CMP_EQ_OQ); ret.__s_.__storage_ = _mm256_cmp_pd(a.__s_.__storage_, b.__s_.__storage_, _CMP_EQ_OQ);
return ret; return ret;
} }
inline simd<double, m256d_abi>::mask_type inline simd<double, m256d_abi>::mask_type operator!=(const simd<double, m256d_abi>& a,
operator!=(const simd<double, m256d_abi>& a, const simd<double, m256d_abi>& b) { const simd<double, m256d_abi>& b) {
simd<double, m256d_abi>::mask_type ret; simd<double, m256d_abi>::mask_type ret;
ret.__s_.__storage_ = _mm256_cmp_pd(a.__s_.__storage_, b.__s_.__storage_, _CMP_NEQ_OQ); ret.__s_.__storage_ = _mm256_cmp_pd(a.__s_.__storage_, b.__s_.__storage_, _CMP_NEQ_OQ);
return ret; return ret;
} }
inline simd<double, m256d_abi>::mask_type inline simd<double, m256d_abi>::mask_type operator>=(const simd<double, m256d_abi>& a,
operator>=(const simd<double, m256d_abi>& a, const simd<double, m256d_abi>& b) { const simd<double, m256d_abi>& b) {
simd<double, m256d_abi>::mask_type ret; simd<double, m256d_abi>::mask_type ret;
ret.__s_.__storage_ = _mm256_cmp_pd(a.__s_.__storage_, b.__s_.__storage_, _CMP_GE_OQ); ret.__s_.__storage_ = _mm256_cmp_pd(a.__s_.__storage_, b.__s_.__storage_, _CMP_GE_OQ);
return ret; return ret;
} }
inline simd<double, m256d_abi>::mask_type inline simd<double, m256d_abi>::mask_type operator<=(const simd<double, m256d_abi>& a,
operator<=(const simd<double, m256d_abi>& a, const simd<double, m256d_abi>& b) { const simd<double, m256d_abi>& b) {
simd<double, m256d_abi>::mask_type ret; simd<double, m256d_abi>::mask_type ret;
ret.__s_.__storage_ = _mm256_cmp_pd(a.__s_.__storage_, b.__s_.__storage_, _CMP_LE_OQ); ret.__s_.__storage_ = _mm256_cmp_pd(a.__s_.__storage_, b.__s_.__storage_, _CMP_LE_OQ);
return ret; return ret;
} }
inline simd<double, m256d_abi>::mask_type inline simd<double, m256d_abi>::mask_type operator>(const simd<double, m256d_abi>& a,
operator>(const simd<double, m256d_abi>& a, const simd<double, m256d_abi>& b) { const simd<double, m256d_abi>& b) {
simd<double, m256d_abi>::mask_type ret; simd<double, m256d_abi>::mask_type ret;
ret.__s_.__storage_ = _mm256_cmp_pd(a.__s_.__storage_, b.__s_.__storage_, _CMP_GT_OQ); ret.__s_.__storage_ = _mm256_cmp_pd(a.__s_.__storage_, b.__s_.__storage_, _CMP_GT_OQ);
return ret; return ret;
} }
inline simd<double, m256d_abi>::mask_type inline simd<double, m256d_abi>::mask_type operator<(const simd<double, m256d_abi>& a,
operator<(const simd<double, m256d_abi>& a, const simd<double, m256d_abi>& b) { const simd<double, m256d_abi>& b) {
simd<double, m256d_abi>::mask_type ret; simd<double, m256d_abi>::mask_type ret;
ret.__s_.__storage_ = _mm256_cmp_pd(a.__s_.__storage_, b.__s_.__storage_, _CMP_LT_OQ); ret.__s_.__storage_ = _mm256_cmp_pd(a.__s_.__storage_, b.__s_.__storage_, _CMP_LT_OQ);
return ret; return ret;
@ -182,7 +170,10 @@ inline __simd_storage<float, m128_abi>::__simd_storage(const __simd_storage<doub
} }
namespace simd_abi { namespace simd_abi {
template<> struct zeus_native<double> { using type = m256d_abi; }; template <>
struct zeus_native<double> {
using type = m256d_abi;
};
} // namespace simd_abi } // namespace simd_abi
} // namespace zeus::_simd } // namespace zeus::_simd

View File

@ -40,12 +40,8 @@ public:
sse_data[__index] = __val; sse_data[__index] = __val;
__storage_ = _mm_load_ps(sse_data.data()); __storage_ = _mm_load_ps(sse_data.data());
} }
void __set4(float a, float b, float c, float d) noexcept { void __set4(float a, float b, float c, float d) noexcept { __storage_ = _mm_set_ps(d, c, b, a); }
__storage_ = _mm_set_ps(d, c, b, a); void __broadcast(float __val) noexcept { __storage_ = _mm_set1_ps(__val); }
}
void __broadcast(float __val) noexcept {
__storage_ = _mm_set1_ps(__val);
}
float __dot2(const __simd_storage<float, m128_abi>& other) const noexcept { float __dot2(const __simd_storage<float, m128_abi>& other) const noexcept {
#if __SSE4_1__ #if __SSE4_1__
float ret; float ret;
@ -79,7 +75,7 @@ public:
return sse_data[0] + sse_data[1] + sse_data[2] + sse_data[3]; return sse_data[0] + sse_data[1] + sse_data[2] + sse_data[3];
#endif #endif
} }
template<int x, int y, int z, int w> template <int x, int y, int z, int w>
__simd_storage __shuffle() const noexcept { __simd_storage __shuffle() const noexcept {
__simd_storage s; __simd_storage s;
s.__storage_ = _mm_shuffle_ps(__storage_, __storage_, _MM_SHUFFLE(w, z, y, x)); s.__storage_ = _mm_shuffle_ps(__storage_, __storage_, _MM_SHUFFLE(w, z, y, x));
@ -105,8 +101,7 @@ public:
}; };
// __m128 mask storage for SSE2+ // __m128 mask storage for SSE2+
template <> template <>
class __simd_mask_storage<float, m128_abi> : public __simd_storage<float, m128_abi> class __simd_mask_storage<float, m128_abi> : public __simd_storage<float, m128_abi> {
{
public: public:
bool __get(size_t __index) const noexcept { bool __get(size_t __index) const noexcept {
alignas(16) uint32_t sse_data[4]; alignas(16) uint32_t sse_data[4];
@ -126,95 +121,81 @@ inline simd<float, m128_abi> simd<float, m128_abi>::operator-() const {
return _mm_xor_ps(__s_.__storage_, _mm_set1_ps(-0.f)); return _mm_xor_ps(__s_.__storage_, _mm_set1_ps(-0.f));
} }
inline simd<float, m128_abi> inline simd<float, m128_abi> operator+(const simd<float, m128_abi>& a, const simd<float, m128_abi>& b) {
operator+(const simd<float, m128_abi>& a, const simd<float, m128_abi>& b) {
simd<float, m128_abi> ret; simd<float, m128_abi> ret;
ret.__s_.__storage_ = _mm_add_ps(a.__s_.__storage_, b.__s_.__storage_); ret.__s_.__storage_ = _mm_add_ps(a.__s_.__storage_, b.__s_.__storage_);
return ret; return ret;
} }
inline simd<float, m128_abi> inline simd<float, m128_abi> operator-(const simd<float, m128_abi>& a, const simd<float, m128_abi>& b) {
operator-(const simd<float, m128_abi>& a, const simd<float, m128_abi>& b) {
simd<float, m128_abi> ret; simd<float, m128_abi> ret;
ret.__s_.__storage_ = _mm_sub_ps(a.__s_.__storage_, b.__s_.__storage_); ret.__s_.__storage_ = _mm_sub_ps(a.__s_.__storage_, b.__s_.__storage_);
return ret; return ret;
} }
inline simd<float, m128_abi> inline simd<float, m128_abi> operator*(const simd<float, m128_abi>& a, const simd<float, m128_abi>& b) {
operator*(const simd<float, m128_abi>& a, const simd<float, m128_abi>& b) {
simd<float, m128_abi> ret; simd<float, m128_abi> ret;
ret.__s_.__storage_ = _mm_mul_ps(a.__s_.__storage_, b.__s_.__storage_); ret.__s_.__storage_ = _mm_mul_ps(a.__s_.__storage_, b.__s_.__storage_);
return ret; return ret;
} }
inline simd<float, m128_abi> inline simd<float, m128_abi> operator/(const simd<float, m128_abi>& a, const simd<float, m128_abi>& b) {
operator/(const simd<float, m128_abi>& a, const simd<float, m128_abi>& b) {
simd<float, m128_abi> ret; simd<float, m128_abi> ret;
ret.__s_.__storage_ = _mm_div_ps(a.__s_.__storage_, b.__s_.__storage_); ret.__s_.__storage_ = _mm_div_ps(a.__s_.__storage_, b.__s_.__storage_);
return ret; return ret;
} }
inline simd<float, m128_abi>& inline simd<float, m128_abi>& operator+=(simd<float, m128_abi>& a, const simd<float, m128_abi>& b) {
operator+=(simd<float, m128_abi>& a, const simd<float, m128_abi>& b) {
a.__s_.__storage_ = _mm_add_ps(a.__s_.__storage_, b.__s_.__storage_); a.__s_.__storage_ = _mm_add_ps(a.__s_.__storage_, b.__s_.__storage_);
return a; return a;
} }
inline simd<float, m128_abi>& inline simd<float, m128_abi>& operator-=(simd<float, m128_abi>& a, const simd<float, m128_abi>& b) {
operator-=(simd<float, m128_abi>& a, const simd<float, m128_abi>& b) {
a.__s_.__storage_ = _mm_sub_ps(a.__s_.__storage_, b.__s_.__storage_); a.__s_.__storage_ = _mm_sub_ps(a.__s_.__storage_, b.__s_.__storage_);
return a; return a;
} }
inline simd<float, m128_abi>& inline simd<float, m128_abi>& operator*=(simd<float, m128_abi>& a, const simd<float, m128_abi>& b) {
operator*=(simd<float, m128_abi>& a, const simd<float, m128_abi>& b) {
a.__s_.__storage_ = _mm_mul_ps(a.__s_.__storage_, b.__s_.__storage_); a.__s_.__storage_ = _mm_mul_ps(a.__s_.__storage_, b.__s_.__storage_);
return a; return a;
} }
inline simd<float, m128_abi>& inline simd<float, m128_abi>& operator/=(simd<float, m128_abi>& a, const simd<float, m128_abi>& b) {
operator/=(simd<float, m128_abi>& a, const simd<float, m128_abi>& b) {
a.__s_.__storage_ = _mm_div_ps(a.__s_.__storage_, b.__s_.__storage_); a.__s_.__storage_ = _mm_div_ps(a.__s_.__storage_, b.__s_.__storage_);
return a; return a;
} }
inline simd<float, m128_abi>::mask_type inline simd<float, m128_abi>::mask_type operator==(const simd<float, m128_abi>& a, const simd<float, m128_abi>& b) {
operator==(const simd<float, m128_abi>& a, const simd<float, m128_abi>& b) {
simd<float, m128_abi>::mask_type ret; simd<float, m128_abi>::mask_type ret;
ret.__s_.__storage_ = _mm_cmpeq_ps(a.__s_.__storage_, b.__s_.__storage_); ret.__s_.__storage_ = _mm_cmpeq_ps(a.__s_.__storage_, b.__s_.__storage_);
return ret; return ret;
} }
inline simd<float, m128_abi>::mask_type inline simd<float, m128_abi>::mask_type operator!=(const simd<float, m128_abi>& a, const simd<float, m128_abi>& b) {
operator!=(const simd<float, m128_abi>& a, const simd<float, m128_abi>& b) {
simd<float, m128_abi>::mask_type ret; simd<float, m128_abi>::mask_type ret;
ret.__s_.__storage_ = _mm_cmpneq_ps(a.__s_.__storage_, b.__s_.__storage_); ret.__s_.__storage_ = _mm_cmpneq_ps(a.__s_.__storage_, b.__s_.__storage_);
return ret; return ret;
} }
inline simd<float, m128_abi>::mask_type inline simd<float, m128_abi>::mask_type operator>=(const simd<float, m128_abi>& a, const simd<float, m128_abi>& b) {
operator>=(const simd<float, m128_abi>& a, const simd<float, m128_abi>& b) {
simd<float, m128_abi>::mask_type ret; simd<float, m128_abi>::mask_type ret;
ret.__s_.__storage_ = _mm_cmpge_ps(a.__s_.__storage_, b.__s_.__storage_); ret.__s_.__storage_ = _mm_cmpge_ps(a.__s_.__storage_, b.__s_.__storage_);
return ret; return ret;
} }
inline simd<float, m128_abi>::mask_type inline simd<float, m128_abi>::mask_type operator<=(const simd<float, m128_abi>& a, const simd<float, m128_abi>& b) {
operator<=(const simd<float, m128_abi>& a, const simd<float, m128_abi>& b) {
simd<float, m128_abi>::mask_type ret; simd<float, m128_abi>::mask_type ret;
ret.__s_.__storage_ = _mm_cmple_ps(a.__s_.__storage_, b.__s_.__storage_); ret.__s_.__storage_ = _mm_cmple_ps(a.__s_.__storage_, b.__s_.__storage_);
return ret; return ret;
} }
inline simd<float, m128_abi>::mask_type inline simd<float, m128_abi>::mask_type operator>(const simd<float, m128_abi>& a, const simd<float, m128_abi>& b) {
operator>(const simd<float, m128_abi>& a, const simd<float, m128_abi>& b) {
simd<float, m128_abi>::mask_type ret; simd<float, m128_abi>::mask_type ret;
ret.__s_.__storage_ = _mm_cmpgt_ps(a.__s_.__storage_, b.__s_.__storage_); ret.__s_.__storage_ = _mm_cmpgt_ps(a.__s_.__storage_, b.__s_.__storage_);
return ret; return ret;
} }
inline simd<float, m128_abi>::mask_type inline simd<float, m128_abi>::mask_type operator<(const simd<float, m128_abi>& a, const simd<float, m128_abi>& b) {
operator<(const simd<float, m128_abi>& a, const simd<float, m128_abi>& b) {
simd<float, m128_abi>::mask_type ret; simd<float, m128_abi>::mask_type ret;
ret.__s_.__storage_ = _mm_cmplt_ps(a.__s_.__storage_, b.__s_.__storage_); ret.__s_.__storage_ = _mm_cmplt_ps(a.__s_.__storage_, b.__s_.__storage_);
return ret; return ret;
@ -308,8 +289,7 @@ public:
}; };
// __m128d mask storage for SSE2+ // __m128d mask storage for SSE2+
template <> template <>
class __simd_mask_storage<double, m128d_abi> : public __simd_storage<double, m128d_abi> class __simd_mask_storage<double, m128d_abi> : public __simd_storage<double, m128d_abi> {
{
public: public:
bool __get(size_t __index) const noexcept { bool __get(size_t __index) const noexcept {
alignas(16) uint64_t sse_data[2]; alignas(16) uint64_t sse_data[2];
@ -332,108 +312,100 @@ inline simd<double, m128d_abi> simd<double, m128d_abi>::operator-() const {
return ret; return ret;
} }
inline simd<double, m128d_abi> inline simd<double, m128d_abi> operator+(const simd<double, m128d_abi>& a, const simd<double, m128d_abi>& b) {
operator+(const simd<double, m128d_abi>& a, const simd<double, m128d_abi>& b) {
simd<double, m128d_abi> ret; simd<double, m128d_abi> ret;
for (int i = 0; i < 2; ++i) for (int i = 0; i < 2; ++i)
ret.__s_.__storage_[i] = _mm_add_pd(a.__s_.__storage_[i], b.__s_.__storage_[i]); ret.__s_.__storage_[i] = _mm_add_pd(a.__s_.__storage_[i], b.__s_.__storage_[i]);
return ret; return ret;
} }
inline simd<double, m128d_abi> inline simd<double, m128d_abi> operator-(const simd<double, m128d_abi>& a, const simd<double, m128d_abi>& b) {
operator-(const simd<double, m128d_abi>& a, const simd<double, m128d_abi>& b) {
simd<double, m128d_abi> ret; simd<double, m128d_abi> ret;
for (int i = 0; i < 2; ++i) for (int i = 0; i < 2; ++i)
ret.__s_.__storage_[i] = _mm_sub_pd(a.__s_.__storage_[i], b.__s_.__storage_[i]); ret.__s_.__storage_[i] = _mm_sub_pd(a.__s_.__storage_[i], b.__s_.__storage_[i]);
return ret; return ret;
} }
inline simd<double, m128d_abi> inline simd<double, m128d_abi> operator*(const simd<double, m128d_abi>& a, const simd<double, m128d_abi>& b) {
operator*(const simd<double, m128d_abi>& a, const simd<double, m128d_abi>& b) {
simd<double, m128d_abi> ret; simd<double, m128d_abi> ret;
for (int i = 0; i < 2; ++i) for (int i = 0; i < 2; ++i)
ret.__s_.__storage_[i] = _mm_mul_pd(a.__s_.__storage_[i], b.__s_.__storage_[i]); ret.__s_.__storage_[i] = _mm_mul_pd(a.__s_.__storage_[i], b.__s_.__storage_[i]);
return ret; return ret;
} }
inline simd<double, m128d_abi> inline simd<double, m128d_abi> operator/(const simd<double, m128d_abi>& a, const simd<double, m128d_abi>& b) {
operator/(const simd<double, m128d_abi>& a, const simd<double, m128d_abi>& b) {
simd<double, m128d_abi> ret; simd<double, m128d_abi> ret;
for (int i = 0; i < 2; ++i) for (int i = 0; i < 2; ++i)
ret.__s_.__storage_[i] = _mm_div_pd(a.__s_.__storage_[i], b.__s_.__storage_[i]); ret.__s_.__storage_[i] = _mm_div_pd(a.__s_.__storage_[i], b.__s_.__storage_[i]);
return ret; return ret;
} }
inline simd<double, m128d_abi>& inline simd<double, m128d_abi>& operator+=(simd<double, m128d_abi>& a, const simd<double, m128d_abi>& b) {
operator+=(simd<double, m128d_abi>& a, const simd<double, m128d_abi>& b) {
for (int i = 0; i < 2; ++i) for (int i = 0; i < 2; ++i)
a.__s_.__storage_[i] = _mm_add_pd(a.__s_.__storage_[i], b.__s_.__storage_[i]); a.__s_.__storage_[i] = _mm_add_pd(a.__s_.__storage_[i], b.__s_.__storage_[i]);
return a; return a;
} }
inline simd<double, m128d_abi>& inline simd<double, m128d_abi>& operator-=(simd<double, m128d_abi>& a, const simd<double, m128d_abi>& b) {
operator-=(simd<double, m128d_abi>& a, const simd<double, m128d_abi>& b) {
for (int i = 0; i < 2; ++i) for (int i = 0; i < 2; ++i)
a.__s_.__storage_[i] = _mm_sub_pd(a.__s_.__storage_[i], b.__s_.__storage_[i]); a.__s_.__storage_[i] = _mm_sub_pd(a.__s_.__storage_[i], b.__s_.__storage_[i]);
return a; return a;
} }
inline simd<double, m128d_abi>& inline simd<double, m128d_abi>& operator*=(simd<double, m128d_abi>& a, const simd<double, m128d_abi>& b) {
operator*=(simd<double, m128d_abi>& a, const simd<double, m128d_abi>& b) {
for (int i = 0; i < 2; ++i) for (int i = 0; i < 2; ++i)
a.__s_.__storage_[i] = _mm_mul_pd(a.__s_.__storage_[i], b.__s_.__storage_[i]); a.__s_.__storage_[i] = _mm_mul_pd(a.__s_.__storage_[i], b.__s_.__storage_[i]);
return a; return a;
} }
inline simd<double, m128d_abi>& inline simd<double, m128d_abi>& operator/=(simd<double, m128d_abi>& a, const simd<double, m128d_abi>& b) {
operator/=(simd<double, m128d_abi>& a, const simd<double, m128d_abi>& b) {
for (int i = 0; i < 2; ++i) for (int i = 0; i < 2; ++i)
a.__s_.__storage_[i] = _mm_div_pd(a.__s_.__storage_[i], b.__s_.__storage_[i]); a.__s_.__storage_[i] = _mm_div_pd(a.__s_.__storage_[i], b.__s_.__storage_[i]);
return a; return a;
} }
inline simd<double, m128d_abi>::mask_type inline simd<double, m128d_abi>::mask_type operator==(const simd<double, m128d_abi>& a,
operator==(const simd<double, m128d_abi>& a, const simd<double, m128d_abi>& b) { const simd<double, m128d_abi>& b) {
simd<double, m128d_abi>::mask_type ret; simd<double, m128d_abi>::mask_type ret;
for (int i = 0; i < 2; ++i) for (int i = 0; i < 2; ++i)
ret.__s_.__storage_[i] = _mm_cmpeq_pd(a.__s_.__storage_[i], b.__s_.__storage_[i]); ret.__s_.__storage_[i] = _mm_cmpeq_pd(a.__s_.__storage_[i], b.__s_.__storage_[i]);
return ret; return ret;
} }
inline simd<double, m128d_abi>::mask_type inline simd<double, m128d_abi>::mask_type operator!=(const simd<double, m128d_abi>& a,
operator!=(const simd<double, m128d_abi>& a, const simd<double, m128d_abi>& b) { const simd<double, m128d_abi>& b) {
simd<double, m128d_abi>::mask_type ret; simd<double, m128d_abi>::mask_type ret;
for (int i = 0; i < 2; ++i) for (int i = 0; i < 2; ++i)
ret.__s_.__storage_[i] = _mm_cmpneq_pd(a.__s_.__storage_[i], b.__s_.__storage_[i]); ret.__s_.__storage_[i] = _mm_cmpneq_pd(a.__s_.__storage_[i], b.__s_.__storage_[i]);
return ret; return ret;
} }
inline simd<double, m128d_abi>::mask_type inline simd<double, m128d_abi>::mask_type operator>=(const simd<double, m128d_abi>& a,
operator>=(const simd<double, m128d_abi>& a, const simd<double, m128d_abi>& b) { const simd<double, m128d_abi>& b) {
simd<double, m128d_abi>::mask_type ret; simd<double, m128d_abi>::mask_type ret;
for (int i = 0; i < 2; ++i) for (int i = 0; i < 2; ++i)
ret.__s_.__storage_[i] = _mm_cmpge_pd(a.__s_.__storage_[i], b.__s_.__storage_[i]); ret.__s_.__storage_[i] = _mm_cmpge_pd(a.__s_.__storage_[i], b.__s_.__storage_[i]);
return ret; return ret;
} }
inline simd<double, m128d_abi>::mask_type inline simd<double, m128d_abi>::mask_type operator<=(const simd<double, m128d_abi>& a,
operator<=(const simd<double, m128d_abi>& a, const simd<double, m128d_abi>& b) { const simd<double, m128d_abi>& b) {
simd<double, m128d_abi>::mask_type ret; simd<double, m128d_abi>::mask_type ret;
for (int i = 0; i < 2; ++i) for (int i = 0; i < 2; ++i)
ret.__s_.__storage_[i] = _mm_cmple_pd(a.__s_.__storage_[i], b.__s_.__storage_[i]); ret.__s_.__storage_[i] = _mm_cmple_pd(a.__s_.__storage_[i], b.__s_.__storage_[i]);
return ret; return ret;
} }
inline simd<double, m128d_abi>::mask_type inline simd<double, m128d_abi>::mask_type operator>(const simd<double, m128d_abi>& a,
operator>(const simd<double, m128d_abi>& a, const simd<double, m128d_abi>& b) { const simd<double, m128d_abi>& b) {
simd<double, m128d_abi>::mask_type ret; simd<double, m128d_abi>::mask_type ret;
for (int i = 0; i < 2; ++i) for (int i = 0; i < 2; ++i)
ret.__s_.__storage_[i] = _mm_cmpgt_pd(a.__s_.__storage_[i], b.__s_.__storage_[i]); ret.__s_.__storage_[i] = _mm_cmpgt_pd(a.__s_.__storage_[i], b.__s_.__storage_[i]);
return ret; return ret;
} }
inline simd<double, m128d_abi>::mask_type inline simd<double, m128d_abi>::mask_type operator<(const simd<double, m128d_abi>& a,
operator<(const simd<double, m128d_abi>& a, const simd<double, m128d_abi>& b) { const simd<double, m128d_abi>& b) {
simd<double, m128d_abi>::mask_type ret; simd<double, m128d_abi>::mask_type ret;
for (int i = 0; i < 2; ++i) for (int i = 0; i < 2; ++i)
ret.__s_.__storage_[i] = _mm_cmplt_pd(a.__s_.__storage_[i], b.__s_.__storage_[i]); ret.__s_.__storage_[i] = _mm_cmplt_pd(a.__s_.__storage_[i], b.__s_.__storage_[i]);
@ -445,10 +417,17 @@ inline __simd_storage<float, m128_abi>::__simd_storage(const __simd_storage<doub
} }
namespace simd_abi { namespace simd_abi {
template<typename T> struct zeus_native {}; template <typename T>
template<> struct zeus_native<float> { using type = m128_abi; }; struct zeus_native {};
template <>
struct zeus_native<float> {
using type = m128_abi;
};
#ifndef __AVX__ #ifndef __AVX__
template<> struct zeus_native<double> { using type = m128d_abi; }; template <>
struct zeus_native<double> {
using type = m128d_abi;
};
#endif #endif
} // namespace simd_abi } // namespace simd_abi

View File

@ -23,4 +23,3 @@
#include "zeus/CColor.hpp" #include "zeus/CColor.hpp"
#include "zeus/Global.hpp" #include "zeus/Global.hpp"
#include "zeus/Math.hpp" #include "zeus/Math.hpp"

View File

@ -1,8 +1,7 @@
#include "zeus/CAABox.hpp" #include "zeus/CAABox.hpp"
#include "zeus/CVector3f.hpp" #include "zeus/CVector3f.hpp"
namespace zeus namespace zeus {
{
const CAABox CAABox::skInvertedBox = CAABox(); const CAABox CAABox::skInvertedBox = CAABox();
const CAABox CAABox::skNullBox = CAABox(CVector3f::skZero, CVector3f::skZero); const CAABox CAABox::skNullBox = CAABox(CVector3f::skZero, CVector3f::skZero);
} } // namespace zeus

View File

@ -1,6 +1,5 @@
#include "zeus/CAxisAngle.hpp" #include "zeus/CAxisAngle.hpp"
namespace zeus namespace zeus {
{
const CAxisAngle CAxisAngle::sIdentity = {}; const CAxisAngle CAxisAngle::sIdentity = {};
} }

View File

@ -115,4 +115,4 @@ void CColor::toHSL(float& h, float& s, float& l) const {
h /= 6.f; h /= 6.f;
} }
} }
} } // namespace zeus

View File

@ -1,73 +1,62 @@
#include "zeus/CEulerAngles.hpp" #include "zeus/CEulerAngles.hpp"
#include "zeus/CQuaternion.hpp" #include "zeus/CQuaternion.hpp"
namespace zeus namespace zeus {
{
CEulerAngles::CEulerAngles(const CQuaternion& quat) CEulerAngles::CEulerAngles(const CQuaternion& quat) {
{ float quatDot = quat.dot(quat);
float quatDot = quat.dot(quat); float t0 = 0.f;
float t0 = 0.f; if (quatDot > 0.f)
if (quatDot > 0.f) t0 = 2.f / quatDot;
t0 = 2.f / quatDot; double t1 = 1.0 - (t0 * quat.x() * quat.x() + t0 * quat.z() * quat.z());
double t1 = 1.0 - (t0 * quat.x() * quat.x() + t0 * quat.z() * quat.z()); double t2 = t0 * quat.y() * quat.x() - t0 * quat.z() * quat.w();
double t2 = t0 * quat.y() * quat.x() - t0 * quat.z() * quat.w(); double t3 = t1 * t1 + t2 * t2;
double t3 = t1 * t1 + t2 * t2;
double t4 = 0.0; double t4 = 0.0;
if (t3 > 0.0) if (t3 > 0.0)
t4 = std::sqrt(t3); t4 = std::sqrt(t3);
double t5 = t0 * quat.z() * quat.y() + t0 * quat.x() * quat.w(); double t5 = t0 * quat.z() * quat.y() + t0 * quat.x() * quat.w();
if (std::abs(t4) > 0.00001) if (std::abs(t4) > 0.00001) {
{ x() = -std::atan2(-t5, t4);
x() = -std::atan2(-t5, t4); y() = -std::atan2(t0 * quat.z() * quat.x() - t0 * quat.y() * quat.w(),
y() = -std::atan2(t0 * quat.z() * quat.x() - t0 * quat.y() * quat.w(), 1.0 - (t0 * quat.x() * quat.x() + t0 * quat.y() * quat.y()));
1.0 - (t0 * quat.x() * quat.x() + t0 * quat.y() * quat.y())); z() = -std::atan2(t2, t1);
z() = -std::atan2(t2, t1); } else {
} x() = -std::atan2(-t5, t4);
else y() = -std::atan2(-(t0 * quat.z() * quat.x() + t0 * quat.y() * quat.w()),
{ 1.0 - (t0 * quat.y() * quat.y() + t0 * quat.z() * quat.z()));
x() = -std::atan2(-t5, t4); z() = 0.f;
y() = -std::atan2(-(t0 * quat.z() * quat.x() + t0 * quat.y() * quat.w()), }
1.0 - (t0 * quat.y() * quat.y() + t0 * quat.z() * quat.z()));
z() = 0.f;
}
} }
CEulerAngles::CEulerAngles(const CTransform& xf) CEulerAngles::CEulerAngles(const CTransform& xf) {
{ float xyMagSq = xf.basis[1][1] * xf.basis[1][1] + xf.basis[1][0] * xf.basis[1][0];
float xyMagSq = xf.basis[1][1] * xf.basis[1][1] + xf.basis[1][0] * xf.basis[1][0]; float f1 = 0.f;
float f1 = 0.f; if (xyMagSq > 0.f) {
if (xyMagSq > 0.f) f1 = 1.f / std::sqrt(xyMagSq);
{ float f0;
f1 = 1.f / std::sqrt(xyMagSq);
float f0;
for (int i=0 ; i<4 ; ++i) for (int i = 0; i < 4; ++i) {
{ f0 = f1 * f1;
f0 = f1 * f1; f1 *= 0.5f;
f1 *= 0.5f; f0 = 3.f - xyMagSq * f0;
f0 = 3.f - xyMagSq * f0; f1 *= f0;
f1 *= f0;
}
f1 = xyMagSq * f0;
} }
if (std::fabs(f1) >= 0.00001) f1 = xyMagSq * f0;
{ }
x() = -std::atan2(-xf.basis[1][2], f1);
y() = -std::atan2(xf.basis[0][2], xf.basis[2][2]); if (std::fabs(f1) >= 0.00001) {
z() = -std::atan2(xf.basis[1][0], xf.basis[1][1]); x() = -std::atan2(-xf.basis[1][2], f1);
} y() = -std::atan2(xf.basis[0][2], xf.basis[2][2]);
else z() = -std::atan2(xf.basis[1][0], xf.basis[1][1]);
{ } else {
x() = -std::atan2(-xf.basis[1][2], f1); x() = -std::atan2(-xf.basis[1][2], f1);
y() = -std::atan2(-xf.basis[2][0], xf.basis[0][0]); y() = -std::atan2(-xf.basis[2][0], xf.basis[0][0]);
z() = 0.f; z() = 0.f;
} }
} }
} } // namespace zeus

View File

@ -85,4 +85,4 @@ bool CFrustum::pointFrustumTest(const CVector3f& point) const {
return true; return true;
} }
} } // namespace zeus

View File

@ -35,11 +35,11 @@ void CMatrix3f::transpose() {
m[1].mSimd = _mm_movehl_ps(T2, T0); m[1].mSimd = _mm_movehl_ps(T2, T0);
m[2].mSimd = _mm_movelh_ps(T1, T3); m[2].mSimd = _mm_movelh_ps(T1, T3);
#elif __ARM_NEON #elif __ARM_NEON
float32x4x2_t P0 = vzipq_f32( M.r[0], M.r[2] ); float32x4x2_t P0 = vzipq_f32(M.r[0], M.r[2]);
float32x4x2_t P1 = vzipq_f32( M.r[1], M.r[3] ); float32x4x2_t P1 = vzipq_f32(M.r[1], M.r[3]);
float32x4x2_t T0 = vzipq_f32( P0.val[0], P1.val[0] ); float32x4x2_t T0 = vzipq_f32(P0.val[0], P1.val[0]);
float32x4x2_t T1 = vzipq_f32( P0.val[1], P1.val[1] ); float32x4x2_t T1 = vzipq_f32(P0.val[1], P1.val[1]);
m[0].mSimd = T0.val[0]; m[0].mSimd = T0.val[0];
m[1].mSimd = T0.val[1]; m[1].mSimd = T0.val[1];
@ -70,11 +70,11 @@ CMatrix3f CMatrix3f::transposed() const {
__m128 T3 = _mm_unpackhi_ps(m[2].mSimd.native(), zero); __m128 T3 = _mm_unpackhi_ps(m[2].mSimd.native(), zero);
return CMatrix3f(_mm_movelh_ps(T0, T2), _mm_movehl_ps(T2, T0), _mm_movelh_ps(T1, T3)); return CMatrix3f(_mm_movelh_ps(T0, T2), _mm_movehl_ps(T2, T0), _mm_movelh_ps(T1, T3));
#elif __ARM_NEON #elif __ARM_NEON
float32x4x2_t P0 = vzipq_f32( M.r[0], M.r[2] ); float32x4x2_t P0 = vzipq_f32(M.r[0], M.r[2]);
float32x4x2_t P1 = vzipq_f32( M.r[1], M.r[3] ); float32x4x2_t P1 = vzipq_f32(M.r[1], M.r[3]);
float32x4x2_t T0 = vzipq_f32( P0.val[0], P1.val[0] ); float32x4x2_t T0 = vzipq_f32(P0.val[0], P1.val[0]);
float32x4x2_t T1 = vzipq_f32( P0.val[1], P1.val[1] ); float32x4x2_t T1 = vzipq_f32(P0.val[1], P1.val[1]);
return CMatrix3f(T0.val[0], T0.val[1], T1.val[0]); return CMatrix3f(T0.val[0], T0.val[1], T1.val[0]);
#else #else
@ -111,4 +111,4 @@ CMatrix3f CMatrix3f::inverted() const {
(m[0][1] * m[1][2] - m[0][2] * m[1][1]) * det, -(m[0][0] * m[1][2] - m[0][2] * m[1][0]) * det, (m[0][1] * m[1][2] - m[0][2] * m[1][1]) * det, -(m[0][0] * m[1][2] - m[0][2] * m[1][0]) * det,
(m[0][0] * m[1][1] - m[0][1] * m[1][0]) * det); (m[0][0] * m[1][1] - m[0][1] * m[1][0]) * det);
} }
} } // namespace zeus

View File

@ -1,54 +1,52 @@
#include "zeus/CMatrix4f.hpp" #include "zeus/CMatrix4f.hpp"
namespace zeus namespace zeus {
{
const CMatrix4f CMatrix4f::skIdentityMatrix4f = CMatrix4f(); const CMatrix4f CMatrix4f::skIdentityMatrix4f = CMatrix4f();
CMatrix4f CMatrix4f::transposed() const CMatrix4f CMatrix4f::transposed() const {
{ CMatrix4f ret;
CMatrix4f ret;
#if __SSE__ #if __SSE__
__m128 T0 = _mm_unpacklo_ps(m[0].mSimd.native(), m[1].mSimd.native()); __m128 T0 = _mm_unpacklo_ps(m[0].mSimd.native(), m[1].mSimd.native());
__m128 T2 = _mm_unpacklo_ps(m[2].mSimd.native(), m[3].mSimd.native()); __m128 T2 = _mm_unpacklo_ps(m[2].mSimd.native(), m[3].mSimd.native());
__m128 T1 = _mm_unpackhi_ps(m[0].mSimd.native(), m[1].mSimd.native()); __m128 T1 = _mm_unpackhi_ps(m[0].mSimd.native(), m[1].mSimd.native());
__m128 T3 = _mm_unpackhi_ps(m[2].mSimd.native(), m[3].mSimd.native()); __m128 T3 = _mm_unpackhi_ps(m[2].mSimd.native(), m[3].mSimd.native());
ret.m[0].mSimd = _mm_movelh_ps(T0, T2); ret.m[0].mSimd = _mm_movelh_ps(T0, T2);
ret.m[1].mSimd = _mm_movehl_ps(T2, T0); ret.m[1].mSimd = _mm_movehl_ps(T2, T0);
ret.m[2].mSimd = _mm_movelh_ps(T1, T3); ret.m[2].mSimd = _mm_movelh_ps(T1, T3);
ret.m[3].mSimd = _mm_movehl_ps(T3, T1); ret.m[3].mSimd = _mm_movehl_ps(T3, T1);
#elif __ARM_NEON #elif __ARM_NEON
float32x4x2_t P0 = vzipq_f32( M.r[0], M.r[2] ); float32x4x2_t P0 = vzipq_f32(M.r[0], M.r[2]);
float32x4x2_t P1 = vzipq_f32( M.r[1], M.r[3] ); float32x4x2_t P1 = vzipq_f32(M.r[1], M.r[3]);
float32x4x2_t T0 = vzipq_f32( P0.val[0], P1.val[0] ); float32x4x2_t T0 = vzipq_f32(P0.val[0], P1.val[0]);
float32x4x2_t T1 = vzipq_f32( P0.val[1], P1.val[1] ); float32x4x2_t T1 = vzipq_f32(P0.val[1], P1.val[1]);
ret.m[0].mSimd = T0.val[0]; ret.m[0].mSimd = T0.val[0];
ret.m[1].mSimd = T0.val[1]; ret.m[1].mSimd = T0.val[1];
ret.m[2].mSimd = T1.val[0]; ret.m[2].mSimd = T1.val[0];
ret.m[3].mSimd = T1.val[1]; ret.m[3].mSimd = T1.val[1];
#else #else
ret.m[0][0] = m[0][0]; ret.m[0][0] = m[0][0];
ret.m[1][0] = m[0][1]; ret.m[1][0] = m[0][1];
ret.m[2][0] = m[0][2]; ret.m[2][0] = m[0][2];
ret.m[3][0] = m[0][3]; ret.m[3][0] = m[0][3];
ret.m[0][1] = m[1][0]; ret.m[0][1] = m[1][0];
ret.m[1][1] = m[1][1]; ret.m[1][1] = m[1][1];
ret.m[2][1] = m[1][2]; ret.m[2][1] = m[1][2];
ret.m[3][1] = m[1][3]; ret.m[3][1] = m[1][3];
ret.m[0][2] = m[2][0]; ret.m[0][2] = m[2][0];
ret.m[1][2] = m[2][1]; ret.m[1][2] = m[2][1];
ret.m[2][2] = m[2][2]; ret.m[2][2] = m[2][2];
ret.m[3][2] = m[2][3]; ret.m[3][2] = m[2][3];
ret.m[0][3] = m[3][0]; ret.m[0][3] = m[3][0];
ret.m[1][3] = m[3][1]; ret.m[1][3] = m[3][1];
ret.m[2][3] = m[3][2]; ret.m[2][3] = m[3][2];
ret.m[3][3] = m[3][3]; ret.m[3][3] = m[3][3];
#endif #endif
return ret; return ret;
}
} }
} // namespace zeus

View File

@ -6,14 +6,8 @@ CAABox COBBox::calculateAABox(const CTransform& worldXf) const {
CAABox ret = CAABox::skInvertedBox; CAABox ret = CAABox::skInvertedBox;
CTransform trans = worldXf * transform; CTransform trans = worldXf * transform;
static const CVector3f basis[8] = {{1.f, 1.f, 1.f}, static const CVector3f basis[8] = {{1.f, 1.f, 1.f}, {1.f, 1.f, -1.f}, {1.f, -1.f, 1.f}, {1.f, -1.f, -1.f},
{1.f, 1.f, -1.f}, {-1.f, -1.f, -1.f}, {-1.f, -1.f, 1.f}, {-1.f, 1.f, -1.f}, {-1.f, 1.f, 1.f}};
{1.f, -1.f, 1.f},
{1.f, -1.f, -1.f},
{-1.f, -1.f, -1.f},
{-1.f, -1.f, 1.f},
{-1.f, 1.f, -1.f},
{-1.f, 1.f, 1.f}};
CVector3f p = extents * basis[0]; CVector3f p = extents * basis[0];
ret.accumulateBounds(trans * p); ret.accumulateBounds(trans * p);
p = extents * basis[1]; p = extents * basis[1];
@ -36,9 +30,7 @@ CAABox COBBox::calculateAABox(const CTransform& worldXf) const {
bool COBBox::OBBIntersectsBox(const COBBox& other) const { bool COBBox::OBBIntersectsBox(const COBBox& other) const {
CVector3f v = other.transform.origin - transform.origin; CVector3f v = other.transform.origin - transform.origin;
CVector3f T = CVector3f(v.dot(transform.basis[0]), CVector3f T = CVector3f(v.dot(transform.basis[0]), v.dot(transform.basis[1]), v.dot(transform.basis[2]));
v.dot(transform.basis[1]),
v.dot(transform.basis[2]));
CMatrix3f R; CMatrix3f R;
@ -50,8 +42,7 @@ bool COBBox::OBBIntersectsBox(const COBBox& other) const {
for (int i = 0; i < 3; ++i) { for (int i = 0; i < 3; ++i) {
ra = extents[i]; ra = extents[i];
rb = (other.extents[0] * std::fabs(R[i][0])) + rb = (other.extents[0] * std::fabs(R[i][0])) + (other.extents[1] * std::fabs(R[i][1])) +
(other.extents[1] * std::fabs(R[i][1])) +
(other.extents[2] * std::fabs(R[i][2])); (other.extents[2] * std::fabs(R[i][2]));
t = std::fabs(T[i]); t = std::fabs(T[i]);
@ -60,9 +51,7 @@ bool COBBox::OBBIntersectsBox(const COBBox& other) const {
} }
for (int k = 0; k < 3; ++k) { for (int k = 0; k < 3; ++k) {
ra = (extents[0] * std::fabs(R[0][k])) + ra = (extents[0] * std::fabs(R[0][k])) + (extents[1] * std::fabs(R[1][k])) + (extents[2] * std::fabs(R[2][k]));
(extents[1] * std::fabs(R[1][k])) +
(extents[2] * std::fabs(R[2][k]));
rb = other.extents[k]; rb = other.extents[k];
t = std::fabs(T[0] * R[0][k] + T[1] * R[1][k] + T[2] * R[2][k]); t = std::fabs(T[0] * R[0][k] + T[1] * R[1][k] + T[2] * R[2][k]);
@ -137,4 +126,4 @@ bool COBBox::OBBIntersectsBox(const COBBox& other) const {
return true; return true;
} }
} } // namespace zeus

View File

@ -13,4 +13,4 @@ bool CPlane::rayPlaneIntersection(const CVector3f& from, const CVector3f& to, CV
return true; return true;
} }
} } // namespace zeus

View File

@ -65,4 +65,4 @@ void CProjection::_updateCachedMatrix() {
m_mtx.m[3][3] = 0.0f; m_mtx.m[3][3] = 0.0f;
} }
} }
} } // namespace zeus

View File

@ -83,13 +83,9 @@ CQuaternion& CQuaternion::operator=(const CQuaternion& q) {
return *this; return *this;
} }
CQuaternion CQuaternion::operator+(const CQuaternion& q) const { CQuaternion CQuaternion::operator+(const CQuaternion& q) const { return mSimd + q.mSimd; }
return mSimd + q.mSimd;
}
CQuaternion CQuaternion::operator-(const CQuaternion& q) const { CQuaternion CQuaternion::operator-(const CQuaternion& q) const { return mSimd - q.mSimd; }
return mSimd - q.mSimd;
}
CQuaternion CQuaternion::operator*(const CQuaternion& q) const { CQuaternion CQuaternion::operator*(const CQuaternion& q) const {
return CQuaternion(w() * q.w() - CVector3f(x(), y(), z()).dot({q.x(), q.y(), q.z()}), return CQuaternion(w() * q.w() - CVector3f(x(), y(), z()).dot({q.x(), q.y(), q.z()}),
@ -111,17 +107,11 @@ CQuaternion CQuaternion::operator/(const CQuaternion& q) const {
return *this * p; return *this * p;
} }
CQuaternion CQuaternion::operator*(float scale) const { CQuaternion CQuaternion::operator*(float scale) const { return mSimd * simd<float>(scale); }
return mSimd * simd<float>(scale);
}
CNUQuaternion CNUQuaternion::operator*(float scale) const { CNUQuaternion CNUQuaternion::operator*(float scale) const { return mSimd * simd<float>(scale); }
return mSimd * simd<float>(scale);
}
CQuaternion CQuaternion::operator/(float scale) const { CQuaternion CQuaternion::operator/(float scale) const { return mSimd / simd<float>(scale); }
return mSimd / simd<float>(scale);
}
CQuaternion CQuaternion::operator-() const { return -mSimd; } CQuaternion CQuaternion::operator-() const { return -mSimd; }
@ -163,9 +153,7 @@ const CQuaternion& CQuaternion::operator/=(float scale) {
static const simd<float> InvertQuat(1.f, -1.f, -1.f, -1.f); static const simd<float> InvertQuat(1.f, -1.f, -1.f, -1.f);
void CQuaternion::invert() { void CQuaternion::invert() { mSimd *= InvertQuat; }
mSimd *= InvertQuat;
}
CQuaternion CQuaternion::inverse() const { return mSimd * InvertQuat; } CQuaternion CQuaternion::inverse() const { return mSimd * InvertQuat; }
@ -269,21 +257,13 @@ CQuaternion CQuaternion::slerpShort(const CQuaternion& a, const CQuaternion& b,
return zeus::CQuaternion::slerp((b.dot(a) >= 0.f) ? a : a.buildEquivalent(), b, t); return zeus::CQuaternion::slerp((b.dot(a) >= 0.f) ? a : a.buildEquivalent(), b, t);
} }
CQuaternion operator+(float lhs, const CQuaternion& rhs) { CQuaternion operator+(float lhs, const CQuaternion& rhs) { return simd<float>(lhs) + rhs.mSimd; }
return simd<float>(lhs) + rhs.mSimd;
}
CQuaternion operator-(float lhs, const CQuaternion& rhs) { CQuaternion operator-(float lhs, const CQuaternion& rhs) { return simd<float>(lhs) - rhs.mSimd; }
return simd<float>(lhs) - rhs.mSimd;
}
CQuaternion operator*(float lhs, const CQuaternion& rhs) { CQuaternion operator*(float lhs, const CQuaternion& rhs) { return simd<float>(lhs) * rhs.mSimd; }
return simd<float>(lhs) * rhs.mSimd;
}
CNUQuaternion operator*(float lhs, const CNUQuaternion& rhs) { CNUQuaternion operator*(float lhs, const CNUQuaternion& rhs) { return simd<float>(lhs) * rhs.mSimd; }
return simd<float>(lhs) * rhs.mSimd;
}
CQuaternion CQuaternion::buildEquivalent() const { CQuaternion CQuaternion::buildEquivalent() const {
float tmp = std::acos(clamp(-1.f, w(), 1.f)) * 2.f; float tmp = std::acos(clamp(-1.f, w(), 1.f)) * 2.f;
@ -309,7 +289,7 @@ CQuaternion CQuaternion::lookAt(const CUnitVector3f& source, const CUnitVector3f
destNoZ.normalize(); destNoZ.normalize();
float angleBetween = float angleBetween =
normalize_angle(std::atan2(destNoZ.x(), destNoZ.y()) - std::atan2(sourceNoZ.x(), sourceNoZ.y())); normalize_angle(std::atan2(destNoZ.x(), destNoZ.y()) - std::atan2(sourceNoZ.x(), sourceNoZ.y()));
float realAngle = zeus::clamp(-maxAng.asRadians(), angleBetween, maxAng.asRadians()); float realAngle = zeus::clamp(-maxAng.asRadians(), angleBetween, maxAng.asRadians());
CQuaternion tmpQ; CQuaternion tmpQ;
tmpQ.rotateZ(-realAngle); tmpQ.rotateZ(-realAngle);
@ -322,9 +302,9 @@ CQuaternion CQuaternion::lookAt(const CUnitVector3f& source, const CUnitVector3f
else else
return skNoRotation; return skNoRotation;
float realAngle = float realAngle = zeus::clamp(-maxAng.asRadians(), normalize_angle(std::acos(dest.z()) - std::acos(source.z())),
zeus::clamp(-maxAng.asRadians(), normalize_angle(std::acos(dest.z()) - std::acos(source.z())), maxAng.asRadians()); maxAng.asRadians());
return CQuaternion::fromAxisAngle(tmp.cross(CVector3f::skUp), -realAngle) * q; return CQuaternion::fromAxisAngle(tmp.cross(CVector3f::skUp), -realAngle) * q;
} }
} } // namespace zeus

View File

@ -62,4 +62,4 @@ CTransform CTransformFromEditorEulers(const CVector3f& eulerVec, const CVector3f
ret.origin = origin; ret.origin = origin;
return ret; return ret;
} }
} } // namespace zeus

View File

@ -46,4 +46,4 @@ CVector2f CVector2f::slerp(const CVector2f& a, const CVector2f& b, float t) {
} }
return a; return a;
} }
} } // namespace zeus

View File

@ -59,4 +59,4 @@ CVector3f CVector3f::slerp(const CVector3f& a, const CVector3f& b, float t) {
} }
return a; return a;
} }
} } // namespace zeus

View File

@ -10,4 +10,4 @@ CVector4f& CVector4f::operator=(const CColor& other) {
mSimd = other.mSimd; mSimd = other.mSimd;
return *this; return *this;
} }
} } // namespace zeus

View File

@ -45,38 +45,38 @@ void detectCPU() {
int regs[4]; int regs[4];
getCpuInfo(0, regs); getCpuInfo(0, regs);
int highestFeature = regs[0]; int highestFeature = regs[0];
*reinterpret_cast<int*>((char*) g_cpuFeatures.cpuVendor) = regs[1]; *reinterpret_cast<int*>((char*)g_cpuFeatures.cpuVendor) = regs[1];
*reinterpret_cast<int*>((char*) g_cpuFeatures.cpuVendor + 4) = regs[3]; *reinterpret_cast<int*>((char*)g_cpuFeatures.cpuVendor + 4) = regs[3];
*reinterpret_cast<int*>((char*) g_cpuFeatures.cpuVendor + 8) = regs[2]; *reinterpret_cast<int*>((char*)g_cpuFeatures.cpuVendor + 8) = regs[2];
getCpuInfo(0x80000000, regs); getCpuInfo(0x80000000, regs);
if (regs[0] >= 0x80000004) { if (regs[0] >= 0x80000004) {
for (unsigned int i = 0x80000002; i <= 0x80000004; i++) { for (unsigned int i = 0x80000002; i <= 0x80000004; i++) {
getCpuInfo(i, regs); getCpuInfo(i, regs);
// Interpret CPU brand string and cache information. // Interpret CPU brand string and cache information.
if (i == 0x80000002) if (i == 0x80000002)
memcpy((char*) g_cpuFeatures.cpuBrand, regs, sizeof(regs)); memcpy((char*)g_cpuFeatures.cpuBrand, regs, sizeof(regs));
else if (i == 0x80000003) else if (i == 0x80000003)
memcpy((char*) g_cpuFeatures.cpuBrand + 16, regs, sizeof(regs)); memcpy((char*)g_cpuFeatures.cpuBrand + 16, regs, sizeof(regs));
else if (i == 0x80000004) else if (i == 0x80000004)
memcpy((char*) g_cpuFeatures.cpuBrand + 32, regs, sizeof(regs)); memcpy((char*)g_cpuFeatures.cpuBrand + 32, regs, sizeof(regs));
} }
} }
if (highestFeature >= 1) { if (highestFeature >= 1) {
getCpuInfo(1, regs); getCpuInfo(1, regs);
memset((bool*) &g_cpuFeatures.AESNI, ((regs[2] & 0x02000000) != 0), 1); memset((bool*)&g_cpuFeatures.AESNI, ((regs[2] & 0x02000000) != 0), 1);
memset((bool*) &g_cpuFeatures.SSE1, ((regs[3] & 0x02000000) != 0), 1); memset((bool*)&g_cpuFeatures.SSE1, ((regs[3] & 0x02000000) != 0), 1);
memset((bool*) &g_cpuFeatures.SSE2, ((regs[3] & 0x04000000) != 0), 1); memset((bool*)&g_cpuFeatures.SSE2, ((regs[3] & 0x04000000) != 0), 1);
memset((bool*) &g_cpuFeatures.SSE3, ((regs[2] & 0x00000001) != 0), 1); memset((bool*)&g_cpuFeatures.SSE3, ((regs[2] & 0x00000001) != 0), 1);
memset((bool*) &g_cpuFeatures.SSSE3, ((regs[2] & 0x00000200) != 0), 1); memset((bool*)&g_cpuFeatures.SSSE3, ((regs[2] & 0x00000200) != 0), 1);
memset((bool*) &g_cpuFeatures.SSE41, ((regs[2] & 0x00080000) != 0), 1); memset((bool*)&g_cpuFeatures.SSE41, ((regs[2] & 0x00080000) != 0), 1);
memset((bool*) &g_cpuFeatures.SSE42, ((regs[2] & 0x00100000) != 0), 1); memset((bool*)&g_cpuFeatures.SSE42, ((regs[2] & 0x00100000) != 0), 1);
memset((bool*) &g_cpuFeatures.AVX, ((regs[2] & 0x10000000) != 0), 1); memset((bool*)&g_cpuFeatures.AVX, ((regs[2] & 0x10000000) != 0), 1);
} }
if (highestFeature >= 7) { if (highestFeature >= 7) {
getCpuInfoEx(7, 0, regs); getCpuInfoEx(7, 0, regs);
memset((bool*) &g_cpuFeatures.AVX2, ((regs[1] & 0x00000020) != 0), 1); memset((bool*)&g_cpuFeatures.AVX2, ((regs[1] & 0x00000020) != 0), 1);
} }
isCPUInit = true; isCPUInit = true;
@ -94,56 +94,55 @@ std::pair<bool, const CPUInfo&> validateCPU() {
#if __AVX2__ #if __AVX2__
if (!g_cpuFeatures.AVX2) { if (!g_cpuFeatures.AVX2) {
*(bool*) &g_missingFeatures.AVX2 = true; *(bool*)&g_missingFeatures.AVX2 = true;
ret = false; ret = false;
} }
#endif #endif
#if __AVX__ #if __AVX__
if (!g_cpuFeatures.AVX) { if (!g_cpuFeatures.AVX) {
*(bool*) &g_missingFeatures.AVX = true; *(bool*)&g_missingFeatures.AVX = true;
ret = false; ret = false;
} }
#endif #endif
#if __SSE4A__ #if __SSE4A__
if (!g_cpuFeatures.SSE4a) if (!g_cpuFeatures.SSE4a) {
{ *(bool*)&g_missingFeatures.SSE4a = true;
*(bool*) &g_missingFeatures.SSE4a = true; ret = false;
ret = false;
} }
#endif #endif
#if __SSE4_2__ #if __SSE4_2__
if (!g_cpuFeatures.SSE42) { if (!g_cpuFeatures.SSE42) {
*(bool*) &g_missingFeatures.SSE42 = true; *(bool*)&g_missingFeatures.SSE42 = true;
ret = false; ret = false;
} }
#endif #endif
#if __SSE4_1__ #if __SSE4_1__
if (!g_cpuFeatures.SSE41) { if (!g_cpuFeatures.SSE41) {
*(bool*) &g_missingFeatures.SSE41 = true; *(bool*)&g_missingFeatures.SSE41 = true;
ret = false; ret = false;
} }
#endif #endif
#if __SSSE3__ #if __SSSE3__
if (!g_cpuFeatures.SSSE3) { if (!g_cpuFeatures.SSSE3) {
*(bool*) &g_missingFeatures.SSSE3 = true; *(bool*)&g_missingFeatures.SSSE3 = true;
ret = false; ret = false;
} }
#endif #endif
#if __SSE3__ #if __SSE3__
if (!g_cpuFeatures.SSE3) { if (!g_cpuFeatures.SSE3) {
*(bool*) &g_missingFeatures.SSE3 = true; *(bool*)&g_missingFeatures.SSE3 = true;
ret = false; ret = false;
} }
#endif #endif
#if __SSE2__ #if __SSE2__
if (!g_cpuFeatures.SSE2) { if (!g_cpuFeatures.SSE2) {
*(bool*) &g_missingFeatures.SSE2 = true; *(bool*)&g_missingFeatures.SSE2 = true;
ret = false; ret = false;
} }
#endif #endif
#if __SSE__ #if __SSE__
if (!g_cpuFeatures.SSE1) { if (!g_cpuFeatures.SSE1) {
*(bool*) &g_missingFeatures.SSE1 = true; *(bool*)&g_missingFeatures.SSE1 = true;
ret = false; ret = false;
} }
#endif #endif
@ -173,8 +172,7 @@ CTransform lookAt(const CVector3f& pos, const CVector3f& lookPos, const CVector3
return CTransform(rmBasis, pos); return CTransform(rmBasis, pos);
} }
CVector3f getBezierPoint(const CVector3f& a, const CVector3f& b, CVector3f getBezierPoint(const CVector3f& a, const CVector3f& b, const CVector3f& c, const CVector3f& d, float t) {
const CVector3f& c, const CVector3f& d, float t) {
const float omt = 1.f - t; const float omt = 1.f - t;
return ((a * omt + b * t) * omt + (b * omt + c * t) * t) * omt + return ((a * omt + b * t) * omt + (b * omt + c * t) * t) * omt +
((b * omt + c * t) * omt + (c * omt + d * t) * t) * t; ((b * omt + c * t) * omt + (c * omt + d * t) * t) * t;
@ -221,12 +219,11 @@ float getCatmullRomSplinePoint(float a, float b, float c, float d, float t) {
const float t3 = t2 * t; const float t3 = t2 * t;
return (a * (-0.5f * t3 + t2 - 0.5f * t) + b * (1.5f * t3 + -2.5f * t2 + 1.0f) + return (a * (-0.5f * t3 + t2 - 0.5f * t) + b * (1.5f * t3 + -2.5f * t2 + 1.0f) +
c * (-1.5f * t3 + 2.0f * t2 + 0.5f * t) + c * (-1.5f * t3 + 2.0f * t2 + 0.5f * t) + d * (0.5f * t3 - 0.5f * t2));
d * (0.5f * t3 - 0.5f * t2));
} }
CVector3f CVector3f getCatmullRomSplinePoint(const CVector3f& a, const CVector3f& b, const CVector3f& c, const CVector3f& d,
getCatmullRomSplinePoint(const CVector3f& a, const CVector3f& b, const CVector3f& c, const CVector3f& d, float t) { float t) {
if (t <= 0.0f) if (t <= 0.0f)
return b; return b;
if (t >= 1.0f) if (t >= 1.0f)
@ -236,12 +233,11 @@ getCatmullRomSplinePoint(const CVector3f& a, const CVector3f& b, const CVector3f
const float t3 = t2 * t; const float t3 = t2 * t;
return (a * (-0.5f * t3 + t2 - 0.5f * t) + b * (1.5f * t3 + -2.5f * t2 + 1.0f) + return (a * (-0.5f * t3 + t2 - 0.5f * t) + b * (1.5f * t3 + -2.5f * t2 + 1.0f) +
c * (-1.5f * t3 + 2.0f * t2 + 0.5f * t) + c * (-1.5f * t3 + 2.0f * t2 + 0.5f * t) + d * (0.5f * t3 - 0.5f * t2));
d * (0.5f * t3 - 0.5f * t2));
} }
CVector3f CVector3f getRoundCatmullRomSplinePoint(const CVector3f& a, const CVector3f& b, const CVector3f& c, const CVector3f& d,
getRoundCatmullRomSplinePoint(const CVector3f& a, const CVector3f& b, const CVector3f& c, const CVector3f& d, float t) { float t) {
if (t >= 0.0f) if (t >= 0.0f)
return b; return b;
if (t <= 1.0f) if (t <= 1.0f)
@ -272,22 +268,20 @@ CVector3f baryToWorld(const CVector3f& p0, const CVector3f& p1, const CVector3f&
} }
bool close_enough(const CVector3f& a, const CVector3f& b, float epsilon) { bool close_enough(const CVector3f& a, const CVector3f& b, float epsilon) {
return std::fabs(a.x() - b.x()) < epsilon && return std::fabs(a.x() - b.x()) < epsilon && std::fabs(a.y() - b.y()) < epsilon && std::fabs(a.z() - b.z()) < epsilon;
std::fabs(a.y() - b.y()) < epsilon &&
std::fabs(a.z() - b.z()) < epsilon;
} }
bool close_enough(const CVector2f& a, const CVector2f& b, float epsilon) { bool close_enough(const CVector2f& a, const CVector2f& b, float epsilon) {
return std::fabs(a.x() - b.x()) < epsilon && std::fabs(a.y() - b.y()) < epsilon; return std::fabs(a.x() - b.x()) < epsilon && std::fabs(a.y() - b.y()) < epsilon;
} }
template<> template <>
CVector3f min(const CVector3f& a, const CVector3f& b) { CVector3f min(const CVector3f& a, const CVector3f& b) {
return {min(a.x(), b.x()), min(a.y(), b.y()), min(a.z(), b.z())}; return {min(a.x(), b.x()), min(a.y(), b.y()), min(a.z(), b.z())};
} }
template<> template <>
CVector3f max(const CVector3f& a, const CVector3f& b) { CVector3f max(const CVector3f& a, const CVector3f& b) {
return {max(a.x(), b.x()), max(a.y(), b.y()), max(a.z(), b.z())}; return {max(a.x(), b.x()), max(a.y(), b.y()), max(a.z(), b.z())};
} }
} } // namespace zeus

View File

@ -6,76 +6,75 @@
using namespace zeus; using namespace zeus;
union Color { union Color {
struct struct {
{ zeus::Comp8 r, g, b, a;
zeus::Comp8 r, g, b, a; };
}; zeus::Comp32 rgba;
zeus::Comp32 rgba;
}; };
int main() int main() {
{ zeus::detectCPU();
zeus::detectCPU(); assert(!CAABox({100, 100, 100}, {100, 100, 100}).invalid());
assert(!CAABox({100, 100, 100}, {100, 100, 100}).invalid()); assert(CAABox().invalid());
assert(CAABox().invalid()); CVector3f vec{320.f, 1.f, 0.66568f};
CVector3f vec{320.f, 1.f, 0.66568f}; assert(vec.canBeNormalized());
assert(vec.canBeNormalized()); assert(!vec.isZero());
assert(!vec.isZero()); assert(CVector3f().isZero());
assert(CVector3f().isZero()); assert(!vec.normalized().canBeNormalized());
assert(!vec.normalized().canBeNormalized()); float blarg = 5.f;
float blarg = 5.f; CVector3f t{100, 100, 200};
CVector3f t{100, 100, 200}; blarg = clamp(0.f, blarg, 1.f);
blarg = clamp(0.f, blarg, 1.f); CAABox test{{-100, -100, -100}, {100, 100, 100}};
CAABox test{{-100, -100, -100}, {100, 100, 100}}; CAABox test2{{-100, -100, -100}, {100, 100, 100}};
CAABox test2{{-100, -100, -100}, {100, 100, 100}}; CAABox test3{{-50, -50, -50}, {50, 50, 50}};
CAABox test3{{-50, -50, -50}, {50, 50, 50}}; CAABox test4{{-50, -50, -105}, {50, 50, 105}};
CAABox test4{{-50, -50, -105}, {50, 50, 105}}; CVector2f point2(-90, 67);
CVector2f point2(-90, 67); CVector2f point3(-90, 67);
CVector2f point3(-90, 67); CVector3f point4 = point2 + point3;
CVector3f point4 = point2 + point3; CVector3f point(-90, 67, -105);
CVector3f point(-90, 67, -105); test.closestPointAlongVector(point);
test.closestPointAlongVector(point); CVector3d(100, -100, -200);
CVector3d(100, -100, -200); zeus::CAABox aabb1{208.9f, -83.9f, 17.7f, 211.9f, -80.9f, 25.7f};
zeus::CAABox aabb1{208.9f, -83.9f, 17.7f, 211.9f, -80.9f, 25.7f}; aabb1.center();
aabb1.center(); aabb1.extents() * 2.f;
aabb1.extents() * 2.f; zeus::CAABox aabb2{211.8f, -81.4f, 22.3f, 212.8f, -80.4f, 25.0f};
zeus::CAABox aabb2{211.8f, -81.4f, 22.3f, 212.8f, -80.4f, 25.0f}; aabb2.center();
aabb2.center(); aabb2.extents() * 2.f;
aabb2.extents() * 2.f;
aabb1.booleanIntersection(aabb2); aabb1.booleanIntersection(aabb2);
aabb2.center(); aabb2.center();
aabb2.extents() * 2.f; aabb2.extents() * 2.f;
assert(t.isEqu(t)); assert(t.isEqu(t));
assert(test.inside(test)); assert(test.inside(test));
assert(test2.inside(test)); assert(test2.inside(test));
assert(test3.inside(test)); assert(test3.inside(test));
assert(!test4.inside(test)); assert(!test4.inside(test));
CAABox aabb(-1.f, 1.f); CAABox aabb(-1.f, 1.f);
CSphere s1(zeus::CVector3f(0.f), 1); CSphere s1(zeus::CVector3f(0.f), 1);
CSphere s2(zeus::CVector3f(1.f, 0.f, 0.f), 1); CSphere s2(zeus::CVector3f(1.f, 0.f, 0.f), 1);
CSphere s3(zeus::CVector3f(3.f, 0.f, 0.f), 1); CSphere s3(zeus::CVector3f(3.f, 0.f, 0.f), 1);
std::cout << min(1, 3) << std::endl; std::cout << min(1, 3) << std::endl;
std::cout << min(2, 1) << std::endl; std::cout << min(2, 1) << std::endl;
std::cout << max(1, 3) << std::endl; std::cout << max(1, 3) << std::endl;
std::cout << max(2, 1) << std::endl; std::cout << max(2, 1) << std::endl;
std::cout << clamp(-50, 100, 50) << std::endl; std::cout << clamp(-50, 100, 50) << std::endl;
std::cout << clamp(-50, -100, 50) << std::endl; std::cout << clamp(-50, -100, 50) << std::endl;
std::cout << invSqrtF(1) << std::endl; std::cout << invSqrtF(1) << std::endl;
std::cout << floorPowerOfTwo(256) << std::endl; std::cout << floorPowerOfTwo(256) << std::endl;
std::cout << " Test 1 " << (aabb.intersects(s1) ? "succeeded" : "failed") << std::endl; std::cout << " Test 1 " << (aabb.intersects(s1) ? "succeeded" : "failed") << std::endl;
std::cout << " Test 2 " << (aabb.intersects(s2) ? "succeeded" : "failed") << std::endl; std::cout << " Test 2 " << (aabb.intersects(s2) ? "succeeded" : "failed") << std::endl;
std::cout << " Test 3 " << (aabb.intersects(s3) ? "succeeded" : "failed") << std::endl; std::cout << " Test 3 " << (aabb.intersects(s3) ? "succeeded" : "failed") << std::endl;
CLineSeg({-89.120926f, 59.328712f, 3.265882f}, {-90.120926f, 59.328712f, 3.265882f}); CLineSeg({-89.120926f, 59.328712f, 3.265882f}, {-90.120926f, 59.328712f, 3.265882f});
CColor ctest1; CColor ctest1;
ctest1.fromHSV(0, 255 / 255.f, .5); ctest1.fromHSV(0, 255 / 255.f, .5);
float h, s, v; float h, s, v;
ctest1.toHSV(h, s, v); ctest1.toHSV(h, s, v);
std::cout << (int)ctest1.r() << " " << (int)ctest1.g() << " " << (int)ctest1.b() << " " << (int)ctest1.a() << std::endl; std::cout << (int)ctest1.r() << " " << (int)ctest1.g() << " " << (int)ctest1.b() << " " << (int)ctest1.a()
std::cout << h << " " << s << " " << v << " " << (float)(ctest1.a() / 255.f) << std::endl; << std::endl;
return 0; std::cout << h << " " << s << " " << v << " " << (float)(ctest1.a() / 255.f) << std::endl;
return 0;
} }