From daa51e42bba127e54383f5f72c086e005de8aa47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joonas=20Saraj=C3=A4rvi?= Date: Wed, 12 Sep 2012 01:44:34 +0300 Subject: [PATCH] Fix glm::findMSB for GCC >= 4.0 Before this fix, the GCC specific MSB function returned the number of leading zero bits in the parameter value. With this change, the number of trailing zero bits is returned instead. I am not entirely sure if this fix is correct, because I could not find a clear reference about what findMSB in GLSL is really supposed to return with some concrete input value. At least the result is now consistent with the GLM_ARCH_PURE implementation of glm::findMSB. --- glm/core/func_integer.inl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/glm/core/func_integer.inl b/glm/core/func_integer.inl index 5de9fcbf..07a748ba 100644 --- a/glm/core/func_integer.inl +++ b/glm/core/func_integer.inl @@ -543,7 +543,11 @@ namespace glm genIUType const & Value ) { - return __builtin_clz(Value); + /** + * ctz returns the number or trailing 0-bits; see + * http://gcc.gnu.org/onlinedocs/gcc-4.7.1/gcc/Other-Builtins.html + */ + return __builtin_ctz(Value); } #else