From 76d12fb6025f1c8149bff3ba87266e6b003a260e Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Fri, 29 Apr 2016 10:51:21 +0200 Subject: [PATCH 1/5] Fixed roundPowerOfTwo and floorPowerOfTwo #503 --- glm/gtc/round.inl | 9 +++++---- test/gtc/gtc_round.cpp | 28 ++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/glm/gtc/round.inl b/glm/gtc/round.inl index 94fdd54b..c816089f 100644 --- a/glm/gtc/round.inl +++ b/glm/gtc/round.inl @@ -30,8 +30,9 @@ /// @author Christophe Riccio /////////////////////////////////////////////////////////////////////////////////// -namespace glm -{ +#include "../detail/func_integer.hpp" + +namespace glm{ namespace detail { template class vecType, bool compute = false> @@ -275,7 +276,7 @@ namespace detail template GLM_FUNC_QUALIFIER genType floorPowerOfTwo(genType value) { - return isPowerOfTwo(value) ? value : highestBitValue(value); + return isPowerOfTwo(value) ? value : findMSB(value); } template class vecType> @@ -293,7 +294,7 @@ namespace detail if(isPowerOfTwo(value)) return value; - genIUType const prev = highestBitValue(value); + genIUType const prev = findMSB(value); genIUType const next = prev << 1; return (next - value) < (value - prev) ? next : prev; } diff --git a/test/gtc/gtc_round.cpp b/test/gtc/gtc_round.cpp index aa6cf1a1..97b2abfd 100644 --- a/test/gtc/gtc_round.cpp +++ b/test/gtc/gtc_round.cpp @@ -294,6 +294,32 @@ namespace ceilPowerOfTwo } }//namespace ceilPowerOfTwo +namespace roundPowerOfTwo +{ + int test() + { + int Error = 0; + + glm::uint32 const A = glm::roundPowerOfTwo(7u); + Error += A == 8u ? 0 : 1; + + return Error; + } +}//namespace roundPowerOfTwo + +namespace floorPowerOfTwo +{ + int test() + { + int Error = 0; + + glm::uint32 const A = glm::floorPowerOfTwo(7u); + Error += A == 4u ? 0 : 1; + + return Error; + } +}//namespace floorPowerOfTwo + namespace floorMultiple { template @@ -380,6 +406,8 @@ int main() Error += isPowerOfTwo::test(); Error += ceilPowerOfTwo::test(); + Error += floorPowerOfTwo::test(); + Error += roundPowerOfTwo::test(); # ifdef NDEBUG Error += ceilPowerOfTwo::perf(); From e0d312ccafcb318dc45a5bd441ac961753d6c1fc Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Fri, 29 Apr 2016 10:52:04 +0200 Subject: [PATCH 2/5] Fixed roundPowerOfTwo and floorPowerOfTwo #503 --- readme.md | 1 + 1 file changed, 1 insertion(+) diff --git a/readme.md b/readme.md index cf93b453..5a35b7b8 100644 --- a/readme.md +++ b/readme.md @@ -54,6 +54,7 @@ glm::mat4 camera(float Translate, glm::vec2 const & Rotate) #### [GLM 0.9.7.5](https://github.com/g-truc/glm/tree/0.9.7) - 2016-0X-XX ##### Fixes: - Fixed uaddCarry warning #497 +- Fixed roundPowerOfTwo and floorPowerOfTwo #503 #### [GLM 0.9.7.4](https://github.com/g-truc/glm/releases/tag/0.9.7.4) - 2016-03-19 ##### Fixes: From 68ec048b7021ac1f37a917532302465816a276da Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Fri, 29 Apr 2016 17:24:35 +0200 Subject: [PATCH 3/5] Fixed roundPowerOfTwo and floorPowerOfTwo #503 --- glm/gtc/round.inl | 6 +++--- test/gtc/gtc_round.cpp | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/glm/gtc/round.inl b/glm/gtc/round.inl index c816089f..988c64a1 100644 --- a/glm/gtc/round.inl +++ b/glm/gtc/round.inl @@ -276,7 +276,7 @@ namespace detail template GLM_FUNC_QUALIFIER genType floorPowerOfTwo(genType value) { - return isPowerOfTwo(value) ? value : findMSB(value); + return isPowerOfTwo(value) ? value : static_cast(1) << findMSB(value); } template class vecType> @@ -294,8 +294,8 @@ namespace detail if(isPowerOfTwo(value)) return value; - genIUType const prev = findMSB(value); - genIUType const next = prev << 1; + genIUType const prev = static_cast(1) << findMSB(value); + genIUType const next = prev << static_cast(1); return (next - value) < (value - prev) ? next : prev; } diff --git a/test/gtc/gtc_round.cpp b/test/gtc/gtc_round.cpp index 97b2abfd..ba57a786 100644 --- a/test/gtc/gtc_round.cpp +++ b/test/gtc/gtc_round.cpp @@ -303,6 +303,21 @@ namespace roundPowerOfTwo glm::uint32 const A = glm::roundPowerOfTwo(7u); Error += A == 8u ? 0 : 1; + glm::uint32 const B = glm::roundPowerOfTwo(15u); + Error += B == 16u ? 0 : 1; + + glm::uint32 const C = glm::roundPowerOfTwo(31u); + Error += C == 32u ? 0 : 1; + + glm::uint32 const D = glm::roundPowerOfTwo(9u); + Error += D == 8u ? 0 : 1; + + glm::uint32 const E = glm::roundPowerOfTwo(17u); + Error += E == 16u ? 0 : 1; + + glm::uint32 const F = glm::roundPowerOfTwo(33u); + Error += F == 32u ? 0 : 1; + return Error; } }//namespace roundPowerOfTwo @@ -316,6 +331,12 @@ namespace floorPowerOfTwo glm::uint32 const A = glm::floorPowerOfTwo(7u); Error += A == 4u ? 0 : 1; + glm::uint32 const B = glm::floorPowerOfTwo(15u); + Error += B == 8u ? 0 : 1; + + glm::uint32 const C = glm::floorPowerOfTwo(31u); + Error += C == 16u ? 0 : 1; + return Error; } }//namespace floorPowerOfTwo From 872aa9d8ec939309c3382cd91bbfde049186cd1d Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Fri, 29 Apr 2016 17:31:36 +0200 Subject: [PATCH 4/5] Improved ***PowerOfTwo --- test/gtc/gtc_round.cpp | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/test/gtc/gtc_round.cpp b/test/gtc/gtc_round.cpp index ba57a786..bfb7e552 100644 --- a/test/gtc/gtc_round.cpp +++ b/test/gtc/gtc_round.cpp @@ -174,7 +174,7 @@ namespace isPowerOfTwo } }//isPowerOfTwo -namespace ceilPowerOfTwo +namespace ceilPowerOfTwo_advanced { template GLM_FUNC_QUALIFIER genIUType highestBitValue(genIUType Value) @@ -292,7 +292,7 @@ namespace ceilPowerOfTwo return Error; } -}//namespace ceilPowerOfTwo +}//namespace ceilPowerOfTwo_advanced namespace roundPowerOfTwo { @@ -341,6 +341,25 @@ namespace floorPowerOfTwo } }//namespace floorPowerOfTwo +namespace ceilPowerOfTwo +{ + int test() + { + int Error = 0; + + glm::uint32 const A = glm::ceilPowerOfTwo(7u); + Error += A == 8u ? 0 : 1; + + glm::uint32 const B = glm::ceilPowerOfTwo(15u); + Error += B == 16u ? 0 : 1; + + glm::uint32 const C = glm::ceilPowerOfTwo(31u); + Error += C == 32u ? 0 : 1; + + return Error; + } +}//namespace ceilPowerOfTwo + namespace floorMultiple { template @@ -426,10 +445,11 @@ int main() int Error(0); Error += isPowerOfTwo::test(); - Error += ceilPowerOfTwo::test(); Error += floorPowerOfTwo::test(); Error += roundPowerOfTwo::test(); - + Error += ceilPowerOfTwo::test(); + Error += ceilPowerOfTwo_advanced::test(); + # ifdef NDEBUG Error += ceilPowerOfTwo::perf(); # endif//NDEBUG From e9bb34fb78b3e54d1fabb8d05642e36af4382db8 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Sat, 30 Apr 2016 16:23:55 +0200 Subject: [PATCH 5/5] - Fixed Visual C++ SIMD instruction set automatic detection in 64 bits --- glm/detail/setup.hpp | 8 +++++++- readme.md | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/glm/detail/setup.hpp b/glm/detail/setup.hpp index 1d6ffca1..9c7f209e 100644 --- a/glm/detail/setup.hpp +++ b/glm/detail/setup.hpp @@ -423,8 +423,14 @@ # define GLM_ARCH (GLM_ARCH_AVX2 | GLM_ARCH_AVX | GLM_ARCH_SSE4 | GLM_ARCH_SSE3 | GLM_ARCH_SSE2) # elif defined(__AVX__) # define GLM_ARCH (GLM_ARCH_AVX | GLM_ARCH_SSE4 | GLM_ARCH_SSE3 | GLM_ARCH_SSE2) -# elif _M_IX86_FP == 2 +# elif defined(_M_X64) # define GLM_ARCH (GLM_ARCH_SSE2) +# elif defined(_M_IX86_FP) +# if _M_IX86_FP >= 2 +# define GLM_ARCH (GLM_ARCH_SSE2) +# else +# define GLM_ARCH (GLM_ARCH_PURE) +# endif # else # define GLM_ARCH (GLM_ARCH_PURE) # endif diff --git a/readme.md b/readme.md index cf93b453..16944885 100644 --- a/readme.md +++ b/readme.md @@ -54,6 +54,8 @@ glm::mat4 camera(float Translate, glm::vec2 const & Rotate) #### [GLM 0.9.7.5](https://github.com/g-truc/glm/tree/0.9.7) - 2016-0X-XX ##### Fixes: - Fixed uaddCarry warning #497 +- Fixed roundPowerOfTwo and floorPowerOfTwo #503 +- Fixed Visual C++ SIMD instruction set automatic detection in 64 bits #### [GLM 0.9.7.4](https://github.com/g-truc/glm/releases/tag/0.9.7.4) - 2016-03-19 ##### Fixes: