reland 8897 (was not a build-breaker) and fix MathTest (was a build-breaker)
git-svn-id: http://skia.googlecode.com/svn/trunk@8899 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/core/SkMath.h b/include/core/SkMath.h
index cee3257..2da1a3a 100644
--- a/include/core/SkMath.h
+++ b/include/core/SkMath.h
@@ -40,12 +40,24 @@
//! Returns the number of leading zero bits (0...32)
int SkCLZ_portable(uint32_t);
-#if defined(SK_CPU_ARM)
- #define SkCLZ(x) __builtin_clz(x)
-#endif
-
#ifndef SkCLZ
- #define SkCLZ(x) SkCLZ_portable(x)
+ #if defined(_MSC_VER) && _MSC_VER >= 1400
+ #include <intrin.h>
+
+ static inline int SkCLZ(uint32_t mask) {
+ if (mask) {
+ DWORD index;
+ _BitScanReverse(&index, mask);
+ return index ^ 0x1F;
+ } else {
+ return 32;
+ }
+ }
+ #elif defined(SK_CPU_ARM) || defined(__GNUC__)
+ #define SkCLZ(x) __builtin_clz(x)
+ #else
+ #define SkCLZ(x) SkCLZ_portable(x)
+ #endif
#endif
/**
diff --git a/tests/MathTest.cpp b/tests/MathTest.cpp
index 4ad83d1..ca860e4 100644
--- a/tests/MathTest.cpp
+++ b/tests/MathTest.cpp
@@ -17,7 +17,7 @@
REPORTER_ASSERT(reporter, 32 == SkCLZ(0));
REPORTER_ASSERT(reporter, 31 == SkCLZ(1));
REPORTER_ASSERT(reporter, 1 == SkCLZ(1 << 30));
- REPORTER_ASSERT(reporter, 0 == SkCLZ(~0UL));
+ REPORTER_ASSERT(reporter, 0 == SkCLZ(~0U));
SkRandom rand;
for (int i = 0; i < 1000; ++i) {