Chromium Code Reviews| 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 x/y and x%y into div and mod respectively. | |
| 178 */ | |
| 179 | |
| 180 template <typename T> | |
| 181 inline void SkDivMod(T x, T y, T* div, T* mod) { | |
|
reed1
2013/09/20 19:02:39
1. SkTDivMode
2. add dox
3. rename x to numer? y t
mtklein
2013/09/20 19:29:35
Done.
| |
| 182 #ifdef SK_CPU_ARM | |
| 183 // If we wrote this as in the else branch, GCC won't fuse the two into one | |
| 184 // divmod call, but rather a div call followed by a divmod. Silly! This | |
| 185 // version is just as fast as calling __aeabi_[u]idivmod manually, but with | |
| 186 // prettier code. | |
| 187 // | |
| 188 // This benches as around 2x faster than the code in the else branch. | |
| 189 const T d = x/y; | |
| 190 *div = d; | |
| 191 *mod = x-d*y; | |
| 192 #else | |
| 193 // On x86 this will just be a single idiv. | |
| 194 *div = x/y; | |
| 195 *mod = x%y; | |
| 196 #endif // SK_CPU_ARM | |
| 197 } | |
| 198 | |
| 176 #endif | 199 #endif |
| OLD | NEW |