OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkMathPriv_DEFINED | 8 #ifndef SkMathPriv_DEFINED |
9 #define SkMathPriv_DEFINED | 9 #define SkMathPriv_DEFINED |
10 | 10 |
(...skipping 15 matching lines...) Expand all Loading... |
26 static inline int32_t SkCopySign32(int32_t x, int32_t y) { | 26 static inline int32_t SkCopySign32(int32_t x, int32_t y) { |
27 return SkApplySign(x, SkExtractSign(x ^ y)); | 27 return SkApplySign(x, SkExtractSign(x ^ y)); |
28 } | 28 } |
29 | 29 |
30 /** Given a positive value and a positive max, return the value | 30 /** Given a positive value and a positive max, return the value |
31 pinned against max. | 31 pinned against max. |
32 Note: only works as long as max - value doesn't wrap around | 32 Note: only works as long as max - value doesn't wrap around |
33 @return max if value >= max, else value | 33 @return max if value >= max, else value |
34 */ | 34 */ |
35 static inline unsigned SkClampUMax(unsigned value, unsigned max) { | 35 static inline unsigned SkClampUMax(unsigned value, unsigned max) { |
36 #ifdef SK_CPU_HAS_CONDITIONAL_INSTR | |
37 if (value > max) { | 36 if (value > max) { |
38 value = max; | 37 value = max; |
39 } | 38 } |
40 return value; | 39 return value; |
41 #else | |
42 int diff = max - value; | |
43 // clear diff if diff is positive | |
44 diff &= diff >> 31; | |
45 | |
46 return value + diff; | |
47 #endif | |
48 } | 40 } |
49 | 41 |
50 /** Computes the 64bit product of a * b, and then shifts the answer down by | 42 /** Computes the 64bit product of a * b, and then shifts the answer down by |
51 shift bits, returning the low 32bits. shift must be [0..63] | 43 shift bits, returning the low 32bits. shift must be [0..63] |
52 e.g. to perform a fixedmul, call SkMulShift(a, b, 16) | 44 e.g. to perform a fixedmul, call SkMulShift(a, b, 16) |
53 */ | 45 */ |
54 int32_t SkMulShift(int32_t a, int32_t b, unsigned shift); | 46 int32_t SkMulShift(int32_t a, int32_t b, unsigned shift); |
55 | 47 |
56 /** Return the integer cube root of value, with a bias of bitBias | 48 /** Return the integer cube root of value, with a bias of bitBias |
57 */ | 49 */ |
(...skipping 22 matching lines...) Expand all Loading... |
80 } | 72 } |
81 | 73 |
82 /** Just the rounding step in SkDiv255Round: round(value / 255) | 74 /** Just the rounding step in SkDiv255Round: round(value / 255) |
83 */ | 75 */ |
84 static inline unsigned SkDiv255Round(unsigned prod) { | 76 static inline unsigned SkDiv255Round(unsigned prod) { |
85 prod += 128; | 77 prod += 128; |
86 return (prod + (prod >> 8)) >> 8; | 78 return (prod + (prod >> 8)) >> 8; |
87 } | 79 } |
88 | 80 |
89 #endif | 81 #endif |
OLD | NEW |