diff --git a/glm/detail/func_integer.inl b/glm/detail/func_integer.inl index 25910eb0..47be412a 100644 --- a/glm/detail/func_integer.inl +++ b/glm/detail/func_integer.inl @@ -317,6 +317,10 @@ namespace detail template class vecType> GLM_FUNC_QUALIFIER vecType bitCount(vecType const & v) { + #if GLM_COMPILER & GLM_COMPILER_VC + #pragma warning(push) + #pragma warning(disable : 4310) //cast truncates constant value + #endif vecType::type, P> x(*reinterpret_cast::type, P> const *>(&v)); x = detail::compute_bitfieldBitCountStep::type, P, vecType, detail::is_aligned

::value, sizeof(T) * 8>= 2>::call(x, typename detail::make_unsigned::type(0x5555555555555555ull), typename detail::make_unsigned::type( 1)); x = detail::compute_bitfieldBitCountStep::type, P, vecType, detail::is_aligned

::value, sizeof(T) * 8>= 4>::call(x, typename detail::make_unsigned::type(0x3333333333333333ull), typename detail::make_unsigned::type( 2)); @@ -325,6 +329,9 @@ 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); + #if GLM_COMPILER & GLM_COMPILER_VC + #pragma warning(pop) + #endif } // findLSB 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/glm/detail/type_vec.hpp b/glm/detail/type_vec.hpp index 23e463e7..7849db63 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 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 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..babf82a9 --- /dev/null +++ b/test/core/core_type_aligned.cpp @@ -0,0 +1,94 @@ +#include + +int test_aligned() +{ + int Error = 0; + + size_t size1_aligned = sizeof(glm::detail::storage::type); + Error += size1_aligned == 1 ? 0 : 1; + size_t size2_aligned = sizeof(glm::detail::storage::type); + Error += size2_aligned == 2 ? 0 : 1; + size_t size4_aligned = sizeof(glm::detail::storage::type); + Error += size4_aligned == 4 ? 0 : 1; + size_t size8_aligned = sizeof(glm::detail::storage::type); + Error += size8_aligned == 8 ? 0 : 1; + size_t size16_aligned = sizeof(glm::detail::storage::type); + Error += size16_aligned == 16 ? 0 : 1; + size_t size32_aligned = sizeof(glm::detail::storage::type); + Error += size32_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; +} + +int test_unaligned() +{ + int Error = 0; + + size_t size1_unaligned = sizeof(glm::detail::storage::type); + Error += size1_unaligned == 1 ? 0 : 1; + size_t size2_unaligned = sizeof(glm::detail::storage::type); + Error += size2_unaligned == 2 ? 0 : 1; + size_t size4_unaligned = sizeof(glm::detail::storage::type); + Error += size4_unaligned == 4 ? 0 : 1; + size_t size8_unaligned = sizeof(glm::detail::storage::type); + Error += size8_unaligned == 8 ? 0 : 1; + size_t size16_unaligned = sizeof(glm::detail::storage::type); + Error += size16_unaligned == 16 ? 0 : 1; + size_t size32_unaligned = sizeof(glm::detail::storage::type); + Error += size32_unaligned == 32 ? 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; +} + + +int main() +{ + int Error = 0; + + Error += test_aligned(); + Error += test_unaligned(); + + return Error; +}