mirror of
https://github.com/g-truc/glm.git
synced 2024-11-13 22:01:46 +00:00
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:
parent
daa51e42bb
commit
ad3422f6aa
@ -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
|
* 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
|
#else
|
||||||
|
Loading…
Reference in New Issue
Block a user