From e64b7c4d17d4489f749d02350faccac46c6a287b Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Mon, 28 Sep 2020 10:53:49 -1000 Subject: [PATCH] hsh vector type implicit casts --- CMakeLists.txt | 5 ++ include/zeus/CColor.hpp | 9 ++++ include/zeus/CMatrix3f.hpp | 10 ++++ include/zeus/CMatrix4f.hpp | 10 ++++ include/zeus/CVector2f.hpp | 11 ++++ include/zeus/CVector3f.hpp | 11 ++++ include/zeus/CVector4f.hpp | 11 ++++ include/zeus/Global.hpp | 4 ++ include/zeus/simd/parallelism_v2_simd.hpp | 64 ++++++++++++++++------- 9 files changed, 115 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 255f513..6eff6cd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -62,5 +62,10 @@ if(TARGET athena-core) target_compile_definitions(zeus PUBLIC ZE_ATHENA_TYPES=1) endif() +if(TARGET hsh) + target_link_libraries(zeus PUBLIC hsh) + target_compile_definitions(zeus PUBLIC ZE_HSH_TYPES=1) +endif() + add_subdirectory(test) diff --git a/include/zeus/CColor.hpp b/include/zeus/CColor.hpp index ab64d47..4601f07 100644 --- a/include/zeus/CColor.hpp +++ b/include/zeus/CColor.hpp @@ -124,6 +124,15 @@ public: writer.writeUByte(atUint8(f[3] * 255)); } +#endif + +#if ZE_HSH_TYPES + + operator hsh::float4() const { + simd_floats floats(mSimd); + return hsh::float4{floats[0], floats[1], floats[2], floats[3]}; + } + #endif [[nodiscard]] bool operator==(const CColor& rhs) const { diff --git a/include/zeus/CMatrix3f.hpp b/include/zeus/CMatrix3f.hpp index a07c168..1b23e70 100644 --- a/include/zeus/CMatrix3f.hpp +++ b/include/zeus/CMatrix3f.hpp @@ -67,6 +67,16 @@ public: return ret; } +#endif + +#if ZE_HSH_TYPES + + operator hsh::float3x3() const { + return hsh::float3x3{hsh::float3(m[0]), hsh::float3(m[1]), hsh::float3(m[2])}; + } + + constexpr CMatrix3f(const hsh::float3x3& vec) : m{vec.cols[0], vec.cols[1], vec.cols[2]} {} + #endif CMatrix3f(const CQuaternion& quat); diff --git a/include/zeus/CMatrix4f.hpp b/include/zeus/CMatrix4f.hpp index 40da5f9..c2bbf66 100644 --- a/include/zeus/CMatrix4f.hpp +++ b/include/zeus/CMatrix4f.hpp @@ -49,6 +49,16 @@ public: m[3].mSimd = CVector4f(0.f, 0.f, 0.f, 1.0f).mSimd; } +#if ZE_HSH_TYPES + + operator hsh::float4x4() const { + return hsh::float4x4{hsh::float4(m[0]), hsh::float4(m[1]), hsh::float4(m[2]), hsh::float4(m[3])}; + } + + constexpr CMatrix4f(const hsh::float4x4& vec) : m{vec.cols[0], vec.cols[1], vec.cols[2], vec.cols[3]} {} + +#endif + constexpr CMatrix4f& operator=(const CMatrix4f& other) = default; [[nodiscard]] CVector4f operator*(const CVector4f& other) const { diff --git a/include/zeus/CVector2f.hpp b/include/zeus/CVector2f.hpp index 266cae1..0a09a86 100644 --- a/include/zeus/CVector2f.hpp +++ b/include/zeus/CVector2f.hpp @@ -39,6 +39,17 @@ public: return ret; } +#endif + +#if ZE_HSH_TYPES + + operator hsh::float2() const { + simd_floats floats(mSimd); + return hsh::float2{floats[0], floats[1]}; + } + + constexpr CVector2f(const hsh::float2& vec) : mSimd(vec.x, vec.y) {} + #endif explicit constexpr CVector2f(float xy) : mSimd(xy) {} diff --git a/include/zeus/CVector3f.hpp b/include/zeus/CVector3f.hpp index bed85d3..d3872d8 100644 --- a/include/zeus/CVector3f.hpp +++ b/include/zeus/CVector3f.hpp @@ -47,6 +47,17 @@ public: return ret; } +#endif + +#if ZE_HSH_TYPES + + operator hsh::float3() const { + simd_floats floats(mSimd); + return hsh::float3{floats[0], floats[1], floats[2]}; + } + + constexpr CVector3f(const hsh::float3& vec) : mSimd(vec.x, vec.y, vec.z) {} + #endif inline CVector3f(const CVector3d& vec); diff --git a/include/zeus/CVector4f.hpp b/include/zeus/CVector4f.hpp index 6d624f9..86401f7 100644 --- a/include/zeus/CVector4f.hpp +++ b/include/zeus/CVector4f.hpp @@ -40,6 +40,17 @@ public: mSimd.copy_from(f); } +#endif + +#if ZE_HSH_TYPES + + operator hsh::float4() const { + simd_floats floats(mSimd); + return hsh::float4{floats[0], floats[1], floats[2], floats[3]}; + } + + constexpr CVector4f(const hsh::float4& vec) : mSimd(vec.x, vec.y, vec.z, vec.w) {} + #endif explicit constexpr CVector4f(float xyzw) : mSimd(xyzw) {} diff --git a/include/zeus/Global.hpp b/include/zeus/Global.hpp index 7dc7133..509695c 100644 --- a/include/zeus/Global.hpp +++ b/include/zeus/Global.hpp @@ -7,6 +7,10 @@ #include "simd/simd.hpp" #endif +#if ZE_HSH_TYPES +#include "hsh/hsh.h" +#endif + namespace zeus { #if ZE_ATHENA_TYPES template diff --git a/include/zeus/simd/parallelism_v2_simd.hpp b/include/zeus/simd/parallelism_v2_simd.hpp index 4fc1904..5fca03d 100644 --- a/include/zeus/simd/parallelism_v2_simd.hpp +++ b/include/zeus/simd/parallelism_v2_simd.hpp @@ -718,54 +718,78 @@ public: return *this; } - __simd_reference operator++() && { return std::move(*this) = __ptr_->__get(__index_) + 1; } + __simd_reference operator++() && { return std::move(*this) = _Vp(*this) + 1; } _Vp operator++(int) && { - auto __val = __ptr_->__get(__index_); + auto __val = _Vp(*this); __ptr_->__set(__index_, __val + 1); return __val; } - __simd_reference operator--() && { return std::move(*this) = __ptr_->__get(__index_) - 1; } + __simd_reference operator--() && { return std::move(*this) = _Vp(*this) - 1; } _Vp operator--(int) && { - auto __val = __ptr_->__get(__index_); + auto __val = _Vp(*this); __ptr_->__set(__index_, __val - 1); return __val; } - __simd_reference operator+=(_Vp __value) && { return std::move(*this) = __ptr_->__get(__index_) + __value; } + __simd_reference operator+=(_Vp __value) && { return std::move(*this) = _Vp(*this) + __value; } - __simd_reference operator-=(_Vp __value) && { return std::move(*this) = __ptr_->__get(__index_) - __value; } + __simd_reference operator-=(_Vp __value) && { return std::move(*this) = _Vp(*this) - __value; } - __simd_reference operator*=(_Vp __value) && { return std::move(*this) = __ptr_->__get(__index_) * __value; } + __simd_reference operator*=(_Vp __value) && { return std::move(*this) = _Vp(*this) * __value; } - __simd_reference operator/=(_Vp __value) && { return std::move(*this) = __ptr_->__get(__index_) / __value; } + __simd_reference operator/=(_Vp __value) && { return std::move(*this) = _Vp(*this) / __value; } - __simd_reference operator%=(_Vp __value) && { return std::move(*this) = __ptr_->__get(__index_) % __value; } + __simd_reference operator%=(_Vp __value) && { return std::move(*this) = _Vp(*this) % __value; } - __simd_reference operator>>=(_Vp __value) && { return std::move(*this) = __ptr_->__get(__index_) >> __value; } + __simd_reference operator>>=(_Vp __value) && { return std::move(*this) = _Vp(*this) >> __value; } - __simd_reference operator<<=(_Vp __value) && { return std::move(*this) = __ptr_->__get(__index_) << __value; } + __simd_reference operator<<=(_Vp __value) && { return std::move(*this) = _Vp(*this) << __value; } - __simd_reference operator&=(_Vp __value) && { return std::move(*this) = __ptr_->__get(__index_) & __value; } + __simd_reference operator&=(_Vp __value) && { return std::move(*this) = _Vp(*this) & __value; } - __simd_reference operator|=(_Vp __value) && { return std::move(*this) = __ptr_->__get(__index_) | __value; } + __simd_reference operator|=(_Vp __value) && { return std::move(*this) = _Vp(*this) | __value; } - __simd_reference operator^=(_Vp __value) && { return std::move(*this) = __ptr_->__get(__index_) ^ __value; } + __simd_reference operator^=(_Vp __value) && { return std::move(*this) = _Vp(*this) ^ __value; } - bool operator<(_Vp __value) const { return __ptr_->__get(__index_) < __value; } + bool operator<(const __simd_reference& __value) const { return _Vp(*this) < _Vp(__value); } - bool operator<=(_Vp __value) const { return __ptr_->__get(__index_) <= __value; } + bool operator<=(const __simd_reference& __value) const { return _Vp(*this) <= _Vp(__value); } - bool operator>(_Vp __value) const { return __ptr_->__get(__index_) > __value; } + bool operator>(const __simd_reference& __value) const { return _Vp(*this) > _Vp(__value); } - bool operator>=(_Vp __value) const { return __ptr_->__get(__index_) >= __value; } + bool operator>=(const __simd_reference& __value) const { return _Vp(*this) >= _Vp(__value); } - bool operator==(_Vp __value) const { return __ptr_->__get(__index_) == __value; } + bool operator==(const __simd_reference& __value) const { return _Vp(*this) == _Vp(__value); } - bool operator!=(_Vp __value) const { return __ptr_->__get(__index_) != __value; } + bool operator!=(const __simd_reference& __value) const { return _Vp(*this) != _Vp(__value); } + + bool operator<(_Vp __value) const { return _Vp(*this) < __value; } + + bool operator<=(_Vp __value) const { return _Vp(*this) <= __value; } + + bool operator>(_Vp __value) const { return _Vp(*this) > __value; } + + bool operator>=(_Vp __value) const { return _Vp(*this) >= __value; } + + bool operator==(_Vp __value) const { return _Vp(*this) == __value; } + + bool operator!=(_Vp __value) const { return _Vp(*this) != __value; } }; +template +inline bool operator<(_Vp a, const __simd_reference<_Vp, _Tp, _Abi>& b) { return a < _Vp(b); } +template +inline bool operator<=(_Vp a, const __simd_reference<_Vp, _Tp, _Abi>& b) { return a <= _Vp(b); } +template +inline bool operator>(_Vp a, const __simd_reference<_Vp, _Tp, _Abi>& b) { return a > _Vp(b); } +template +inline bool operator>=(_Vp a, const __simd_reference<_Vp, _Tp, _Abi>& b) { return a >= _Vp(b); } +template +inline bool operator==(_Vp a, const __simd_reference<_Vp, _Tp, _Abi>& b) { return a == _Vp(b); } +template +inline bool operator!=(_Vp a, const __simd_reference<_Vp, _Tp, _Abi>& b) { return a != _Vp(b); } template class __simd_mask_reference {