Add SkDivMod with a special case for ARM.

BUG=skia:1663
R=djsollen@google.com, tomhudson@google.com, reed@google.com

Author: mtklein@google.com

Review URL: https://chromiumcodereview.appspot.com/24159009

git-svn-id: http://skia.googlecode.com/svn/trunk/include@11482 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/core/SkMath.h b/core/SkMath.h
index 078c8fc..affcada 100644
--- a/core/SkMath.h
+++ b/core/SkMath.h
@@ -173,4 +173,26 @@
     return (prod + (prod >> 8)) >> 8;
 }
 
+/**
+ * Stores numer/denom and numer%denom into div and mod respectively.
+ */
+template <typename In, typename Out>
+inline void SkTDivMod(In numer, In denom, Out* div, Out* mod) {
+#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 In d = numer/denom;
+    *div = static_cast<Out>(d);
+    *mod = static_cast<Out>(numer-d*denom);
+#else
+    // On x86 this will just be a single idiv.
+    *div = static_cast<Out>(numer/denom);
+    *mod = static_cast<Out>(numer%denom);
+#endif  // SK_CPU_ARM
+}
+
 #endif