diff --git a/glm/detail/func_integer.inl b/glm/detail/func_integer.inl index 738a2ace..a93d1a08 100644 --- a/glm/detail/func_integer.inl +++ b/glm/detail/func_integer.inl @@ -92,22 +92,19 @@ namespace detail // uaddCarry GLM_FUNC_QUALIFIER uint uaddCarry(uint const & x, uint const & y, uint & Carry) { - uint64 Value64 = static_cast(x) + static_cast(y); - uint32 Result = static_cast(Value64 % (static_cast(1) << static_cast(32))); - Carry = (Value64 % (static_cast(1) << static_cast(32))) > 1 ? static_cast(1) : static_cast(0); - return Result; + uint64 const Value64(static_cast(x) + static_cast(y)); + uint64 const Max32(static_cast(std::numeric_limits::max())); + Carry = Value64 > Max32 ? 1 : 0; + return static_cast(Value64 % Max32); } template class vecType> GLM_FUNC_QUALIFIER vecType uaddCarry(vecType const & x, vecType const & y, vecType & Carry) { vecType Value64(vecType(x) + vecType(y)); - vecType Result(Value64 % (static_cast(1) << static_cast(32))); - - vecType DoCarry(greaterThan(Value64 % (static_cast(1) << static_cast(32)), vecType(1))); - Carry = mix(vecType(0), vecType(1), DoCarry); - - return Result; + vecType Max32(static_cast(std::numeric_limits::max())); + Carry = mix(vecType(0), vecType(1), greaterThan(Value64, Max32)); + return vecType(Value64 % Max32); } // usubBorrow @@ -217,12 +214,12 @@ namespace detail GLM_FUNC_QUALIFIER vecType bitfieldReverse(vecType const & v) { vecType x(v); - x = detail::compute_bitfieldReverseStep= 2>::call(x, T(0x5555555555555555ull), static_cast( 1)); - x = detail::compute_bitfieldReverseStep= 4>::call(x, T(0x3333333333333333ull), static_cast( 2)); - x = detail::compute_bitfieldReverseStep= 8>::call(x, T(0x0F0F0F0F0F0F0F0Full), static_cast( 4)); - x = detail::compute_bitfieldReverseStep= 16>::call(x, T(0x00FF00FF00FF00FFull), static_cast( 8)); - x = detail::compute_bitfieldReverseStep= 32>::call(x, T(0x0000FFFF0000FFFFull), static_cast(16)); - x = detail::compute_bitfieldReverseStep= 64>::call(x, T(0x00000000FFFFFFFFull), static_cast(32)); + x = detail::compute_bitfieldReverseStep= 2>::call(x, T(0x5555555555555555ull), static_cast( 1)); + x = detail::compute_bitfieldReverseStep= 4>::call(x, T(0x3333333333333333ull), static_cast( 2)); + x = detail::compute_bitfieldReverseStep= 8>::call(x, T(0x0F0F0F0F0F0F0F0Full), static_cast( 4)); + x = detail::compute_bitfieldReverseStep= 16>::call(x, T(0x00FF00FF00FF00FFull), static_cast( 8)); + x = detail::compute_bitfieldReverseStep= 32>::call(x, T(0x0000FFFF0000FFFFull), static_cast(16)); + x = detail::compute_bitfieldReverseStep= 64>::call(x, T(0x00000000FFFFFFFFull), static_cast(32)); return x; } @@ -236,14 +233,13 @@ namespace detail template class vecType> GLM_FUNC_QUALIFIER vecType bitCount(vecType const & v) { - typedef glm::detail::make_unsigned::type U; - vecType x(*reinterpret_cast const *>(&v)); - x = detail::compute_bitfieldBitCountStep= 2>::call(x, U(0x5555555555555555ull), static_cast( 1)); - x = detail::compute_bitfieldBitCountStep= 4>::call(x, U(0x3333333333333333ull), static_cast( 2)); - x = detail::compute_bitfieldBitCountStep= 8>::call(x, U(0x0F0F0F0F0F0F0F0Full), static_cast( 4)); - x = detail::compute_bitfieldBitCountStep= 16>::call(x, U(0x00FF00FF00FF00FFull), static_cast( 8)); - x = detail::compute_bitfieldBitCountStep= 32>::call(x, U(0x0000FFFF0000FFFFull), static_cast(16)); - x = detail::compute_bitfieldBitCountStep= 64>::call(x, U(0x00000000FFFFFFFFull), static_cast(32)); + vecType::type, P> x(*reinterpret_cast::type, P> const *>(&v)); + x = detail::compute_bitfieldBitCountStep= 2>::call(x, typename detail::make_unsigned::type(0x5555555555555555ull), typename detail::make_unsigned::type( 1)); + x = detail::compute_bitfieldBitCountStep= 4>::call(x, typename detail::make_unsigned::type(0x3333333333333333ull), typename detail::make_unsigned::type( 2)); + x = detail::compute_bitfieldBitCountStep= 8>::call(x, typename detail::make_unsigned::type(0x0F0F0F0F0F0F0F0Full), typename detail::make_unsigned::type( 4)); + x = detail::compute_bitfieldBitCountStep= 16>::call(x, typename detail::make_unsigned::type(0x00FF00FF00FF00FFull), typename detail::make_unsigned::type( 8)); + x = detail::compute_bitfieldBitCountStep= 32>::call(x, typename detail::make_unsigned::type(0x0000FFFF0000FFFFull), typename detail::make_unsigned::type(16)); + x = detail::compute_bitfieldBitCountStep= 64>::call(x, typename detail::make_unsigned::type(0x00000000FFFFFFFFull), typename detail::make_unsigned::type(32)); return vecType(x); } diff --git a/glm/detail/type_vec4.inl b/glm/detail/type_vec4.inl index 292597d8..04135f8d 100644 --- a/glm/detail/type_vec4.inl +++ b/glm/detail/type_vec4.inl @@ -1060,7 +1060,7 @@ namespace glm } template - GLM_FUNC_QUALIFIER tvec4 operator<<(tvec4 const & left, T scalar) + GLM_FUNC_QUALIFIER tvec4 operator<<(tvec4 const & v, T scalar) { return tvec4( v.x << scalar, diff --git a/readme.txt b/readme.txt index 3c6b17ea..1690d847 100644 --- a/readme.txt +++ b/readme.txt @@ -82,6 +82,7 @@ Fixes: - Fixed Visual Studio 14 compiler warnings - Fixed implicit conversion from another tvec2 type to another tvec2 #241 - Fixed lack of consistency of quat and dualquat constructors +- Fixed uaddCarray #253 Deprecation: - Removed degrees for function parameters diff --git a/test/core/core_func_integer.cpp b/test/core/core_func_integer.cpp index c3b44080..119017b6 100644 --- a/test/core/core_func_integer.cpp +++ b/test/core/core_func_integer.cpp @@ -226,12 +226,12 @@ namespace bitfieldReverse GLM_FUNC_QUALIFIER vecType bitfieldReverseOps(vecType const & v) { vecType x(v); - x = compute_bitfieldReverseStep= 2>::call(x, T(0x5555555555555555ull), static_cast( 1)); - x = compute_bitfieldReverseStep= 4>::call(x, T(0x3333333333333333ull), static_cast( 2)); - x = compute_bitfieldReverseStep= 8>::call(x, T(0x0F0F0F0F0F0F0F0Full), static_cast( 4)); - x = compute_bitfieldReverseStep= 16>::call(x, T(0x00FF00FF00FF00FFull), static_cast( 8)); - x = compute_bitfieldReverseStep= 32>::call(x, T(0x0000FFFF0000FFFFull), static_cast(16)); - x = compute_bitfieldReverseStep= 64>::call(x, T(0x00000000FFFFFFFFull), static_cast(32)); + x = compute_bitfieldReverseStep= 2>::call(x, T(0x5555555555555555ull), static_cast( 1)); + x = compute_bitfieldReverseStep= 4>::call(x, T(0x3333333333333333ull), static_cast( 2)); + x = compute_bitfieldReverseStep= 8>::call(x, T(0x0F0F0F0F0F0F0F0Full), static_cast( 4)); + x = compute_bitfieldReverseStep= 16>::call(x, T(0x00FF00FF00FF00FFull), static_cast( 8)); + x = compute_bitfieldReverseStep= 32>::call(x, T(0x0000FFFF0000FFFFull), static_cast(16)); + x = compute_bitfieldReverseStep= 64>::call(x, T(0x00000000FFFFFFFFull), static_cast(32)); return x; } @@ -898,6 +898,14 @@ namespace findLSB namespace uaddCarry { + void test_instance(unsigned int n) + { + glm::uint a = std::numeric_limits::max() - 4, + b = n, + carry = 0; + glm::uint result = glm::uaddCarry(a, b, carry); + } + int test() { int Error(0); @@ -952,6 +960,11 @@ namespace uaddCarry Error += glm::all(glm::equal(Result, glm::uvec4(33))) ? 0 : 1; } + { + for(unsigned int i = 0; i < 10; ++i) + test_instance(i); + } + return Error; } }//namespace uaddCarry @@ -1214,14 +1227,13 @@ namespace bitCount template class vecType> GLM_FUNC_QUALIFIER vecType bitCount_bitfield(vecType const & v) { - typedef glm::detail::make_unsigned::type U; - vecType x(*reinterpret_cast const *>(&v)); - x = compute_bitfieldBitCountStep= 2>::call(x, U(0x5555555555555555ull), static_cast( 1)); - x = compute_bitfieldBitCountStep= 4>::call(x, U(0x3333333333333333ull), static_cast( 2)); - x = compute_bitfieldBitCountStep= 8>::call(x, U(0x0F0F0F0F0F0F0F0Full), static_cast( 4)); - x = compute_bitfieldBitCountStep= 16>::call(x, U(0x00FF00FF00FF00FFull), static_cast( 8)); - x = compute_bitfieldBitCountStep= 32>::call(x, U(0x0000FFFF0000FFFFull), static_cast(16)); - x = compute_bitfieldBitCountStep= 64>::call(x, U(0x00000000FFFFFFFFull), static_cast(32)); + vecType::type, P> x(*reinterpret_cast::type, P> const *>(&v)); + x = compute_bitfieldBitCountStep= 2>::call(x, typename glm::detail::make_unsigned::type(0x5555555555555555ull), typename glm::detail::make_unsigned::type( 1)); + x = compute_bitfieldBitCountStep= 4>::call(x, typename glm::detail::make_unsigned::type(0x3333333333333333ull), typename glm::detail::make_unsigned::type( 2)); + x = compute_bitfieldBitCountStep= 8>::call(x, typename glm::detail::make_unsigned::type(0x0F0F0F0F0F0F0F0Full), typename glm::detail::make_unsigned::type( 4)); + x = compute_bitfieldBitCountStep= 16>::call(x, typename glm::detail::make_unsigned::type(0x00FF00FF00FF00FFull), typename glm::detail::make_unsigned::type( 8)); + x = compute_bitfieldBitCountStep= 32>::call(x, typename glm::detail::make_unsigned::type(0x0000FFFF0000FFFFull), typename glm::detail::make_unsigned::type(16)); + x = compute_bitfieldBitCountStep= 64>::call(x, typename glm::detail::make_unsigned::type(0x00000000FFFFFFFFull), typename glm::detail::make_unsigned::type(32)); return vecType(x); }