Better fix glm::findMSB for GCC >= 4.0

The previous fix only worked correctly for values where
the most significant enabled bit was the only enabled bit.

This change changes the implementation back to using clz,
but so that the result is changed with additional arithmetics.

There is still at least one known limitation with regards
to acceptable input types, but this is documented in the code.
This commit is contained in:
Joonas Sarajärvi 2012-09-12 15:17:21 +03:00
parent daa51e42bb
commit ad3422f6aa

View File

@ -544,10 +544,13 @@ namespace glm
)
{
/**
* ctz returns the number or trailing 0-bits; see
* 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 __builtin_ctz(Value);
return 31 - __builtin_clz(Value);
}
#else