OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #ifndef SkMath_DEFINED | 10 #ifndef SkMath_DEFINED |
(...skipping 22 matching lines...) Expand all Loading... |
33 | 33 |
34 /** Return the integer square root of n, treated as a SkFixed (16.16) | 34 /** Return the integer square root of n, treated as a SkFixed (16.16) |
35 */ | 35 */ |
36 #define SkSqrt32(n) SkSqrtBits(n, 15) | 36 #define SkSqrt32(n) SkSqrtBits(n, 15) |
37 | 37 |
38 /////////////////////////////////////////////////////////////////////////////// | 38 /////////////////////////////////////////////////////////////////////////////// |
39 | 39 |
40 //! Returns the number of leading zero bits (0...32) | 40 //! Returns the number of leading zero bits (0...32) |
41 int SkCLZ_portable(uint32_t); | 41 int SkCLZ_portable(uint32_t); |
42 | 42 |
43 #if defined(SK_CPU_ARM) | 43 #ifndef SkCLZ |
44 #define SkCLZ(x) __builtin_clz(x) | 44 #if defined(_MSC_VER) && _MSC_VER >= 1400 |
45 #endif | 45 #include <intrin.h> |
46 | 46 |
47 #ifndef SkCLZ | 47 static inline int SkCLZ(uint32_t mask) { |
48 #define SkCLZ(x) SkCLZ_portable(x) | 48 if (mask) { |
| 49 DWORD index; |
| 50 _BitScanReverse(&index, mask); |
| 51 return index ^ 0x1F; |
| 52 } else { |
| 53 return 32; |
| 54 } |
| 55 } |
| 56 #elif defined(SK_CPU_ARM) || defined(__GNUC__) |
| 57 #define SkCLZ(x) __builtin_clz(x) |
| 58 #else |
| 59 #define SkCLZ(x) SkCLZ_portable(x) |
| 60 #endif |
49 #endif | 61 #endif |
50 | 62 |
51 /** | 63 /** |
52 * Returns (value < 0 ? 0 : value) efficiently (i.e. no compares or branches) | 64 * Returns (value < 0 ? 0 : value) efficiently (i.e. no compares or branches) |
53 */ | 65 */ |
54 static inline int SkClampPos(int value) { | 66 static inline int SkClampPos(int value) { |
55 return value & ~(value >> 31); | 67 return value & ~(value >> 31); |
56 } | 68 } |
57 | 69 |
58 /** Given an integer and a positive (max) integer, return the value | 70 /** Given an integer and a positive (max) integer, return the value |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 * Only valid if a and b are unsigned and <= 32767. | 164 * Only valid if a and b are unsigned and <= 32767. |
153 */ | 165 */ |
154 static inline U8CPU SkMulDiv255Round(U16CPU a, U16CPU b) { | 166 static inline U8CPU SkMulDiv255Round(U16CPU a, U16CPU b) { |
155 SkASSERT(a <= 32767); | 167 SkASSERT(a <= 32767); |
156 SkASSERT(b <= 32767); | 168 SkASSERT(b <= 32767); |
157 unsigned prod = SkMulS16(a, b) + 128; | 169 unsigned prod = SkMulS16(a, b) + 128; |
158 return (prod + (prod >> 8)) >> 8; | 170 return (prod + (prod >> 8)) >> 8; |
159 } | 171 } |
160 | 172 |
161 #endif | 173 #endif |
OLD | NEW |