From 062ee19ac763e0f3ed66c6ffb575e6aa3075d12d Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Wed, 12 Nov 2014 22:48:15 +0100 Subject: [PATCH] Fixed bitfieldInsert and bitfieldExtract --- glm/detail/func_integer.inl | 2 +- test/core/core_func_common.cpp | 6 +++--- test/core/core_func_integer.cpp | 13 +++++++------ test/gtc/gtc_bitfield.cpp | 20 ++++++++++++-------- 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/glm/detail/func_integer.inl b/glm/detail/func_integer.inl index 1c05a09b..d6e94e99 100644 --- a/glm/detail/func_integer.inl +++ b/glm/detail/func_integer.inl @@ -44,7 +44,7 @@ namespace detail { GLM_FUNC_QUALIFIER int mask(int Bits) { - return ~((~0) << Bits); + return Bits >= 32 ? 0xffffffff : (static_cast(1) << Bits) - static_cast(1); } }//namespace detail diff --git a/test/core/core_func_common.cpp b/test/core/core_func_common.cpp index ee75fbf8..61256f30 100644 --- a/test/core/core_func_common.cpp +++ b/test/core/core_func_common.cpp @@ -866,7 +866,7 @@ namespace sign { int Error = 0; - std::size_t const Count = 1000000000; + std::size_t const Count = 10000000; std::vector Input, Output; Input.resize(Count); Output.resize(Count); @@ -913,7 +913,7 @@ namespace sign { int Error = 0; - std::size_t const Count = 1000000000; + std::size_t const Count = 10000000; std::vector Input, Output; Input.resize(Count); Output.resize(Count); @@ -960,7 +960,7 @@ namespace sign { int Error = 0; - glm::uint32 const Count = 1000000000; + glm::uint32 const Count = 10000000; std::clock_t Timestamp0 = std::clock(); glm::int32 Sum = 0; diff --git a/test/core/core_func_integer.cpp b/test/core/core_func_integer.cpp index 4a75733e..cb07d752 100644 --- a/test/core/core_func_integer.cpp +++ b/test/core/core_func_integer.cpp @@ -37,11 +37,12 @@ namespace bitfieldInsert typeU32 const Data32[] = { + {0x00000000, 0xffffffff, 0, 31, 0x7fffffff}, + {0x00000000, 0xffffffff, 0, 32, 0xffffffff}, + {0x00000000, 0xffffffff, 0, 0, 0x00000000}, {0xff000000, 0x0000ff00, 8, 8, 0xff00ff00}, {0xffff0000, 0x0000ffff, 16, 16, 0x00000000}, - {0x0000ffff, 0xffff0000, 16, 16, 0xffffffff}, - {0x00000000, 0xffffffff, 0, 32, 0xffffffff}, - {0x00000000, 0xffffffff, 0, 0, 0x00000000} + {0x0000ffff, 0xffff0000, 16, 16, 0xffffffff} }; int test() @@ -342,7 +343,7 @@ namespace findMSB std::clock_t Timestamps1 = std::clock(); - for(std::size_t k = 0; k < 10000000; ++k) + for(std::size_t k = 0; k < 1000000; ++k) for(std::size_t i = 0; i < sizeof(Data) / sizeof(type); ++i) { int Result = findMSB_095(Data[i].Value); @@ -401,7 +402,7 @@ namespace findMSB std::clock_t Timestamps1 = std::clock(); - for(std::size_t k = 0; k < 10000000; ++k) + for(std::size_t k = 0; k < 1000000; ++k) for(std::size_t i = 0; i < sizeof(Data) / sizeof(type); ++i) { int Result = findMSB_nlz1(Data[i].Value); @@ -536,7 +537,7 @@ namespace findMSB int Error(0); Error += perf_950(); - Error += perf_ops(); + //Error += perf_ops(); return Error; } diff --git a/test/gtc/gtc_bitfield.cpp b/test/gtc/gtc_bitfield.cpp index eed75a44..2763e874 100644 --- a/test/gtc/gtc_bitfield.cpp +++ b/test/gtc/gtc_bitfield.cpp @@ -103,10 +103,12 @@ namespace mask { type const Data[] = { - {0, 0x00000000}, - {1, 0x00000001}, - {2, 0x00000003}, - {3, 0x00000007} + { 0, 0x00000000}, + { 1, 0x00000001}, + { 2, 0x00000003}, + { 3, 0x00000007}, + {31, 0x7fffffff}, + {32, 0xffffffff} }; int Error(0); @@ -142,10 +144,12 @@ namespace mask { type const Data[] = { - {glm::ivec4(0), glm::ivec4(0x00000000)}, - {glm::ivec4(1), glm::ivec4(0x00000001)}, - {glm::ivec4(2), glm::ivec4(0x00000003)}, - {glm::ivec4(3), glm::ivec4(0x00000007)} + {glm::ivec4( 0), glm::ivec4(0x00000000)}, + {glm::ivec4( 1), glm::ivec4(0x00000001)}, + {glm::ivec4( 2), glm::ivec4(0x00000003)}, + {glm::ivec4( 3), glm::ivec4(0x00000007)}, + {glm::ivec4(31), glm::ivec4(0x7fffffff)}, + {glm::ivec4(32), glm::ivec4(0xffffffff)} }; int Error(0);