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 | |
64 /////////////////////////////////////////////////////////////////////////////// | 38 /////////////////////////////////////////////////////////////////////////////// |
65 | 39 |
66 //! Returns the number of leading zero bits (0...32) | 40 //! Returns the number of leading zero bits (0...32) |
67 int SkCLZ_portable(uint32_t); | 41 int SkCLZ_portable(uint32_t); |
68 | 42 |
69 #ifndef SkCLZ | 43 #ifndef SkCLZ |
70 #if defined(_MSC_VER) && _MSC_VER >= 1400 | 44 #if defined(_MSC_VER) && _MSC_VER >= 1400 |
71 #include <intrin.h> | 45 #include <intrin.h> |
72 | 46 |
73 static inline int SkCLZ(uint32_t mask) { | 47 static inline int SkCLZ(uint32_t mask) { |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 *div = static_cast<Out>(d); | 189 *div = static_cast<Out>(d); |
216 *mod = static_cast<Out>(numer-d*denom); | 190 *mod = static_cast<Out>(numer-d*denom); |
217 #else | 191 #else |
218 // On x86 this will just be a single idiv. | 192 // On x86 this will just be a single idiv. |
219 *div = static_cast<Out>(numer/denom); | 193 *div = static_cast<Out>(numer/denom); |
220 *mod = static_cast<Out>(numer%denom); | 194 *mod = static_cast<Out>(numer%denom); |
221 #endif // SK_CPU_ARM | 195 #endif // SK_CPU_ARM |
222 } | 196 } |
223 | 197 |
224 #endif | 198 #endif |
OLD | NEW |