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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 * Return a*b/255, rounding any fractional bits. | 166 * Return a*b/255, rounding any fractional bits. |
167 * Only valid if a and b are unsigned and <= 32767. | 167 * Only valid if a and b are unsigned and <= 32767. |
168 */ | 168 */ |
169 static inline U8CPU SkMulDiv255Round(U16CPU a, U16CPU b) { | 169 static inline U8CPU SkMulDiv255Round(U16CPU a, U16CPU b) { |
170 SkASSERT(a <= 32767); | 170 SkASSERT(a <= 32767); |
171 SkASSERT(b <= 32767); | 171 SkASSERT(b <= 32767); |
172 unsigned prod = SkMulS16(a, b) + 128; | 172 unsigned prod = SkMulS16(a, b) + 128; |
173 return (prod + (prod >> 8)) >> 8; | 173 return (prod + (prod >> 8)) >> 8; |
174 } | 174 } |
175 | 175 |
| 176 /** |
| 177 * Stores numer/denom and numer%denom into div and mod respectively. |
| 178 */ |
| 179 template <typename In, typename Out> |
| 180 inline void SkTDivMod(In numer, In denom, Out* div, Out* mod) { |
| 181 #ifdef SK_CPU_ARM |
| 182 // If we wrote this as in the else branch, GCC won't fuse the two into one |
| 183 // divmod call, but rather a div call followed by a divmod. Silly! This |
| 184 // version is just as fast as calling __aeabi_[u]idivmod manually, but with |
| 185 // prettier code. |
| 186 // |
| 187 // This benches as around 2x faster than the code in the else branch. |
| 188 const In d = numer/denom; |
| 189 *div = static_cast<Out>(d); |
| 190 *mod = static_cast<Out>(numer-d*denom); |
| 191 #else |
| 192 // On x86 this will just be a single idiv. |
| 193 *div = static_cast<Out>(numer/denom); |
| 194 *mod = static_cast<Out>(numer%denom); |
| 195 #endif // SK_CPU_ARM |
| 196 } |
| 197 |
176 #endif | 198 #endif |
OLD | NEW |