Move some functions to MathPriv.h
Change-Id: I22c57a746e4a997fc03f35aa06b23d9fa9ed4fa9
Reviewed-on: https://skia-review.googlesource.com/152183
Commit-Queue: Hal Canary <halcanary@google.com>
Commit-Queue: Mike Klein <mtklein@google.com>
Auto-Submit: Hal Canary <halcanary@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
diff --git a/src/codec/SkBmpStandardCodec.cpp b/src/codec/SkBmpStandardCodec.cpp
index dd71535..8e01ac0 100644
--- a/src/codec/SkBmpStandardCodec.cpp
+++ b/src/codec/SkBmpStandardCodec.cpp
@@ -8,6 +8,7 @@
#include "SkBmpStandardCodec.h"
#include "SkCodecPriv.h"
#include "SkColorData.h"
+#include "SkMathPriv.h"
#include "SkStream.h"
/*
diff --git a/src/codec/SkSampledCodec.cpp b/src/codec/SkSampledCodec.cpp
index ccede33..0ba7ef9 100644
--- a/src/codec/SkSampledCodec.cpp
+++ b/src/codec/SkSampledCodec.cpp
@@ -8,6 +8,7 @@
#include "SkCodec.h"
#include "SkCodecPriv.h"
#include "SkMath.h"
+#include "SkMathPriv.h"
#include "SkSampledCodec.h"
#include "SkSampler.h"
#include "SkTemplates.h"
diff --git a/src/core/SkBlurMask.cpp b/src/core/SkBlurMask.cpp
index b36bc0c..1ca0e5b 100644
--- a/src/core/SkBlurMask.cpp
+++ b/src/core/SkBlurMask.cpp
@@ -7,12 +7,13 @@
#include "SkBlurMask.h"
-#include "SkTo.h"
#include "SkColorPriv.h"
+#include "SkEndian.h"
#include "SkMaskBlurFilter.h"
#include "SkMath.h"
+#include "SkMathPriv.h"
#include "SkTemplates.h"
-#include "SkEndian.h"
+#include "SkTo.h"
// This constant approximates the scaling done in the software path's
// "high quality" mode, in SkBlurMask::Blur() (1 / sqrt(3)).
diff --git a/src/core/SkMathPriv.h b/src/core/SkMathPriv.h
index 24bf324..f9ff27a 100644
--- a/src/core/SkMathPriv.h
+++ b/src/core/SkMathPriv.h
@@ -10,6 +10,44 @@
#include "SkMath.h"
+/**
+ * Return the integer square root of value, with a bias of bitBias
+ */
+int32_t SkSqrtBits(int32_t value, int bitBias);
+
+/** Return the integer square root of n, treated as a SkFixed (16.16)
+ */
+static inline int32_t SkSqrt32(int32_t n) { return SkSqrtBits(n, 15); }
+
+/**
+ * Returns (value < 0 ? 0 : value) efficiently (i.e. no compares or branches)
+ */
+static inline int SkClampPos(int value) {
+ return value & ~(value >> 31);
+}
+
+/**
+ * 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_ARM32
+ // 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
+}
+
/** Returns -1 if n < 0, else returns 0
*/
#define SkExtractSign(n) ((int32_t)(n) >> 31)
diff --git a/src/effects/SkEmbossMask.cpp b/src/effects/SkEmbossMask.cpp
index c45745d..a9b8e4f 100644
--- a/src/effects/SkEmbossMask.cpp
+++ b/src/effects/SkEmbossMask.cpp
@@ -9,6 +9,7 @@
#include "SkFixed.h"
#include "SkMath.h"
+#include "SkMathPriv.h"
#include "SkTo.h"
static inline int nonzero_to_one(int x) {