From 5c341d1ff1b58cc2b88c52f4ee41faf53a2a7578 Mon Sep 17 00:00:00 2001 From: "reed@google.com" Date: Mon, 29 Apr 2013 15:34:35 +0000 Subject: [PATCH] reenable __builtin_clz for GNUC (and clang), recognizing that it is undefined for a zero argument, so we check for that explicitly. git-svn-id: http://skia.googlecode.com/svn/trunk@8905 2bbb7eff-a529-9590-31e7-b0007b416f81 --- include/core/SkMath.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/include/core/SkMath.h b/include/core/SkMath.h index 6505b08..078c8fc 100644 --- a/include/core/SkMath.h +++ b/include/core/SkMath.h @@ -53,8 +53,11 @@ int SkCLZ_portable(uint32_t); return 32; } } - #elif defined(SK_CPU_ARM) - #define SkCLZ(mask) __builtin_clz(mask) + #elif defined(SK_CPU_ARM) || defined(__GNUC__) || defined(__clang__) + static inline int SkCLZ(uint32_t mask) { + // __builtin_clz(0) is undefined, so we have to detect that case. + return mask ? __builtin_clz(mask) : 32; + } #else #define SkCLZ(x) SkCLZ_portable(x) #endif -- 2.7.4