|
|
|
@ -92,22 +92,19 @@ namespace detail |
|
|
|
|
// uaddCarry |
|
|
|
|
GLM_FUNC_QUALIFIER uint uaddCarry(uint const & x, uint const & y, uint & Carry) |
|
|
|
|
{ |
|
|
|
|
uint64 Value64 = static_cast<uint64>(x) + static_cast<uint64>(y); |
|
|
|
|
uint32 Result = static_cast<uint32>(Value64 % (static_cast<uint64>(1) << static_cast<uint64>(32))); |
|
|
|
|
Carry = (Value64 % (static_cast<uint64>(1) << static_cast<uint64>(32))) > 1 ? static_cast<uint32>(1) : static_cast<uint32>(0); |
|
|
|
|
return Result; |
|
|
|
|
uint64 const Value64(static_cast<uint64>(x) + static_cast<uint64>(y)); |
|
|
|
|
uint64 const Max32(static_cast<uint64>(std::numeric_limits<uint>::max())); |
|
|
|
|
Carry = Value64 > Max32 ? 1 : 0; |
|
|
|
|
return static_cast<uint32>(Value64 % Max32); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
template <precision P, template <typename, precision> class vecType> |
|
|
|
|
GLM_FUNC_QUALIFIER vecType<uint, P> uaddCarry(vecType<uint, P> const & x, vecType<uint, P> const & y, vecType<uint, P> & Carry) |
|
|
|
|
{ |
|
|
|
|
vecType<uint64, P> Value64(vecType<uint64, P>(x) + vecType<uint64, P>(y)); |
|
|
|
|
vecType<uint32, P> Result(Value64 % (static_cast<uint64>(1) << static_cast<uint64>(32))); |
|
|
|
|
|
|
|
|
|
vecType<bool, P> DoCarry(greaterThan(Value64 % (static_cast<uint64>(1) << static_cast<uint64>(32)), vecType<uint64, P>(1))); |
|
|
|
|
Carry = mix(vecType<uint32, P>(0), vecType<uint32, P>(1), DoCarry); |
|
|
|
|
|
|
|
|
|
return Result; |
|
|
|
|
vecType<uint64, P> Max32(static_cast<uint64>(std::numeric_limits<uint>::max())); |
|
|
|
|
Carry = mix(vecType<uint32, P>(0), vecType<uint32, P>(1), greaterThan(Value64, Max32)); |
|
|
|
|
return vecType<uint32,P>(Value64 % Max32); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// usubBorrow |
|
|
|
@ -217,12 +214,12 @@ namespace detail |
|
|
|
|
GLM_FUNC_QUALIFIER vecType<T, P> bitfieldReverse(vecType<T, P> const & v) |
|
|
|
|
{ |
|
|
|
|
vecType<T, P> x(v); |
|
|
|
|
x = detail::compute_bitfieldReverseStep<sizeof(T) * 8 >= 2>::call<T, P, vecType>(x, T(0x5555555555555555ull), static_cast<T>( 1)); |
|
|
|
|
x = detail::compute_bitfieldReverseStep<sizeof(T) * 8 >= 4>::call<T, P, vecType>(x, T(0x3333333333333333ull), static_cast<T>( 2)); |
|
|
|
|
x = detail::compute_bitfieldReverseStep<sizeof(T) * 8 >= 8>::call<T, P, vecType>(x, T(0x0F0F0F0F0F0F0F0Full), static_cast<T>( 4)); |
|
|
|
|
x = detail::compute_bitfieldReverseStep<sizeof(T) * 8 >= 16>::call<T, P, vecType>(x, T(0x00FF00FF00FF00FFull), static_cast<T>( 8)); |
|
|
|
|
x = detail::compute_bitfieldReverseStep<sizeof(T) * 8 >= 32>::call<T, P, vecType>(x, T(0x0000FFFF0000FFFFull), static_cast<T>(16)); |
|
|
|
|
x = detail::compute_bitfieldReverseStep<sizeof(T) * 8 >= 64>::call<T, P, vecType>(x, T(0x00000000FFFFFFFFull), static_cast<T>(32)); |
|
|
|
|
x = detail::compute_bitfieldReverseStep<sizeof(T) * 8 >= 2>::call(x, T(0x5555555555555555ull), static_cast<T>( 1)); |
|
|
|
|
x = detail::compute_bitfieldReverseStep<sizeof(T) * 8 >= 4>::call(x, T(0x3333333333333333ull), static_cast<T>( 2)); |
|
|
|
|
x = detail::compute_bitfieldReverseStep<sizeof(T) * 8 >= 8>::call(x, T(0x0F0F0F0F0F0F0F0Full), static_cast<T>( 4)); |
|
|
|
|
x = detail::compute_bitfieldReverseStep<sizeof(T) * 8 >= 16>::call(x, T(0x00FF00FF00FF00FFull), static_cast<T>( 8)); |
|
|
|
|
x = detail::compute_bitfieldReverseStep<sizeof(T) * 8 >= 32>::call(x, T(0x0000FFFF0000FFFFull), static_cast<T>(16)); |
|
|
|
|
x = detail::compute_bitfieldReverseStep<sizeof(T) * 8 >= 64>::call(x, T(0x00000000FFFFFFFFull), static_cast<T>(32)); |
|
|
|
|
return x; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -236,14 +233,13 @@ namespace detail |
|
|
|
|
template <typename T, glm::precision P, template <typename, glm::precision> class vecType> |
|
|
|
|
GLM_FUNC_QUALIFIER vecType<int, P> bitCount(vecType<T, P> const & v) |
|
|
|
|
{ |
|
|
|
|
typedef glm::detail::make_unsigned<T>::type U; |
|
|
|
|
vecType<U, P> x(*reinterpret_cast<vecType<U, P> const *>(&v)); |
|
|
|
|
x = detail::compute_bitfieldBitCountStep<sizeof(T) * 8 >= 2>::call<U, P, vecType>(x, U(0x5555555555555555ull), static_cast<U>( 1)); |
|
|
|
|
x = detail::compute_bitfieldBitCountStep<sizeof(T) * 8 >= 4>::call<U, P, vecType>(x, U(0x3333333333333333ull), static_cast<U>( 2)); |
|
|
|
|
x = detail::compute_bitfieldBitCountStep<sizeof(T) * 8 >= 8>::call<U, P, vecType>(x, U(0x0F0F0F0F0F0F0F0Full), static_cast<U>( 4)); |
|
|
|
|
x = detail::compute_bitfieldBitCountStep<sizeof(T) * 8 >= 16>::call<U, P, vecType>(x, U(0x00FF00FF00FF00FFull), static_cast<U>( 8)); |
|
|
|
|
x = detail::compute_bitfieldBitCountStep<sizeof(T) * 8 >= 32>::call<U, P, vecType>(x, U(0x0000FFFF0000FFFFull), static_cast<U>(16)); |
|
|
|
|
x = detail::compute_bitfieldBitCountStep<sizeof(T) * 8 >= 64>::call<U, P, vecType>(x, U(0x00000000FFFFFFFFull), static_cast<U>(32)); |
|
|
|
|
vecType<typename detail::make_unsigned<T>::type, P> x(*reinterpret_cast<vecType<typename detail::make_unsigned<T>::type, P> const *>(&v)); |
|
|
|
|
x = detail::compute_bitfieldBitCountStep<sizeof(T) * 8 >= 2>::call(x, typename detail::make_unsigned<T>::type(0x5555555555555555ull), typename detail::make_unsigned<T>::type( 1)); |
|
|
|
|
x = detail::compute_bitfieldBitCountStep<sizeof(T) * 8 >= 4>::call(x, typename detail::make_unsigned<T>::type(0x3333333333333333ull), typename detail::make_unsigned<T>::type( 2)); |
|
|
|
|
x = detail::compute_bitfieldBitCountStep<sizeof(T) * 8 >= 8>::call(x, typename detail::make_unsigned<T>::type(0x0F0F0F0F0F0F0F0Full), typename detail::make_unsigned<T>::type( 4)); |
|
|
|
|
x = detail::compute_bitfieldBitCountStep<sizeof(T) * 8 >= 16>::call(x, typename detail::make_unsigned<T>::type(0x00FF00FF00FF00FFull), typename detail::make_unsigned<T>::type( 8)); |
|
|
|
|
x = detail::compute_bitfieldBitCountStep<sizeof(T) * 8 >= 32>::call(x, typename detail::make_unsigned<T>::type(0x0000FFFF0000FFFFull), typename detail::make_unsigned<T>::type(16)); |
|
|
|
|
x = detail::compute_bitfieldBitCountStep<sizeof(T) * 8 >= 64>::call(x, typename detail::make_unsigned<T>::type(0x00000000FFFFFFFFull), typename detail::make_unsigned<T>::type(32)); |
|
|
|
|
return vecType<int, P>(x); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|