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 17 matching lines...) Expand all Loading... |
28 | 28 |
29 /** | 29 /** |
30 * Return the integer square root of value, with a bias of bitBias | 30 * Return the integer square root of value, with a bias of bitBias |
31 */ | 31 */ |
32 int32_t SkSqrtBits(int32_t value, int bitBias); | 32 int32_t SkSqrtBits(int32_t value, int bitBias); |
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 // 64bit -> 32bit utilities |
| 39 |
| 40 /** |
| 41 * Return true iff the 64bit value can exactly be represented in signed 32bits |
| 42 */ |
| 43 static inline bool sk_64_isS32(int64_t value) { |
| 44 return (int32_t)value == value; |
| 45 } |
| 46 |
| 47 /** |
| 48 * Return the 64bit argument as signed 32bits, asserting in debug that the arg |
| 49 * exactly fits in signed 32bits. In the release build, no checks are preformed |
| 50 * and the return value if the arg does not fit is undefined. |
| 51 */ |
| 52 static inline int32_t sk_64_asS32(int64_t value) { |
| 53 SkASSERT(sk_64_isS32(value)); |
| 54 return (int32_t)value; |
| 55 } |
| 56 |
| 57 // Handy util that can be passed two ints, and will automatically promote to |
| 58 // 64bits before the multiply, so the caller doesn't have to remember to cast |
| 59 // e.g. (int64_t)a * b; |
| 60 static inline int64_t sk_64_mul(int64_t a, int64_t b) { |
| 61 return a * b; |
| 62 } |
| 63 |
38 /////////////////////////////////////////////////////////////////////////////// | 64 /////////////////////////////////////////////////////////////////////////////// |
39 | 65 |
40 //! Returns the number of leading zero bits (0...32) | 66 //! Returns the number of leading zero bits (0...32) |
41 int SkCLZ_portable(uint32_t); | 67 int SkCLZ_portable(uint32_t); |
42 | 68 |
43 #ifndef SkCLZ | 69 #ifndef SkCLZ |
44 #if defined(_MSC_VER) && _MSC_VER >= 1400 | 70 #if defined(_MSC_VER) && _MSC_VER >= 1400 |
45 #include <intrin.h> | 71 #include <intrin.h> |
46 | 72 |
47 static inline int SkCLZ(uint32_t mask) { | 73 static inline int SkCLZ(uint32_t mask) { |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 *div = static_cast<Out>(d); | 215 *div = static_cast<Out>(d); |
190 *mod = static_cast<Out>(numer-d*denom); | 216 *mod = static_cast<Out>(numer-d*denom); |
191 #else | 217 #else |
192 // On x86 this will just be a single idiv. | 218 // On x86 this will just be a single idiv. |
193 *div = static_cast<Out>(numer/denom); | 219 *div = static_cast<Out>(numer/denom); |
194 *mod = static_cast<Out>(numer%denom); | 220 *mod = static_cast<Out>(numer%denom); |
195 #endif // SK_CPU_ARM | 221 #endif // SK_CPU_ARM |
196 } | 222 } |
197 | 223 |
198 #endif | 224 #endif |
OLD | NEW |