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

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: port get_upper_left_from_offset 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
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
« no previous file with comments | « bench/MathBench.cpp ('k') | src/core/SkBitmap.cpp » ('j') | src/core/SkBitmap.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698