|
@@ -522,6 +522,7 @@ namespace glm
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// findMSB
|
|
// findMSB
|
|
|
|
|
+/*
|
|
|
#if((GLM_ARCH != GLM_ARCH_PURE) && (GLM_COMPILER & GLM_COMPILER_VC))
|
|
#if((GLM_ARCH != GLM_ARCH_PURE) && (GLM_COMPILER & GLM_COMPILER_VC))
|
|
|
|
|
|
|
|
template <typename genIUType>
|
|
template <typename genIUType>
|
|
@@ -530,11 +531,16 @@ namespace glm
|
|
|
genIUType const & Value
|
|
genIUType const & Value
|
|
|
)
|
|
)
|
|
|
{
|
|
{
|
|
|
|
|
+ GLM_STATIC_ASSERT(std::numeric_limits<genIUType>::is_integer, "'findMSB' only accept integer values");
|
|
|
|
|
+ if(Value == 0)
|
|
|
|
|
+ return -1;
|
|
|
|
|
+
|
|
|
unsigned long Result(0);
|
|
unsigned long Result(0);
|
|
|
_BitScanReverse(&Result, Value);
|
|
_BitScanReverse(&Result, Value);
|
|
|
return int(Result);
|
|
return int(Result);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// __builtin_clz seems to be buggy as it crasks for some values, from 0x00200000 to 80000000
|
|
|
#elif((GLM_ARCH != GLM_ARCH_PURE) && (GLM_COMPILER & GLM_COMPILER_GCC) && (GLM_COMPILER >= GLM_COMPILER_GCC40))
|
|
#elif((GLM_ARCH != GLM_ARCH_PURE) && (GLM_COMPILER & GLM_COMPILER_GCC) && (GLM_COMPILER >= GLM_COMPILER_GCC40))
|
|
|
|
|
|
|
|
template <typename genIUType>
|
|
template <typename genIUType>
|
|
@@ -543,18 +549,20 @@ namespace glm
|
|
|
genIUType const & Value
|
|
genIUType const & Value
|
|
|
)
|
|
)
|
|
|
{
|
|
{
|
|
|
- /**
|
|
|
|
|
- * clz returns the number or trailing 0-bits; see
|
|
|
|
|
- * http://gcc.gnu.org/onlinedocs/gcc-4.7.1/gcc/Other-Builtins.html
|
|
|
|
|
- *
|
|
|
|
|
- * NoteBecause __builtin_clz only works for unsigned ints, this
|
|
|
|
|
- * implementation will not work for 64-bit integers.
|
|
|
|
|
- */
|
|
|
|
|
- return 31 - __builtin_clz(Value);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ GLM_STATIC_ASSERT(std::numeric_limits<genIUType>::is_integer, "'findMSB' only accept integer values");
|
|
|
|
|
+ if(Value == 0)
|
|
|
|
|
+ return -1;
|
|
|
|
|
|
|
|
|
|
+ // clz returns the number or trailing 0-bits; see
|
|
|
|
|
+ // http://gcc.gnu.org/onlinedocs/gcc-4.7.1/gcc/Other-Builtins.html
|
|
|
|
|
+ //
|
|
|
|
|
+ // NoteBecause __builtin_clz only works for unsigned ints, this
|
|
|
|
|
+ // implementation will not work for 64-bit integers.
|
|
|
|
|
+ //
|
|
|
|
|
+ return 31 - __builtin_clzl(Value);
|
|
|
|
|
+ }
|
|
|
#else
|
|
#else
|
|
|
-
|
|
|
|
|
|
|
+*/
|
|
|
template <typename genIUType>
|
|
template <typename genIUType>
|
|
|
GLM_FUNC_QUALIFIER int findMSB
|
|
GLM_FUNC_QUALIFIER int findMSB
|
|
|
(
|
|
(
|
|
@@ -562,14 +570,26 @@ namespace glm
|
|
|
)
|
|
)
|
|
|
{
|
|
{
|
|
|
GLM_STATIC_ASSERT(std::numeric_limits<genIUType>::is_integer, "'findMSB' only accept integer values");
|
|
GLM_STATIC_ASSERT(std::numeric_limits<genIUType>::is_integer, "'findMSB' only accept integer values");
|
|
|
- if(Value == 0)
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if(Value == 0 || Value == -1)
|
|
|
return -1;
|
|
return -1;
|
|
|
-
|
|
|
|
|
- genIUType bit = genIUType(-1);
|
|
|
|
|
- for(genIUType tmp = Value; tmp; tmp >>= 1, ++bit){}
|
|
|
|
|
- return bit;
|
|
|
|
|
|
|
+ else if(Value > 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ genIUType Bit = genIUType(-1);
|
|
|
|
|
+ for(genIUType tmp = Value; tmp > 0; tmp >>= 1, ++Bit){}
|
|
|
|
|
+ return Bit;
|
|
|
|
|
+ }
|
|
|
|
|
+ else //if(Value < 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ int const BitCount(sizeof(genIUType) * 8);
|
|
|
|
|
+ int MostSignificantBit(-1);
|
|
|
|
|
+ for(int BitIndex(0); BitIndex < BitCount; ++BitIndex)
|
|
|
|
|
+ MostSignificantBit = (Value & (1 << BitIndex)) ? MostSignificantBit : BitIndex;
|
|
|
|
|
+ assert(MostSignificantBit >= 0);
|
|
|
|
|
+ return MostSignificantBit;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
-#endif//(GLM_COMPILER)
|
|
|
|
|
|
|
+//#endif//(GLM_COMPILER)
|
|
|
|
|
|
|
|
template <typename T>
|
|
template <typename T>
|
|
|
GLM_FUNC_QUALIFIER detail::tvec2<int> findMSB
|
|
GLM_FUNC_QUALIFIER detail::tvec2<int> findMSB
|