Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Unified Diff: include/core/SkMath.h

Issue 24159009: Add SkDivMod with a special case for ARM. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: appease gcc on 10.6 Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « bench/MathBench.cpp ('k') | src/core/SkBitmap.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/core/SkMath.h
diff --git a/include/core/SkMath.h b/include/core/SkMath.h
index 078c8fccdc2206975c07ed830222fe82f7e710af..affcadaf2c76749829bdfaa9258f27d92545578d 100644
--- a/include/core/SkMath.h
+++ b/include/core/SkMath.h
@@ -173,4 +173,26 @@ static inline U8CPU SkMulDiv255Round(U16CPU a, U16CPU b) {
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
« no previous file with comments | « bench/MathBench.cpp ('k') | src/core/SkBitmap.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698