Chromium Code Reviews| Index: include/core/SkMath.h |
| diff --git a/include/core/SkMath.h b/include/core/SkMath.h |
| index 078c8fccdc2206975c07ed830222fe82f7e710af..ba3d36e85f0353df70f89e25593f1e5cd4623887 100644 |
| --- a/include/core/SkMath.h |
| +++ b/include/core/SkMath.h |
| @@ -173,4 +173,27 @@ static inline U8CPU SkMulDiv255Round(U16CPU a, U16CPU b) { |
| return (prod + (prod >> 8)) >> 8; |
| } |
| +/** |
| + * Stores x/y and x%y into div and mod respectively. |
| + */ |
| + |
| +template <typename T> |
| +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.
|
| +#ifdef SK_CPU_ARM |
| + // If we wrote this as in the else branch, GCC won't fuse the two into one |
| + // divmod call, but rather a div call followed by a divmod. Silly! This |
| + // version is just as fast as calling __aeabi_[u]idivmod manually, but with |
| + // prettier code. |
| + // |
| + // This benches as around 2x faster than the code in the else branch. |
| + const T d = x/y; |
| + *div = d; |
| + *mod = x-d*y; |
| +#else |
| + // On x86 this will just be a single idiv. |
| + *div = x/y; |
| + *mod = x%y; |
| +#endif // SK_CPU_ARM |
| +} |
| + |
| #endif |