From 1bef2b284742259bb2e7ee7cfac75ca3dc537a1e Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Sat, 16 Jan 2016 15:16:30 -0800 Subject: [PATCH] Enable atdna on CVector*f when ZE_ATHENA_TYPES is defined --- include/CVector2f.hpp | 62 ++++++++++++++++++++++++++++------------ include/CVector3f.hpp | 59 +++++++++++++++++++++++++++----------- include/CVector4f.hpp | 66 ++++++++++++++++++++++++++++++------------- 3 files changed, 132 insertions(+), 55 deletions(-) diff --git a/include/CVector2f.hpp b/include/CVector2f.hpp index d0d4eac..0673e46 100644 --- a/include/CVector2f.hpp +++ b/include/CVector2f.hpp @@ -16,8 +16,22 @@ namespace Zeus { class alignas(16) CVector2f { - public: +#if __atdna__ + float clangVec __attribute__((__vector_size__(8))); +#endif +public: ZE_DECLARE_ALIGNED_ALLOCATOR(); + union + { + struct + { + float x, y; + }; + float v[4]; +#if __SSE__ + __m128 mVec128; +#endif + }; inline CVector2f() {zeroOut();} #if __SSE__ @@ -32,20 +46,44 @@ class alignas(16) CVector2f x = vec.vec[0], y = vec.vec[1], v[2] = 0.0f, v[3] = 0.0f; } #endif + + operator atVec2f() + { + atVec2f ret; +#if __SSE__ + ret.mVec128 = mVec128; +#else + ret.vec = v; #endif - CVector2f(float xy) {splat(xy);} - void assign(float x, float y) {v[0] = x; v[1] = y; v[2] = 0; v[3] = 0.0;} - CVector2f(float x, float y) {assign(x, y);} -#if ZE_ATHENA_TYPES - CVector2f(Athena::io::IStreamReader& input) + return ret; + } + operator atVec2f() const + { + atVec2f ret; +#if __SSE__ + ret.mVec128 = mVec128; +#else + ret.vec = v; +#endif + return ret; + } + + void read(Athena::io::IStreamReader& input) { x = input.readFloat(); y = input.readFloat(); v[2] = 0.0f; v[3] = 0.0f; } + + CVector2f(Athena::io::IStreamReader& input) + { read(input); } #endif + CVector2f(float xy) {splat(xy);} + void assign(float x, float y) {v[0] = x; v[1] = y; v[2] = 0; v[3] = 0.0;} + CVector2f(float x, float y) {assign(x, y);} + inline bool operator ==(const CVector2f& rhs) const {return (x == rhs.x && y == rhs.y);} inline bool operator !=(const CVector2f& rhs) const @@ -307,18 +345,6 @@ class alignas(16) CVector2f inline const float& operator[](size_t idx) const {return (&x)[idx];} - union - { - struct - { - float x, y; - }; - float v[4]; -#if __SSE__ - __m128 mVec128; -#endif - }; - static const CVector2f skOne; static const CVector2f skNegOne; static const CVector2f skZero; diff --git a/include/CVector3f.hpp b/include/CVector3f.hpp index 96cbe26..3be42cb 100644 --- a/include/CVector3f.hpp +++ b/include/CVector3f.hpp @@ -16,13 +16,28 @@ namespace Zeus { class alignas(16) CVector3f { +#if __atdna__ + float clangVec __attribute__((__vector_size__(12))); +#endif public: ZE_DECLARE_ALIGNED_ALLOCATOR(); - + + union + { + struct { float x, y, z; }; + float v[4]; +#if __SSE__ + __m128 mVec128; +#elif __GEKKO_PS__ + ps128_t mVec128; +#endif + }; + inline CVector3f() {zeroOut();} #if __SSE__ || __GEKKO_PS__ CVector3f(const __m128& mVec128) : mVec128(mVec128) {v[3] = 0.0f;} #endif + #if ZE_ATHENA_TYPES CVector3f(const atVec3f& vec) #if __SSE__ || __GEKKO_PS__ @@ -32,11 +47,28 @@ public: x = vec.vec[0], y = vec.vec[1], z = vec.vec[2], v[3] = 0.0f; } #endif + + operator atVec3f() + { + atVec3f ret; +#if __SSE__ + ret.mVec128 = mVec128; +#else + ret.vec = v; #endif - CVector3f(float xyz) {splat(xyz);} - void assign(float x, float y, float z) {v[0] = x; v[1] = y; v[2] = z; v[3] = 0.0;} - CVector3f(float x, float y, float z) {assign(x, y, z);} -#if ZE_ATHENA_TYPES + return ret; + } + operator atVec3f() const + { + atVec3f ret; +#if __SSE__ + ret.mVec128 = mVec128; +#else + ret.vec = v; +#endif + return ret; + } + void read(Athena::io::IStreamReader& input) { x = input.readFloat(); @@ -46,6 +78,11 @@ public: } CVector3f(Athena::io::IStreamReader& input) {read(input);} #endif + + CVector3f(float xyz) {splat(xyz);} + void assign(float x, float y, float z) {v[0] = x; v[1] = y; v[2] = z; v[3] = 0.0;} + CVector3f(float x, float y, float z) {assign(x, y, z);} + CVector3f(const CVector2f& other) { x = other.x; @@ -313,18 +350,6 @@ public: inline float& operator[](size_t idx) {return (&x)[idx];} inline const float& operator[](size_t idx) const {return (&x)[idx];} - - union - { - struct { float x, y, z; }; - float v[4]; -#if __SSE__ - __m128 mVec128; -#elif __GEKKO_PS__ - ps128_t mVec128; -#endif - }; - static const CVector3f skOne; static const CVector3f skNegOne; static const CVector3f skZero; diff --git a/include/CVector4f.hpp b/include/CVector4f.hpp index 5dce4bc..08f4c50 100644 --- a/include/CVector4f.hpp +++ b/include/CVector4f.hpp @@ -16,8 +16,22 @@ namespace Zeus class CColor; class alignas(16) CVector4f { - public: +#if __atdna__ + float clangVec __attribute__((__vector_size__(16))); +#endif +public: ZE_DECLARE_ALIGNED_ALLOCATOR(); + union + { + struct + { + float x, y, z, w; + }; + float v[4]; +#if __SSE__ + __m128 mVec128; +#endif + }; inline CVector4f() {zeroOut();} #if __SSE__ @@ -31,23 +45,47 @@ class alignas(16) CVector4f { x = vec.vec[0], y = vec.vec[1], z = vec.vec[2], w = vec.vec[3]; } -#endif #endif - CVector4f(float xyzw) {splat(xyzw);} - void assign(float x, float y, float z, float w) {v[0] = x; v[1] = y; v[2] = z; v[3] = w;} - CVector4f(float x, float y, float z, float w) {assign(x, y, z, w);} - CVector4f(const CColor& other); -#if ZE_ATHENA_TYPES - CVector4f(Athena::io::IStreamReader& input) + operator atVec4f() + { + atVec4f ret; +#if __SSE__ + ret.mVec128 = mVec128; +#else + ret.vec = v; +#endif + return ret; + } + operator atVec4f() const + { + atVec4f ret; +#if __SSE__ + ret.mVec128 = mVec128; +#else + ret.vec = v; +#endif + return ret; + } + + void read(Athena::io::IStreamReader& input) { x = input.readFloat(); y = input.readFloat(); z = input.readFloat(); w = input.readFloat(); } + + CVector4f(Athena::io::IStreamReader& input) + { read(input); } + #endif + CVector4f(float xyzw) {splat(xyzw);} + void assign(float x, float y, float z, float w) {v[0] = x; v[1] = y; v[2] = z; v[3] = w;} + CVector4f(float x, float y, float z, float w) {assign(x, y, z, w);} + CVector4f(const CColor& other); + CVector4f(const CVector3f& other) { x = other.x; @@ -325,18 +363,6 @@ class alignas(16) CVector4f inline const float& operator[](size_t idx) const {return (&x)[idx];} - union - { - struct - { - float x, y, z, w; - }; - float v[4]; -#if __SSE__ - __m128 mVec128; -#endif - }; - static const CVector4f skOne; static const CVector4f skNegOne; static const CVector4f skZero;