diff options
author | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-04-29 14:43:50 +0000 |
---|---|---|
committer | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-04-29 14:43:50 +0000 |
commit | 7729534da419436ea6127545e9f79b0b47ccffb4 (patch) | |
tree | 60a180399c152f14c88fea948bb6c51dd193cc8a | |
parent | 44d37d9d7228e7409f4feea722c26f570434b8fd (diff) |
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
-rw-r--r-- | include/core/SkMath.h | 22 | ||||
-rw-r--r-- | tests/MathTest.cpp | 2 |
2 files changed, 18 insertions, 6 deletions
diff --git a/include/core/SkMath.h b/include/core/SkMath.h index cee3257197..2da1a3a921 100644 --- a/include/core/SkMath.h +++ b/include/core/SkMath.h @@ -40,12 +40,24 @@ int32_t SkSqrtBits(int32_t value, int bitBias); //! 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 4ad83d1829..ca860e462b 100644 --- a/tests/MathTest.cpp +++ b/tests/MathTest.cpp @@ -17,7 +17,7 @@ static void test_clz(skiatest::Reporter* reporter) { 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) { |