From 9f0958e40d6eb7325da7a099ef53c1e9c58cb148 Mon Sep 17 00:00:00 2001 From: "Jason P. Barmparesos" Date: Mon, 12 Sep 2016 16:40:37 +0300 Subject: [PATCH 01/19] Fixed bug on the faceforward function. --- glm/detail/func_geometric_simd.inl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glm/detail/func_geometric_simd.inl b/glm/detail/func_geometric_simd.inl index 22548728..f0d14a26 100644 --- a/glm/detail/func_geometric_simd.inl +++ b/glm/detail/func_geometric_simd.inl @@ -67,7 +67,7 @@ namespace detail GLM_FUNC_QUALIFIER static tvec4 call(tvec4 const& N, tvec4 const& I, tvec4 const& Nref) { tvec4 result(uninitialize); - result.data = glm_vec4_faceforward(N.data. I.data, Nref.data); + result.data = glm_vec4_faceforward(N.data, I.data, Nref.data); return result; } }; From 460b6ba1b6334890196ddf6cd8446840a08e5c5e Mon Sep 17 00:00:00 2001 From: Aaron Date: Mon, 12 Sep 2016 10:55:01 -0700 Subject: [PATCH 02/19] Corrected test for msvc compiler --- glm/detail/func_integer.inl | 4 ++-- glm/detail/type_vec.hpp | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/glm/detail/func_integer.inl b/glm/detail/func_integer.inl index accc58d9..47be412a 100644 --- a/glm/detail/func_integer.inl +++ b/glm/detail/func_integer.inl @@ -317,7 +317,7 @@ namespace detail template class vecType> GLM_FUNC_QUALIFIER vecType bitCount(vecType const & v) { - #ifdef GLM_COMPILER_VC + #if GLM_COMPILER & GLM_COMPILER_VC #pragma warning(push) #pragma warning(disable : 4310) //cast truncates constant value #endif @@ -329,7 +329,7 @@ namespace detail x = detail::compute_bitfieldBitCountStep::type, P, vecType, detail::is_aligned

::value, sizeof(T) * 8>= 32>::call(x, typename detail::make_unsigned::type(0x0000FFFF0000FFFFull), typename detail::make_unsigned::type(16)); x = detail::compute_bitfieldBitCountStep::type, P, vecType, detail::is_aligned

::value, sizeof(T) * 8>= 64>::call(x, typename detail::make_unsigned::type(0x00000000FFFFFFFFull), typename detail::make_unsigned::type(32)); return vecType(x); - #ifdef GLM_COMPILER_VC + #if GLM_COMPILER & GLM_COMPILER_VC #pragma warning(pop) #endif } diff --git a/glm/detail/type_vec.hpp b/glm/detail/type_vec.hpp index 686a9b50..9d066550 100644 --- a/glm/detail/type_vec.hpp +++ b/glm/detail/type_vec.hpp @@ -9,7 +9,7 @@ namespace glm{ namespace detail { -#ifdef GLM_COMPILER_VC +#if GLM_COMPILER & GLM_COMPILER_VC #pragma warning(push) #pragma warning(disable : 4324) // structure was padded due to alignment specifier #endif @@ -21,9 +21,10 @@ namespace detail template<> GLM_ALIGNED_STRUCT(16) aligned<16>{}; template<> GLM_ALIGNED_STRUCT(32) aligned<32>{}; template<> GLM_ALIGNED_STRUCT(64) aligned<64>{}; -#ifdef GLM_COMPILER_VC +#if GLM_COMPILER & GLM_COMPILER_VC #pragma warning(pop) #endif + template struct storage { From f3044dde88668f4d89bcfec1723181c22e903b69 Mon Sep 17 00:00:00 2001 From: "Jason P. Barmparesos" Date: Mon, 12 Sep 2016 16:40:37 +0300 Subject: [PATCH 03/19] Fixed bug on the faceforward function. --- glm/detail/func_geometric_simd.inl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glm/detail/func_geometric_simd.inl b/glm/detail/func_geometric_simd.inl index 22548728..f0d14a26 100644 --- a/glm/detail/func_geometric_simd.inl +++ b/glm/detail/func_geometric_simd.inl @@ -67,7 +67,7 @@ namespace detail GLM_FUNC_QUALIFIER static tvec4 call(tvec4 const& N, tvec4 const& I, tvec4 const& Nref) { tvec4 result(uninitialize); - result.data = glm_vec4_faceforward(N.data. I.data, Nref.data); + result.data = glm_vec4_faceforward(N.data, I.data, Nref.data); return result; } }; From 5fb5e0e3211674d0b70680343fd5bfe898c6a8cc Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Tue, 13 Sep 2016 00:01:54 +0200 Subject: [PATCH 04/19] Fixed bug on the faceforward function. #549 --- readme.md | 1 + 1 file changed, 1 insertion(+) diff --git a/readme.md b/readme.md index 09f1d0c5..14ab3ff4 100644 --- a/readme.md +++ b/readme.md @@ -54,6 +54,7 @@ glm::mat4 camera(float Translate, glm::vec2 const & Rotate) #### [GLM 0.9.8.1](https://github.com/g-truc/glm/tree/0.9.8) - 2016-XX-XX ##### Fixes: - Fixed GCC warning filtering, replaced -pedantic by -Wpedantic +- Fixed bug on the faceforward function. #549 #### [GLM 0.9.8.0](https://github.com/g-truc/glm/releases/tag/0.9.8.0) - 2016-09-11 ##### Features: From 8ac281e8415b8c47269a8d68235274092e920f0c Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Tue, 13 Sep 2016 00:02:59 +0200 Subject: [PATCH 05/19] Fixed bug on the faceforward function. #549 --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 14ab3ff4..f65abd8c 100644 --- a/readme.md +++ b/readme.md @@ -54,7 +54,7 @@ glm::mat4 camera(float Translate, glm::vec2 const & Rotate) #### [GLM 0.9.8.1](https://github.com/g-truc/glm/tree/0.9.8) - 2016-XX-XX ##### Fixes: - Fixed GCC warning filtering, replaced -pedantic by -Wpedantic -- Fixed bug on the faceforward function. #549 +- Fixed SIMD faceforward bug. #549 #### [GLM 0.9.8.0](https://github.com/g-truc/glm/releases/tag/0.9.8.0) - 2016-09-11 ##### Features: From cb7179239b02dbdc92c6a1c7f7fa51e9ae8ecef4 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Tue, 13 Sep 2016 00:21:56 +0200 Subject: [PATCH 06/19] - Fixed GCC 4.8 with C++11 compilation option #550 --- glm/detail/type_vec4.hpp | 2 +- glm/detail/type_vec4.inl | 2 +- glm/detail/type_vec4_simd.inl | 3 +-- readme.md | 3 ++- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/glm/detail/type_vec4.hpp b/glm/detail/type_vec4.hpp index 4cd69dcd..5a03cd47 100644 --- a/glm/detail/type_vec4.hpp +++ b/glm/detail/type_vec4.hpp @@ -101,7 +101,7 @@ namespace glm /// Explicit converions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification) template - GLM_FUNC_DECL GLM_CONSTEXPR tvec4(A a, B b, C c, D d); + GLM_FUNC_DECL GLM_CONSTEXPR_SIMD tvec4(A a, B b, C c, D d); template GLM_FUNC_DECL GLM_CONSTEXPR tvec4(tvec1 const& a, tvec1 const& b, tvec1 const& c, tvec1 const& d); diff --git a/glm/detail/type_vec4.inl b/glm/detail/type_vec4.inl index d7bbf386..496da9d6 100644 --- a/glm/detail/type_vec4.inl +++ b/glm/detail/type_vec4.inl @@ -196,7 +196,7 @@ namespace detail template template - GLM_FUNC_QUALIFIER GLM_CONSTEXPR tvec4::tvec4(A a, B b, C c, D d) : + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD tvec4::tvec4(A a, B b, C c, D d) : x(static_cast(a)), y(static_cast(b)), z(static_cast(c)), diff --git a/glm/detail/type_vec4_simd.inl b/glm/detail/type_vec4_simd.inl index 6ae818f5..55db422e 100644 --- a/glm/detail/type_vec4_simd.inl +++ b/glm/detail/type_vec4_simd.inl @@ -458,7 +458,7 @@ namespace detail GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD tvec4::tvec4(int32 a, int32 b, int32 c, int32 d) : data(_mm_set_epi32(d, c, b, a)) {} -/* + template <> template <> GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD tvec4::tvec4(int32 a, int32 b, int32 c, int32 d) : @@ -476,7 +476,6 @@ namespace detail GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD tvec4::tvec4(int32 a, int32 b, int32 c, int32 d) : data(_mm_castsi128_ps(_mm_set_epi32(d, c, b, a))) {} -*/ }//namespace glm #endif//GLM_ARCH & GLM_ARCH_SSE2_BIT diff --git a/readme.md b/readme.md index f65abd8c..66187677 100644 --- a/readme.md +++ b/readme.md @@ -54,7 +54,8 @@ glm::mat4 camera(float Translate, glm::vec2 const & Rotate) #### [GLM 0.9.8.1](https://github.com/g-truc/glm/tree/0.9.8) - 2016-XX-XX ##### Fixes: - Fixed GCC warning filtering, replaced -pedantic by -Wpedantic -- Fixed SIMD faceforward bug. #549 +- Fixed SIMD faceforward bug. #549 +- Fixed GCC 4.8 with C++11 compilation option #550 #### [GLM 0.9.8.0](https://github.com/g-truc/glm/releases/tag/0.9.8.0) - 2016-09-11 ##### Features: From e57615b6bb3efdaa5704e4acf6c6cdd7868f1154 Mon Sep 17 00:00:00 2001 From: Aaron Date: Tue, 13 Sep 2016 00:36:43 -0700 Subject: [PATCH 07/19] Changed how storage alignment is created to eliminate warnings on msvc. --- glm/detail/type_vec.hpp | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/glm/detail/type_vec.hpp b/glm/detail/type_vec.hpp index 9d066550..af8ed14a 100644 --- a/glm/detail/type_vec.hpp +++ b/glm/detail/type_vec.hpp @@ -9,22 +9,6 @@ namespace glm{ namespace detail { -#if GLM_COMPILER & GLM_COMPILER_VC -#pragma warning(push) -#pragma warning(disable : 4324) // structure was padded due to alignment specifier -#endif - template struct aligned {}; - template<> GLM_ALIGNED_STRUCT(1) aligned<1>{}; - template<> GLM_ALIGNED_STRUCT(2) aligned<2>{}; - template<> GLM_ALIGNED_STRUCT(4) aligned<4>{}; - template<> GLM_ALIGNED_STRUCT(8) aligned<8>{}; - template<> GLM_ALIGNED_STRUCT(16) aligned<16>{}; - template<> GLM_ALIGNED_STRUCT(32) aligned<32>{}; - template<> GLM_ALIGNED_STRUCT(64) aligned<64>{}; -#if GLM_COMPILER & GLM_COMPILER_VC -#pragma warning(pop) -#endif - template struct storage { @@ -33,15 +17,22 @@ namespace detail } type; }; - template - struct storage - { - struct type : aligned - { - uint8 data[size]; + #define GLM_ALIGNED_STORAGE_TYPE_STRUCT(x) \ + template \ + struct storage { \ + GLM_ALIGNED_STRUCT(x) type { \ + uint8_t data[x]; \ + }; \ }; - }; + GLM_ALIGNED_STORAGE_TYPE_STRUCT(1) + GLM_ALIGNED_STORAGE_TYPE_STRUCT(2) + GLM_ALIGNED_STORAGE_TYPE_STRUCT(4) + GLM_ALIGNED_STORAGE_TYPE_STRUCT(8) + GLM_ALIGNED_STORAGE_TYPE_STRUCT(16) + GLM_ALIGNED_STORAGE_TYPE_STRUCT(32) + GLM_ALIGNED_STORAGE_TYPE_STRUCT(64) + # if GLM_ARCH & GLM_ARCH_SSE2_BIT template <> struct storage From fa51f18b0c874f462b627fa9f7eebaffb4cd456e Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Wed, 14 Sep 2016 22:01:30 +0200 Subject: [PATCH 08/19] Fixed GCC build broken by #548 PR --- glm/detail/type_vec.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glm/detail/type_vec.hpp b/glm/detail/type_vec.hpp index af8ed14a..7849db63 100644 --- a/glm/detail/type_vec.hpp +++ b/glm/detail/type_vec.hpp @@ -21,7 +21,7 @@ namespace detail template \ struct storage { \ GLM_ALIGNED_STRUCT(x) type { \ - uint8_t data[x]; \ + uint8 data[x]; \ }; \ }; From e2ae466059020363914b8505fd558a207285cdba Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Wed, 14 Sep 2016 22:33:59 +0200 Subject: [PATCH 09/19] Added aligned storage tests #548 --- test/core/CMakeLists.txt | 1 + test/core/core_type_aligned.cpp | 104 ++++++++++++++++++++++++++++++++ 2 files changed, 105 insertions(+) create mode 100644 test/core/core_type_aligned.cpp diff --git a/test/core/CMakeLists.txt b/test/core/CMakeLists.txt index f83823d6..c2349c49 100644 --- a/test/core/CMakeLists.txt +++ b/test/core/CMakeLists.txt @@ -1,3 +1,4 @@ +glmCreateTestGTC(core_type_aligned) glmCreateTestGTC(core_type_cast) glmCreateTestGTC(core_type_ctor) glmCreateTestGTC(core_type_float) diff --git a/test/core/core_type_aligned.cpp b/test/core/core_type_aligned.cpp new file mode 100644 index 00000000..45f59688 --- /dev/null +++ b/test/core/core_type_aligned.cpp @@ -0,0 +1,104 @@ +#include +/* +#define GLM_ALIGNED(x) __declspec(align(x)) +#define GLM_ALIGNED_STRUCT(x) struct __declspec(align(x)) + +#define GLM_ALIGNED_STORAGE_TYPE_STRUCT(x) \ +template \ +struct storage { \ + GLM_ALIGNED_STRUCT(x) type { \ + uint8_t data[x]; \ + }; \ +}; + +template +struct storage { + typedef struct type { + uint8_t data[size]; + } type; +}; + +GLM_ALIGNED_STORAGE_TYPE_STRUCT(1) +GLM_ALIGNED_STORAGE_TYPE_STRUCT(2) +GLM_ALIGNED_STORAGE_TYPE_STRUCT(4) +GLM_ALIGNED_STORAGE_TYPE_STRUCT(8) +GLM_ALIGNED_STORAGE_TYPE_STRUCT(16) +GLM_ALIGNED_STORAGE_TYPE_STRUCT(32) +GLM_ALIGNED_STORAGE_TYPE_STRUCT(64) +*/ +int main() { + size_t size1_aligned = sizeof(glm::detail::storage::type); + size_t size2_aligned = sizeof(glm::detail::storage::type); + size_t size4_aligned = sizeof(glm::detail::storage::type); + size_t size8_aligned = sizeof(glm::detail::storage::type); + size_t size16_aligned = sizeof(glm::detail::storage::type); + size_t size32_aligned = sizeof(glm::detail::storage::type); + size_t size64_aligned = sizeof(glm::detail::storage::type); + size_t size128_aligned = sizeof(glm::detail::storage::type); + + size_t size1_unaligned = sizeof(glm::detail::storage::type); + size_t size2_unaligned = sizeof(glm::detail::storage::type); + size_t size4_unaligned = sizeof(glm::detail::storage::type); + size_t size8_unaligned = sizeof(glm::detail::storage::type); + size_t size16_unaligned = sizeof(glm::detail::storage::type); + size_t size32_unaligned = sizeof(glm::detail::storage::type); + size_t size64_unaligned = sizeof(glm::detail::storage::type); + size_t size128_unaligned = sizeof(glm::detail::storage::type); + + size_t align1_aligned = alignof(glm::detail::storage::type); + size_t align2_aligned = alignof(glm::detail::storage::type); + size_t align4_aligned = alignof(glm::detail::storage::type); + size_t align8_aligned = alignof(glm::detail::storage::type); + size_t align16_aligned = alignof(glm::detail::storage::type); + size_t align32_aligned = alignof(glm::detail::storage::type); + size_t align64_aligned = alignof(glm::detail::storage::type); + size_t align128_aligned = alignof(glm::detail::storage::type); + + size_t align1_unaligned = alignof(glm::detail::storage::type); + size_t align2_unaligned = alignof(glm::detail::storage::type); + size_t align4_unaligned = alignof(glm::detail::storage::type); + size_t align8_unaligned = alignof(glm::detail::storage::type); + size_t align16_unaligned = alignof(glm::detail::storage::type); + size_t align32_unaligned = alignof(glm::detail::storage::type); + size_t align64_unaligned = alignof(glm::detail::storage::type); + size_t align128_unaligned = alignof(glm::detail::storage::type); + + // RESULTS + // size1_aligned 1 + // size2_aligned 2 + // size4_aligned 4 + // size8_aligned 8 + // size16_aligned 16 + // size32_aligned 32 + // size64_aligned 64 + // size128_aligned 128 + // + // size1_unaligned 1 + // size2_unaligned 2 + // size4_unaligned 4 + // size8_unaligned 8 + // size16_unaligned 16 + // size32_unaligned 32 + // size64_unaligned 64 + // size128_unaligned 128 + // + // align1_aligned 1 + // align2_aligned 2 + // align4_aligned 4 + // align8_aligned 8 + // align16_aligned 16 + // align32_aligned 32 + // align64_aligned 64 + // align128_aligned 1 + // + // align1_unaligned 1 + // align2_unaligned 1 + // align4_unaligned 1 + // align8_unaligned 1 + // align16_unaligned 1 + // align32_unaligned 1 + // align64_unaligned 1 + // align128_unaligned 1 + + return 0; +} From 39455067dca8e29036ae34d6f24994f8a6d00096 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Wed, 14 Sep 2016 23:18:52 +0200 Subject: [PATCH 10/19] Improved core_type_aligned test --- test/core/core_type_aligned.cpp | 182 +++++++++++++++----------------- 1 file changed, 87 insertions(+), 95 deletions(-) diff --git a/test/core/core_type_aligned.cpp b/test/core/core_type_aligned.cpp index 45f59688..be15e9d8 100644 --- a/test/core/core_type_aligned.cpp +++ b/test/core/core_type_aligned.cpp @@ -1,104 +1,96 @@ #include -/* -#define GLM_ALIGNED(x) __declspec(align(x)) -#define GLM_ALIGNED_STRUCT(x) struct __declspec(align(x)) -#define GLM_ALIGNED_STORAGE_TYPE_STRUCT(x) \ -template \ -struct storage { \ - GLM_ALIGNED_STRUCT(x) type { \ - uint8_t data[x]; \ - }; \ -}; +int test_aligned() +{ + int Error = 0; -template -struct storage { - typedef struct type { - uint8_t data[size]; - } type; -}; + size_t size1_aligned = sizeof(glm::detail::storage::type); + Error += size1_aligned == 1 ? 0 : 1; + size_t align1_aligned = alignof(glm::detail::storage::type); + Error += align1_aligned == 1 ? 0 : 1; -GLM_ALIGNED_STORAGE_TYPE_STRUCT(1) -GLM_ALIGNED_STORAGE_TYPE_STRUCT(2) -GLM_ALIGNED_STORAGE_TYPE_STRUCT(4) -GLM_ALIGNED_STORAGE_TYPE_STRUCT(8) -GLM_ALIGNED_STORAGE_TYPE_STRUCT(16) -GLM_ALIGNED_STORAGE_TYPE_STRUCT(32) -GLM_ALIGNED_STORAGE_TYPE_STRUCT(64) -*/ -int main() { - size_t size1_aligned = sizeof(glm::detail::storage::type); - size_t size2_aligned = sizeof(glm::detail::storage::type); - size_t size4_aligned = sizeof(glm::detail::storage::type); - size_t size8_aligned = sizeof(glm::detail::storage::type); - size_t size16_aligned = sizeof(glm::detail::storage::type); - size_t size32_aligned = sizeof(glm::detail::storage::type); - size_t size64_aligned = sizeof(glm::detail::storage::type); - size_t size128_aligned = sizeof(glm::detail::storage::type); + size_t size2_aligned = sizeof(glm::detail::storage::type); + Error += size2_aligned == 2 ? 0 : 1; + size_t align2_aligned = alignof(glm::detail::storage::type); + Error += align2_aligned == 2 ? 0 : 1; - size_t size1_unaligned = sizeof(glm::detail::storage::type); - size_t size2_unaligned = sizeof(glm::detail::storage::type); - size_t size4_unaligned = sizeof(glm::detail::storage::type); - size_t size8_unaligned = sizeof(glm::detail::storage::type); - size_t size16_unaligned = sizeof(glm::detail::storage::type); - size_t size32_unaligned = sizeof(glm::detail::storage::type); - size_t size64_unaligned = sizeof(glm::detail::storage::type); - size_t size128_unaligned = sizeof(glm::detail::storage::type); + size_t size4_aligned = sizeof(glm::detail::storage::type); + Error += size4_aligned == 4 ? 0 : 1; + size_t align4_aligned = alignof(glm::detail::storage::type); + Error += align4_aligned == 4 ? 0 : 1; - size_t align1_aligned = alignof(glm::detail::storage::type); - size_t align2_aligned = alignof(glm::detail::storage::type); - size_t align4_aligned = alignof(glm::detail::storage::type); - size_t align8_aligned = alignof(glm::detail::storage::type); - size_t align16_aligned = alignof(glm::detail::storage::type); - size_t align32_aligned = alignof(glm::detail::storage::type); - size_t align64_aligned = alignof(glm::detail::storage::type); - size_t align128_aligned = alignof(glm::detail::storage::type); + size_t size8_aligned = sizeof(glm::detail::storage::type); + Error += size8_aligned == 8 ? 0 : 1; + size_t align8_aligned = alignof(glm::detail::storage::type); + Error += align8_aligned == 8 ? 0 : 1; - size_t align1_unaligned = alignof(glm::detail::storage::type); - size_t align2_unaligned = alignof(glm::detail::storage::type); - size_t align4_unaligned = alignof(glm::detail::storage::type); - size_t align8_unaligned = alignof(glm::detail::storage::type); - size_t align16_unaligned = alignof(glm::detail::storage::type); - size_t align32_unaligned = alignof(glm::detail::storage::type); - size_t align64_unaligned = alignof(glm::detail::storage::type); - size_t align128_unaligned = alignof(glm::detail::storage::type); + size_t size16_aligned = sizeof(glm::detail::storage::type); + Error += size16_aligned == 16 ? 0 : 1; + size_t align16_aligned = alignof(glm::detail::storage::type); + Error += align16_aligned == 16 ? 0 : 1; - // RESULTS - // size1_aligned 1 - // size2_aligned 2 - // size4_aligned 4 - // size8_aligned 8 - // size16_aligned 16 - // size32_aligned 32 - // size64_aligned 64 - // size128_aligned 128 - // - // size1_unaligned 1 - // size2_unaligned 2 - // size4_unaligned 4 - // size8_unaligned 8 - // size16_unaligned 16 - // size32_unaligned 32 - // size64_unaligned 64 - // size128_unaligned 128 - // - // align1_aligned 1 - // align2_aligned 2 - // align4_aligned 4 - // align8_aligned 8 - // align16_aligned 16 - // align32_aligned 32 - // align64_aligned 64 - // align128_aligned 1 - // - // align1_unaligned 1 - // align2_unaligned 1 - // align4_unaligned 1 - // align8_unaligned 1 - // align16_unaligned 1 - // align32_unaligned 1 - // align64_unaligned 1 - // align128_unaligned 1 - - return 0; + size_t size32_aligned = sizeof(glm::detail::storage::type); + Error += size32_aligned == 32 ? 0 : 1; + size_t align32_aligned = alignof(glm::detail::storage::type); + Error += align32_aligned == 32 ? 0 : 1; + + size_t size64_aligned = sizeof(glm::detail::storage::type); + Error += size64_aligned == 64 ? 0 : 1; + size_t align64_aligned = alignof(glm::detail::storage::type); + Error += align64_aligned == 64 ? 0 : 1; + + return Error; +} + +int test_unaligned() +{ + int Error = 0; + + size_t size1_unaligned = sizeof(glm::detail::storage::type); + Error += size1_unaligned == 1 ? 0 : 1; + size_t align1_unaligned = alignof(glm::detail::storage::type); + Error += align1_unaligned == 1 ? 0 : 1; + + size_t size2_unaligned = sizeof(glm::detail::storage::type); + Error += size2_unaligned == 2 ? 0 : 1; + size_t align2_unaligned = alignof(glm::detail::storage::type); + Error += align2_unaligned == 1 ? 0 : 1; + + size_t size4_unaligned = sizeof(glm::detail::storage::type); + Error += size4_unaligned == 4 ? 0 : 1; + size_t align4_unaligned = alignof(glm::detail::storage::type); + Error += align4_unaligned == 1 ? 0 : 1; + + size_t size8_unaligned = sizeof(glm::detail::storage::type); + Error += size8_unaligned == 8 ? 0 : 1; + size_t align8_unaligned = alignof(glm::detail::storage::type); + Error += align8_unaligned == 1 ? 0 : 1; + + size_t size16_unaligned = sizeof(glm::detail::storage::type); + Error += size16_unaligned == 16 ? 0 : 1; + size_t align16_unaligned = alignof(glm::detail::storage::type); + Error += align16_unaligned == 1 ? 0 : 1; + + size_t size32_unaligned = sizeof(glm::detail::storage::type); + Error += size32_unaligned == 32 ? 0 : 1; + size_t align32_unaligned = alignof(glm::detail::storage::type); + Error += align32_unaligned == 1 ? 0 : 1; + + size_t size64_unaligned = sizeof(glm::detail::storage::type); + Error += size64_unaligned == 64 ? 0 : 1; + size_t align64_unaligned = alignof(glm::detail::storage::type); + Error += align64_unaligned == 1 ? 0 : 1; + + return Error; +} + + +int main() +{ + int Error = 0; + + Error += test_aligned(); + Error += test_unaligned(); + + return Error; } From 89d77b51c666952faec50f996d42ecf589405a5c Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Wed, 14 Sep 2016 23:38:43 +0200 Subject: [PATCH 11/19] Alignof is a C++11 feature --- glm/detail/setup.hpp | 13 ++++++ test/core/core_type_aligned.cpp | 70 ++++++++++++++++----------------- 2 files changed, 47 insertions(+), 36 deletions(-) diff --git a/glm/detail/setup.hpp b/glm/detail/setup.hpp index 8ad7eb9b..51c7c1ae 100644 --- a/glm/detail/setup.hpp +++ b/glm/detail/setup.hpp @@ -418,6 +418,19 @@ ((GLM_COMPILER & GLM_COMPILER_CUDA) && (GLM_COMPILER >= GLM_COMPILER_CUDA50)))) #endif +// N2341 http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2341.pdf +#if GLM_COMPILER & GLM_COMPILER_CLANG +# define GLM_HAS_ALIGNOF __has_feature(c_alignof) +#elif GLM_LANG & GLM_LANG_CXX11_FLAG +# define GLM_HAS_ALIGNOF 1 +#else +# define GLM_HAS_ALIGNOF ((GLM_LANG & GLM_LANG_CXX0X_FLAG) && (\ + ((GLM_COMPILER & GLM_COMPILER_GCC) && (GLM_COMPILER >= GLM_COMPILER_GCC48)) || \ + ((GLM_COMPILER & GLM_COMPILER_INTEL) && (GLM_COMPILER >= GLM_COMPILER_INTEL15)) || \ + ((GLM_COMPILER & GLM_COMPILER_VC) && (GLM_COMPILER >= GLM_COMPILER_VC2015)) || \ + ((GLM_COMPILER & GLM_COMPILER_CUDA) && (GLM_COMPILER >= GLM_COMPILER_CUDA70)))) +#endif + // #if GLM_LANG & GLM_LANG_CXX11_FLAG # define GLM_HAS_ASSIGNABLE 1 diff --git a/test/core/core_type_aligned.cpp b/test/core/core_type_aligned.cpp index be15e9d8..babf82a9 100644 --- a/test/core/core_type_aligned.cpp +++ b/test/core/core_type_aligned.cpp @@ -6,39 +6,38 @@ int test_aligned() size_t size1_aligned = sizeof(glm::detail::storage::type); Error += size1_aligned == 1 ? 0 : 1; - size_t align1_aligned = alignof(glm::detail::storage::type); - Error += align1_aligned == 1 ? 0 : 1; - size_t size2_aligned = sizeof(glm::detail::storage::type); Error += size2_aligned == 2 ? 0 : 1; - size_t align2_aligned = alignof(glm::detail::storage::type); - Error += align2_aligned == 2 ? 0 : 1; - size_t size4_aligned = sizeof(glm::detail::storage::type); Error += size4_aligned == 4 ? 0 : 1; - size_t align4_aligned = alignof(glm::detail::storage::type); - Error += align4_aligned == 4 ? 0 : 1; - size_t size8_aligned = sizeof(glm::detail::storage::type); Error += size8_aligned == 8 ? 0 : 1; - size_t align8_aligned = alignof(glm::detail::storage::type); - Error += align8_aligned == 8 ? 0 : 1; - size_t size16_aligned = sizeof(glm::detail::storage::type); Error += size16_aligned == 16 ? 0 : 1; - size_t align16_aligned = alignof(glm::detail::storage::type); - Error += align16_aligned == 16 ? 0 : 1; - size_t size32_aligned = sizeof(glm::detail::storage::type); Error += size32_aligned == 32 ? 0 : 1; - size_t align32_aligned = alignof(glm::detail::storage::type); - Error += align32_aligned == 32 ? 0 : 1; - size_t size64_aligned = sizeof(glm::detail::storage::type); Error += size64_aligned == 64 ? 0 : 1; + +# if GLM_HAS_ALIGNOF + + size_t align1_aligned = alignof(glm::detail::storage::type); + Error += align1_aligned == 1 ? 0 : 1; + size_t align2_aligned = alignof(glm::detail::storage::type); + Error += align2_aligned == 2 ? 0 : 1; + size_t align4_aligned = alignof(glm::detail::storage::type); + Error += align4_aligned == 4 ? 0 : 1; + size_t align8_aligned = alignof(glm::detail::storage::type); + Error += align8_aligned == 8 ? 0 : 1; + size_t align16_aligned = alignof(glm::detail::storage::type); + Error += align16_aligned == 16 ? 0 : 1; + size_t align32_aligned = alignof(glm::detail::storage::type); + Error += align32_aligned == 32 ? 0 : 1; size_t align64_aligned = alignof(glm::detail::storage::type); Error += align64_aligned == 64 ? 0 : 1; +# endif //GLM_HAS_ALIGNOF + return Error; } @@ -48,39 +47,38 @@ int test_unaligned() size_t size1_unaligned = sizeof(glm::detail::storage::type); Error += size1_unaligned == 1 ? 0 : 1; - size_t align1_unaligned = alignof(glm::detail::storage::type); - Error += align1_unaligned == 1 ? 0 : 1; - size_t size2_unaligned = sizeof(glm::detail::storage::type); Error += size2_unaligned == 2 ? 0 : 1; - size_t align2_unaligned = alignof(glm::detail::storage::type); - Error += align2_unaligned == 1 ? 0 : 1; - size_t size4_unaligned = sizeof(glm::detail::storage::type); Error += size4_unaligned == 4 ? 0 : 1; - size_t align4_unaligned = alignof(glm::detail::storage::type); - Error += align4_unaligned == 1 ? 0 : 1; - size_t size8_unaligned = sizeof(glm::detail::storage::type); Error += size8_unaligned == 8 ? 0 : 1; - size_t align8_unaligned = alignof(glm::detail::storage::type); - Error += align8_unaligned == 1 ? 0 : 1; - size_t size16_unaligned = sizeof(glm::detail::storage::type); Error += size16_unaligned == 16 ? 0 : 1; - size_t align16_unaligned = alignof(glm::detail::storage::type); - Error += align16_unaligned == 1 ? 0 : 1; - size_t size32_unaligned = sizeof(glm::detail::storage::type); Error += size32_unaligned == 32 ? 0 : 1; - size_t align32_unaligned = alignof(glm::detail::storage::type); - Error += align32_unaligned == 1 ? 0 : 1; - size_t size64_unaligned = sizeof(glm::detail::storage::type); Error += size64_unaligned == 64 ? 0 : 1; + +# if GLM_HAS_ALIGNOF + + size_t align1_unaligned = alignof(glm::detail::storage::type); + Error += align1_unaligned == 1 ? 0 : 1; + size_t align2_unaligned = alignof(glm::detail::storage::type); + Error += align2_unaligned == 1 ? 0 : 1; + size_t align4_unaligned = alignof(glm::detail::storage::type); + Error += align4_unaligned == 1 ? 0 : 1; + size_t align8_unaligned = alignof(glm::detail::storage::type); + Error += align8_unaligned == 1 ? 0 : 1; + size_t align16_unaligned = alignof(glm::detail::storage::type); + Error += align16_unaligned == 1 ? 0 : 1; + size_t align32_unaligned = alignof(glm::detail::storage::type); + Error += align32_unaligned == 1 ? 0 : 1; size_t align64_unaligned = alignof(glm::detail::storage::type); Error += align64_unaligned == 1 ? 0 : 1; +# endif //GLM_HAS_ALIGNOF + return Error; } From 746efbeeda8de571ab5b5c4d988b516d9768c439 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Sun, 18 Sep 2016 19:09:30 +0200 Subject: [PATCH 12/19] Added test for GCC --- test/core/core_type_aligned.cpp | 34 +++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/test/core/core_type_aligned.cpp b/test/core/core_type_aligned.cpp index babf82a9..cbb591f0 100644 --- a/test/core/core_type_aligned.cpp +++ b/test/core/core_type_aligned.cpp @@ -36,6 +36,23 @@ int test_aligned() size_t align64_aligned = alignof(glm::detail::storage::type); Error += align64_aligned == 64 ? 0 : 1; +# elif GLM_COMPILER & GLM_COMPILER_GCC + + size_t align1_aligned = __alignof__(glm::detail::storage::type); + Error += align1_aligned == 1 ? 0 : 1; + size_t align2_aligned = __alignof__(glm::detail::storage::type); + Error += align2_aligned == 2 ? 0 : 1; + size_t align4_aligned = __alignof__(glm::detail::storage::type); + Error += align4_aligned == 4 ? 0 : 1; + size_t align8_aligned = __alignof__(glm::detail::storage::type); + Error += align8_aligned == 8 ? 0 : 1; + size_t align16_aligned = __alignof__(glm::detail::storage::type); + Error += align16_aligned == 16 ? 0 : 1; + size_t align32_aligned = __alignof__(glm::detail::storage::type); + Error += align32_aligned == 32 ? 0 : 1; + size_t align64_aligned = __alignof__(glm::detail::storage::type); + Error += align64_aligned == 64 ? 0 : 1; + # endif //GLM_HAS_ALIGNOF return Error; @@ -77,6 +94,23 @@ int test_unaligned() size_t align64_unaligned = alignof(glm::detail::storage::type); Error += align64_unaligned == 1 ? 0 : 1; +# else + + size_t align1_unaligned = __alignof__(glm::detail::storage::type); + Error += align1_unaligned == 1 ? 0 : 1; + size_t align2_unaligned = __alignof__(glm::detail::storage::type); + Error += align2_unaligned == 1 ? 0 : 1; + size_t align4_unaligned = __alignof__(glm::detail::storage::type); + Error += align4_unaligned == 1 ? 0 : 1; + size_t align8_unaligned = __alignof__(glm::detail::storage::type); + Error += align8_unaligned == 1 ? 0 : 1; + size_t align16_unaligned = __alignof__(glm::detail::storage::type); + Error += align16_unaligned == 1 ? 0 : 1; + size_t align32_unaligned = __alignof__(glm::detail::storage::type); + Error += align32_unaligned == 1 ? 0 : 1; + size_t align64_unaligned = __alignof__(glm::detail::storage::type); + Error += align64_unaligned == 1 ? 0 : 1; + # endif //GLM_HAS_ALIGNOF return Error; From ca0b7a9929c9b8ce28513613340ebde5a5f60177 Mon Sep 17 00:00:00 2001 From: Aaron Date: Tue, 13 Sep 2016 00:36:43 -0700 Subject: [PATCH 13/19] Merged graft commit --- glm/detail/type_vec.hpp | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/glm/detail/type_vec.hpp b/glm/detail/type_vec.hpp index 23e463e7..af8ed14a 100644 --- a/glm/detail/type_vec.hpp +++ b/glm/detail/type_vec.hpp @@ -9,15 +9,6 @@ namespace glm{ namespace detail { - template struct aligned {}; - template<> GLM_ALIGNED_STRUCT(1) aligned<1>{}; - template<> GLM_ALIGNED_STRUCT(2) aligned<2>{}; - template<> GLM_ALIGNED_STRUCT(4) aligned<4>{}; - template<> GLM_ALIGNED_STRUCT(8) aligned<8>{}; - template<> GLM_ALIGNED_STRUCT(16) aligned<16>{}; - template<> GLM_ALIGNED_STRUCT(32) aligned<32>{}; - template<> GLM_ALIGNED_STRUCT(64) aligned<64>{}; - template struct storage { @@ -26,15 +17,22 @@ namespace detail } type; }; - template - struct storage - { - struct type : aligned - { - uint8 data[size]; + #define GLM_ALIGNED_STORAGE_TYPE_STRUCT(x) \ + template \ + struct storage { \ + GLM_ALIGNED_STRUCT(x) type { \ + uint8_t data[x]; \ + }; \ }; - }; + GLM_ALIGNED_STORAGE_TYPE_STRUCT(1) + GLM_ALIGNED_STORAGE_TYPE_STRUCT(2) + GLM_ALIGNED_STORAGE_TYPE_STRUCT(4) + GLM_ALIGNED_STORAGE_TYPE_STRUCT(8) + GLM_ALIGNED_STORAGE_TYPE_STRUCT(16) + GLM_ALIGNED_STORAGE_TYPE_STRUCT(32) + GLM_ALIGNED_STORAGE_TYPE_STRUCT(64) + # if GLM_ARCH & GLM_ARCH_SSE2_BIT template <> struct storage From 6a30bbbe51d2b85a58e5fffd34655bc7631120c5 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Wed, 14 Sep 2016 22:01:30 +0200 Subject: [PATCH 14/19] Fixed GCC build broken by #548 PR --- glm/detail/type_vec.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glm/detail/type_vec.hpp b/glm/detail/type_vec.hpp index af8ed14a..7849db63 100644 --- a/glm/detail/type_vec.hpp +++ b/glm/detail/type_vec.hpp @@ -21,7 +21,7 @@ namespace detail template \ struct storage { \ GLM_ALIGNED_STRUCT(x) type { \ - uint8_t data[x]; \ + uint8 data[x]; \ }; \ }; From 24532ecbf17f456c5850c35419f783e11b971c71 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Wed, 14 Sep 2016 22:33:59 +0200 Subject: [PATCH 15/19] Added aligned storage tests #548 --- test/core/CMakeLists.txt | 1 + test/core/core_type_aligned.cpp | 104 ++++++++++++++++++++++++++++++++ 2 files changed, 105 insertions(+) create mode 100644 test/core/core_type_aligned.cpp diff --git a/test/core/CMakeLists.txt b/test/core/CMakeLists.txt index f83823d6..c2349c49 100644 --- a/test/core/CMakeLists.txt +++ b/test/core/CMakeLists.txt @@ -1,3 +1,4 @@ +glmCreateTestGTC(core_type_aligned) glmCreateTestGTC(core_type_cast) glmCreateTestGTC(core_type_ctor) glmCreateTestGTC(core_type_float) diff --git a/test/core/core_type_aligned.cpp b/test/core/core_type_aligned.cpp new file mode 100644 index 00000000..45f59688 --- /dev/null +++ b/test/core/core_type_aligned.cpp @@ -0,0 +1,104 @@ +#include +/* +#define GLM_ALIGNED(x) __declspec(align(x)) +#define GLM_ALIGNED_STRUCT(x) struct __declspec(align(x)) + +#define GLM_ALIGNED_STORAGE_TYPE_STRUCT(x) \ +template \ +struct storage { \ + GLM_ALIGNED_STRUCT(x) type { \ + uint8_t data[x]; \ + }; \ +}; + +template +struct storage { + typedef struct type { + uint8_t data[size]; + } type; +}; + +GLM_ALIGNED_STORAGE_TYPE_STRUCT(1) +GLM_ALIGNED_STORAGE_TYPE_STRUCT(2) +GLM_ALIGNED_STORAGE_TYPE_STRUCT(4) +GLM_ALIGNED_STORAGE_TYPE_STRUCT(8) +GLM_ALIGNED_STORAGE_TYPE_STRUCT(16) +GLM_ALIGNED_STORAGE_TYPE_STRUCT(32) +GLM_ALIGNED_STORAGE_TYPE_STRUCT(64) +*/ +int main() { + size_t size1_aligned = sizeof(glm::detail::storage::type); + size_t size2_aligned = sizeof(glm::detail::storage::type); + size_t size4_aligned = sizeof(glm::detail::storage::type); + size_t size8_aligned = sizeof(glm::detail::storage::type); + size_t size16_aligned = sizeof(glm::detail::storage::type); + size_t size32_aligned = sizeof(glm::detail::storage::type); + size_t size64_aligned = sizeof(glm::detail::storage::type); + size_t size128_aligned = sizeof(glm::detail::storage::type); + + size_t size1_unaligned = sizeof(glm::detail::storage::type); + size_t size2_unaligned = sizeof(glm::detail::storage::type); + size_t size4_unaligned = sizeof(glm::detail::storage::type); + size_t size8_unaligned = sizeof(glm::detail::storage::type); + size_t size16_unaligned = sizeof(glm::detail::storage::type); + size_t size32_unaligned = sizeof(glm::detail::storage::type); + size_t size64_unaligned = sizeof(glm::detail::storage::type); + size_t size128_unaligned = sizeof(glm::detail::storage::type); + + size_t align1_aligned = alignof(glm::detail::storage::type); + size_t align2_aligned = alignof(glm::detail::storage::type); + size_t align4_aligned = alignof(glm::detail::storage::type); + size_t align8_aligned = alignof(glm::detail::storage::type); + size_t align16_aligned = alignof(glm::detail::storage::type); + size_t align32_aligned = alignof(glm::detail::storage::type); + size_t align64_aligned = alignof(glm::detail::storage::type); + size_t align128_aligned = alignof(glm::detail::storage::type); + + size_t align1_unaligned = alignof(glm::detail::storage::type); + size_t align2_unaligned = alignof(glm::detail::storage::type); + size_t align4_unaligned = alignof(glm::detail::storage::type); + size_t align8_unaligned = alignof(glm::detail::storage::type); + size_t align16_unaligned = alignof(glm::detail::storage::type); + size_t align32_unaligned = alignof(glm::detail::storage::type); + size_t align64_unaligned = alignof(glm::detail::storage::type); + size_t align128_unaligned = alignof(glm::detail::storage::type); + + // RESULTS + // size1_aligned 1 + // size2_aligned 2 + // size4_aligned 4 + // size8_aligned 8 + // size16_aligned 16 + // size32_aligned 32 + // size64_aligned 64 + // size128_aligned 128 + // + // size1_unaligned 1 + // size2_unaligned 2 + // size4_unaligned 4 + // size8_unaligned 8 + // size16_unaligned 16 + // size32_unaligned 32 + // size64_unaligned 64 + // size128_unaligned 128 + // + // align1_aligned 1 + // align2_aligned 2 + // align4_aligned 4 + // align8_aligned 8 + // align16_aligned 16 + // align32_aligned 32 + // align64_aligned 64 + // align128_aligned 1 + // + // align1_unaligned 1 + // align2_unaligned 1 + // align4_unaligned 1 + // align8_unaligned 1 + // align16_unaligned 1 + // align32_unaligned 1 + // align64_unaligned 1 + // align128_unaligned 1 + + return 0; +} From d8e30c5fdeaa3df762435384c1b88da63759d401 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Wed, 14 Sep 2016 23:18:52 +0200 Subject: [PATCH 16/19] Improved core_type_aligned test --- test/core/core_type_aligned.cpp | 182 +++++++++++++++----------------- 1 file changed, 87 insertions(+), 95 deletions(-) diff --git a/test/core/core_type_aligned.cpp b/test/core/core_type_aligned.cpp index 45f59688..be15e9d8 100644 --- a/test/core/core_type_aligned.cpp +++ b/test/core/core_type_aligned.cpp @@ -1,104 +1,96 @@ #include -/* -#define GLM_ALIGNED(x) __declspec(align(x)) -#define GLM_ALIGNED_STRUCT(x) struct __declspec(align(x)) -#define GLM_ALIGNED_STORAGE_TYPE_STRUCT(x) \ -template \ -struct storage { \ - GLM_ALIGNED_STRUCT(x) type { \ - uint8_t data[x]; \ - }; \ -}; +int test_aligned() +{ + int Error = 0; -template -struct storage { - typedef struct type { - uint8_t data[size]; - } type; -}; + size_t size1_aligned = sizeof(glm::detail::storage::type); + Error += size1_aligned == 1 ? 0 : 1; + size_t align1_aligned = alignof(glm::detail::storage::type); + Error += align1_aligned == 1 ? 0 : 1; -GLM_ALIGNED_STORAGE_TYPE_STRUCT(1) -GLM_ALIGNED_STORAGE_TYPE_STRUCT(2) -GLM_ALIGNED_STORAGE_TYPE_STRUCT(4) -GLM_ALIGNED_STORAGE_TYPE_STRUCT(8) -GLM_ALIGNED_STORAGE_TYPE_STRUCT(16) -GLM_ALIGNED_STORAGE_TYPE_STRUCT(32) -GLM_ALIGNED_STORAGE_TYPE_STRUCT(64) -*/ -int main() { - size_t size1_aligned = sizeof(glm::detail::storage::type); - size_t size2_aligned = sizeof(glm::detail::storage::type); - size_t size4_aligned = sizeof(glm::detail::storage::type); - size_t size8_aligned = sizeof(glm::detail::storage::type); - size_t size16_aligned = sizeof(glm::detail::storage::type); - size_t size32_aligned = sizeof(glm::detail::storage::type); - size_t size64_aligned = sizeof(glm::detail::storage::type); - size_t size128_aligned = sizeof(glm::detail::storage::type); + size_t size2_aligned = sizeof(glm::detail::storage::type); + Error += size2_aligned == 2 ? 0 : 1; + size_t align2_aligned = alignof(glm::detail::storage::type); + Error += align2_aligned == 2 ? 0 : 1; - size_t size1_unaligned = sizeof(glm::detail::storage::type); - size_t size2_unaligned = sizeof(glm::detail::storage::type); - size_t size4_unaligned = sizeof(glm::detail::storage::type); - size_t size8_unaligned = sizeof(glm::detail::storage::type); - size_t size16_unaligned = sizeof(glm::detail::storage::type); - size_t size32_unaligned = sizeof(glm::detail::storage::type); - size_t size64_unaligned = sizeof(glm::detail::storage::type); - size_t size128_unaligned = sizeof(glm::detail::storage::type); + size_t size4_aligned = sizeof(glm::detail::storage::type); + Error += size4_aligned == 4 ? 0 : 1; + size_t align4_aligned = alignof(glm::detail::storage::type); + Error += align4_aligned == 4 ? 0 : 1; - size_t align1_aligned = alignof(glm::detail::storage::type); - size_t align2_aligned = alignof(glm::detail::storage::type); - size_t align4_aligned = alignof(glm::detail::storage::type); - size_t align8_aligned = alignof(glm::detail::storage::type); - size_t align16_aligned = alignof(glm::detail::storage::type); - size_t align32_aligned = alignof(glm::detail::storage::type); - size_t align64_aligned = alignof(glm::detail::storage::type); - size_t align128_aligned = alignof(glm::detail::storage::type); + size_t size8_aligned = sizeof(glm::detail::storage::type); + Error += size8_aligned == 8 ? 0 : 1; + size_t align8_aligned = alignof(glm::detail::storage::type); + Error += align8_aligned == 8 ? 0 : 1; - size_t align1_unaligned = alignof(glm::detail::storage::type); - size_t align2_unaligned = alignof(glm::detail::storage::type); - size_t align4_unaligned = alignof(glm::detail::storage::type); - size_t align8_unaligned = alignof(glm::detail::storage::type); - size_t align16_unaligned = alignof(glm::detail::storage::type); - size_t align32_unaligned = alignof(glm::detail::storage::type); - size_t align64_unaligned = alignof(glm::detail::storage::type); - size_t align128_unaligned = alignof(glm::detail::storage::type); + size_t size16_aligned = sizeof(glm::detail::storage::type); + Error += size16_aligned == 16 ? 0 : 1; + size_t align16_aligned = alignof(glm::detail::storage::type); + Error += align16_aligned == 16 ? 0 : 1; - // RESULTS - // size1_aligned 1 - // size2_aligned 2 - // size4_aligned 4 - // size8_aligned 8 - // size16_aligned 16 - // size32_aligned 32 - // size64_aligned 64 - // size128_aligned 128 - // - // size1_unaligned 1 - // size2_unaligned 2 - // size4_unaligned 4 - // size8_unaligned 8 - // size16_unaligned 16 - // size32_unaligned 32 - // size64_unaligned 64 - // size128_unaligned 128 - // - // align1_aligned 1 - // align2_aligned 2 - // align4_aligned 4 - // align8_aligned 8 - // align16_aligned 16 - // align32_aligned 32 - // align64_aligned 64 - // align128_aligned 1 - // - // align1_unaligned 1 - // align2_unaligned 1 - // align4_unaligned 1 - // align8_unaligned 1 - // align16_unaligned 1 - // align32_unaligned 1 - // align64_unaligned 1 - // align128_unaligned 1 - - return 0; + size_t size32_aligned = sizeof(glm::detail::storage::type); + Error += size32_aligned == 32 ? 0 : 1; + size_t align32_aligned = alignof(glm::detail::storage::type); + Error += align32_aligned == 32 ? 0 : 1; + + size_t size64_aligned = sizeof(glm::detail::storage::type); + Error += size64_aligned == 64 ? 0 : 1; + size_t align64_aligned = alignof(glm::detail::storage::type); + Error += align64_aligned == 64 ? 0 : 1; + + return Error; +} + +int test_unaligned() +{ + int Error = 0; + + size_t size1_unaligned = sizeof(glm::detail::storage::type); + Error += size1_unaligned == 1 ? 0 : 1; + size_t align1_unaligned = alignof(glm::detail::storage::type); + Error += align1_unaligned == 1 ? 0 : 1; + + size_t size2_unaligned = sizeof(glm::detail::storage::type); + Error += size2_unaligned == 2 ? 0 : 1; + size_t align2_unaligned = alignof(glm::detail::storage::type); + Error += align2_unaligned == 1 ? 0 : 1; + + size_t size4_unaligned = sizeof(glm::detail::storage::type); + Error += size4_unaligned == 4 ? 0 : 1; + size_t align4_unaligned = alignof(glm::detail::storage::type); + Error += align4_unaligned == 1 ? 0 : 1; + + size_t size8_unaligned = sizeof(glm::detail::storage::type); + Error += size8_unaligned == 8 ? 0 : 1; + size_t align8_unaligned = alignof(glm::detail::storage::type); + Error += align8_unaligned == 1 ? 0 : 1; + + size_t size16_unaligned = sizeof(glm::detail::storage::type); + Error += size16_unaligned == 16 ? 0 : 1; + size_t align16_unaligned = alignof(glm::detail::storage::type); + Error += align16_unaligned == 1 ? 0 : 1; + + size_t size32_unaligned = sizeof(glm::detail::storage::type); + Error += size32_unaligned == 32 ? 0 : 1; + size_t align32_unaligned = alignof(glm::detail::storage::type); + Error += align32_unaligned == 1 ? 0 : 1; + + size_t size64_unaligned = sizeof(glm::detail::storage::type); + Error += size64_unaligned == 64 ? 0 : 1; + size_t align64_unaligned = alignof(glm::detail::storage::type); + Error += align64_unaligned == 1 ? 0 : 1; + + return Error; +} + + +int main() +{ + int Error = 0; + + Error += test_aligned(); + Error += test_unaligned(); + + return Error; } From 8c960dc647c54919b9f6f289d97f24f5761371a2 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Wed, 14 Sep 2016 23:38:43 +0200 Subject: [PATCH 17/19] Alignof is a C++11 feature --- glm/detail/setup.hpp | 13 ++++++ test/core/core_type_aligned.cpp | 70 ++++++++++++++++----------------- 2 files changed, 47 insertions(+), 36 deletions(-) diff --git a/glm/detail/setup.hpp b/glm/detail/setup.hpp index 4b0259b6..49ca9beb 100644 --- a/glm/detail/setup.hpp +++ b/glm/detail/setup.hpp @@ -424,6 +424,19 @@ ((GLM_COMPILER & GLM_COMPILER_CUDA) && (GLM_COMPILER >= GLM_COMPILER_CUDA50)))) #endif +// N2341 http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2341.pdf +#if GLM_COMPILER & GLM_COMPILER_CLANG +# define GLM_HAS_ALIGNOF __has_feature(c_alignof) +#elif GLM_LANG & GLM_LANG_CXX11_FLAG +# define GLM_HAS_ALIGNOF 1 +#else +# define GLM_HAS_ALIGNOF ((GLM_LANG & GLM_LANG_CXX0X_FLAG) && (\ + ((GLM_COMPILER & GLM_COMPILER_GCC) && (GLM_COMPILER >= GLM_COMPILER_GCC48)) || \ + ((GLM_COMPILER & GLM_COMPILER_INTEL) && (GLM_COMPILER >= GLM_COMPILER_INTEL15)) || \ + ((GLM_COMPILER & GLM_COMPILER_VC) && (GLM_COMPILER >= GLM_COMPILER_VC2015)) || \ + ((GLM_COMPILER & GLM_COMPILER_CUDA) && (GLM_COMPILER >= GLM_COMPILER_CUDA70)))) +#endif + // #if GLM_LANG & GLM_LANG_CXX11_FLAG # define GLM_HAS_ASSIGNABLE 1 diff --git a/test/core/core_type_aligned.cpp b/test/core/core_type_aligned.cpp index be15e9d8..babf82a9 100644 --- a/test/core/core_type_aligned.cpp +++ b/test/core/core_type_aligned.cpp @@ -6,39 +6,38 @@ int test_aligned() size_t size1_aligned = sizeof(glm::detail::storage::type); Error += size1_aligned == 1 ? 0 : 1; - size_t align1_aligned = alignof(glm::detail::storage::type); - Error += align1_aligned == 1 ? 0 : 1; - size_t size2_aligned = sizeof(glm::detail::storage::type); Error += size2_aligned == 2 ? 0 : 1; - size_t align2_aligned = alignof(glm::detail::storage::type); - Error += align2_aligned == 2 ? 0 : 1; - size_t size4_aligned = sizeof(glm::detail::storage::type); Error += size4_aligned == 4 ? 0 : 1; - size_t align4_aligned = alignof(glm::detail::storage::type); - Error += align4_aligned == 4 ? 0 : 1; - size_t size8_aligned = sizeof(glm::detail::storage::type); Error += size8_aligned == 8 ? 0 : 1; - size_t align8_aligned = alignof(glm::detail::storage::type); - Error += align8_aligned == 8 ? 0 : 1; - size_t size16_aligned = sizeof(glm::detail::storage::type); Error += size16_aligned == 16 ? 0 : 1; - size_t align16_aligned = alignof(glm::detail::storage::type); - Error += align16_aligned == 16 ? 0 : 1; - size_t size32_aligned = sizeof(glm::detail::storage::type); Error += size32_aligned == 32 ? 0 : 1; - size_t align32_aligned = alignof(glm::detail::storage::type); - Error += align32_aligned == 32 ? 0 : 1; - size_t size64_aligned = sizeof(glm::detail::storage::type); Error += size64_aligned == 64 ? 0 : 1; + +# if GLM_HAS_ALIGNOF + + size_t align1_aligned = alignof(glm::detail::storage::type); + Error += align1_aligned == 1 ? 0 : 1; + size_t align2_aligned = alignof(glm::detail::storage::type); + Error += align2_aligned == 2 ? 0 : 1; + size_t align4_aligned = alignof(glm::detail::storage::type); + Error += align4_aligned == 4 ? 0 : 1; + size_t align8_aligned = alignof(glm::detail::storage::type); + Error += align8_aligned == 8 ? 0 : 1; + size_t align16_aligned = alignof(glm::detail::storage::type); + Error += align16_aligned == 16 ? 0 : 1; + size_t align32_aligned = alignof(glm::detail::storage::type); + Error += align32_aligned == 32 ? 0 : 1; size_t align64_aligned = alignof(glm::detail::storage::type); Error += align64_aligned == 64 ? 0 : 1; +# endif //GLM_HAS_ALIGNOF + return Error; } @@ -48,39 +47,38 @@ int test_unaligned() size_t size1_unaligned = sizeof(glm::detail::storage::type); Error += size1_unaligned == 1 ? 0 : 1; - size_t align1_unaligned = alignof(glm::detail::storage::type); - Error += align1_unaligned == 1 ? 0 : 1; - size_t size2_unaligned = sizeof(glm::detail::storage::type); Error += size2_unaligned == 2 ? 0 : 1; - size_t align2_unaligned = alignof(glm::detail::storage::type); - Error += align2_unaligned == 1 ? 0 : 1; - size_t size4_unaligned = sizeof(glm::detail::storage::type); Error += size4_unaligned == 4 ? 0 : 1; - size_t align4_unaligned = alignof(glm::detail::storage::type); - Error += align4_unaligned == 1 ? 0 : 1; - size_t size8_unaligned = sizeof(glm::detail::storage::type); Error += size8_unaligned == 8 ? 0 : 1; - size_t align8_unaligned = alignof(glm::detail::storage::type); - Error += align8_unaligned == 1 ? 0 : 1; - size_t size16_unaligned = sizeof(glm::detail::storage::type); Error += size16_unaligned == 16 ? 0 : 1; - size_t align16_unaligned = alignof(glm::detail::storage::type); - Error += align16_unaligned == 1 ? 0 : 1; - size_t size32_unaligned = sizeof(glm::detail::storage::type); Error += size32_unaligned == 32 ? 0 : 1; - size_t align32_unaligned = alignof(glm::detail::storage::type); - Error += align32_unaligned == 1 ? 0 : 1; - size_t size64_unaligned = sizeof(glm::detail::storage::type); Error += size64_unaligned == 64 ? 0 : 1; + +# if GLM_HAS_ALIGNOF + + size_t align1_unaligned = alignof(glm::detail::storage::type); + Error += align1_unaligned == 1 ? 0 : 1; + size_t align2_unaligned = alignof(glm::detail::storage::type); + Error += align2_unaligned == 1 ? 0 : 1; + size_t align4_unaligned = alignof(glm::detail::storage::type); + Error += align4_unaligned == 1 ? 0 : 1; + size_t align8_unaligned = alignof(glm::detail::storage::type); + Error += align8_unaligned == 1 ? 0 : 1; + size_t align16_unaligned = alignof(glm::detail::storage::type); + Error += align16_unaligned == 1 ? 0 : 1; + size_t align32_unaligned = alignof(glm::detail::storage::type); + Error += align32_unaligned == 1 ? 0 : 1; size_t align64_unaligned = alignof(glm::detail::storage::type); Error += align64_unaligned == 1 ? 0 : 1; +# endif //GLM_HAS_ALIGNOF + return Error; } From b719a9f6cc7b5128577f01bc9019085d0b95fe3a Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Sun, 18 Sep 2016 19:09:30 +0200 Subject: [PATCH 18/19] Added test for GCC --- test/core/core_type_aligned.cpp | 34 +++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/test/core/core_type_aligned.cpp b/test/core/core_type_aligned.cpp index babf82a9..cbb591f0 100644 --- a/test/core/core_type_aligned.cpp +++ b/test/core/core_type_aligned.cpp @@ -36,6 +36,23 @@ int test_aligned() size_t align64_aligned = alignof(glm::detail::storage::type); Error += align64_aligned == 64 ? 0 : 1; +# elif GLM_COMPILER & GLM_COMPILER_GCC + + size_t align1_aligned = __alignof__(glm::detail::storage::type); + Error += align1_aligned == 1 ? 0 : 1; + size_t align2_aligned = __alignof__(glm::detail::storage::type); + Error += align2_aligned == 2 ? 0 : 1; + size_t align4_aligned = __alignof__(glm::detail::storage::type); + Error += align4_aligned == 4 ? 0 : 1; + size_t align8_aligned = __alignof__(glm::detail::storage::type); + Error += align8_aligned == 8 ? 0 : 1; + size_t align16_aligned = __alignof__(glm::detail::storage::type); + Error += align16_aligned == 16 ? 0 : 1; + size_t align32_aligned = __alignof__(glm::detail::storage::type); + Error += align32_aligned == 32 ? 0 : 1; + size_t align64_aligned = __alignof__(glm::detail::storage::type); + Error += align64_aligned == 64 ? 0 : 1; + # endif //GLM_HAS_ALIGNOF return Error; @@ -77,6 +94,23 @@ int test_unaligned() size_t align64_unaligned = alignof(glm::detail::storage::type); Error += align64_unaligned == 1 ? 0 : 1; +# else + + size_t align1_unaligned = __alignof__(glm::detail::storage::type); + Error += align1_unaligned == 1 ? 0 : 1; + size_t align2_unaligned = __alignof__(glm::detail::storage::type); + Error += align2_unaligned == 1 ? 0 : 1; + size_t align4_unaligned = __alignof__(glm::detail::storage::type); + Error += align4_unaligned == 1 ? 0 : 1; + size_t align8_unaligned = __alignof__(glm::detail::storage::type); + Error += align8_unaligned == 1 ? 0 : 1; + size_t align16_unaligned = __alignof__(glm::detail::storage::type); + Error += align16_unaligned == 1 ? 0 : 1; + size_t align32_unaligned = __alignof__(glm::detail::storage::type); + Error += align32_unaligned == 1 ? 0 : 1; + size_t align64_unaligned = __alignof__(glm::detail::storage::type); + Error += align64_unaligned == 1 ? 0 : 1; + # endif //GLM_HAS_ALIGNOF return Error; From 695f853ae0ed50592044f3da0fbec3fc235854a3 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Sun, 18 Sep 2016 19:40:49 +0200 Subject: [PATCH 19/19] Updated readme for fixed Visual Studio aligned type W4 warning #548 --- readme.md | 1 + 1 file changed, 1 insertion(+) diff --git a/readme.md b/readme.md index 66187677..ca9d888a 100644 --- a/readme.md +++ b/readme.md @@ -56,6 +56,7 @@ glm::mat4 camera(float Translate, glm::vec2 const & Rotate) - Fixed GCC warning filtering, replaced -pedantic by -Wpedantic - Fixed SIMD faceforward bug. #549 - Fixed GCC 4.8 with C++11 compilation option #550 +- Fixed Visual Studio aligned type W4 warning #548 #### [GLM 0.9.8.0](https://github.com/g-truc/glm/releases/tag/0.9.8.0) - 2016-09-11 ##### Features: