aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core
diff options
context:
space:
mode:
authorGravatar bungeman <bungeman@google.com>2015-06-24 13:08:51 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-06-24 13:08:52 -0700
commit4760f32f2a68acdcfee53eae98bbdabb19238e8d (patch)
tree41d44095f742edc83534cb3cb4ed82341bcb7253 /src/core
parent0c752f4760f9b501eea5fb4b5fc629d5221473f9 (diff)
Clarify iOS flush-to-zero status.
Modern processors support flush-to-zero and denormalized-are-zero for floating point operations (with ARM NEON unable to disable them). However, iOS on ARM is the only current system which defaults processes to using both all the time. However, this is only iOS on ARM, iOS on x86 (the simulator) does not. Correctly defining this allows the math tests to run error free in the simulator. Review URL: https://codereview.chromium.org/1203533003
Diffstat (limited to 'src/core')
-rw-r--r--src/core/SkFloatBits.cpp4
-rw-r--r--src/core/SkMathPriv.h10
-rw-r--r--src/core/SkPoint.cpp2
3 files changed, 10 insertions, 6 deletions
diff --git a/src/core/SkFloatBits.cpp b/src/core/SkFloatBits.cpp
index 8d89dfef22..919fd0610f 100644
--- a/src/core/SkFloatBits.cpp
+++ b/src/core/SkFloatBits.cpp
@@ -85,7 +85,7 @@ int32_t SkFloatBits_toIntFloor(int32_t packed) {
value = SkApplySign(value, SkExtractSign(packed));
exp = -exp;
if (exp > 25) { // underflow
-#ifdef SK_DISCARD_DENORMALIZED_FOR_SPEED
+#ifdef SK_CPU_FLUSH_TO_ZERO
// The iOS ARM processor discards small denormalized numbers to go faster.
// The comparision below empirically causes the result to agree with the
// tests in MathTest test_float_floor
@@ -154,7 +154,7 @@ int32_t SkFloatBits_toIntCeil(int32_t packed) {
value = SkApplySign(value, SkExtractSign(packed));
exp = -exp;
if (exp > 25) { // underflow
-#ifdef SK_DISCARD_DENORMALIZED_FOR_SPEED
+#ifdef SK_CPU_FLUSH_TO_ZERO
// The iOS ARM processor discards small denormalized numbers to go faster.
// The comparision below empirically causes the result to agree with the
// tests in MathTest test_float_ceil
diff --git a/src/core/SkMathPriv.h b/src/core/SkMathPriv.h
index e997045ea8..345815354c 100644
--- a/src/core/SkMathPriv.h
+++ b/src/core/SkMathPriv.h
@@ -10,10 +10,14 @@
#include "SkMath.h"
-#ifdef SK_BUILD_FOR_IOS
-// The iOS ARM processor discards small denormalized numbers to go faster.
+#if defined(SK_BUILD_FOR_IOS) && (defined(SK_BUILD_FOR_ARM32) || defined(SK_BUILD_FOR_ARM64))
+// iOS on ARM starts processes with the Flush-To-Zero (FTZ) and
+// Denormals-Are-Zero (DAZ) bits in the fpscr register set.
// Algorithms that rely on denormalized numbers need alternative implementations.
-#define SK_DISCARD_DENORMALIZED_FOR_SPEED
+// This can also be controlled in SSE with the MXCSR register,
+// x87 with FSTCW/FLDCW, and mips with FCSR. This should be detected at runtime,
+// or the library built one way or the other more generally (by the build).
+#define SK_CPU_FLUSH_TO_ZERO
#endif
/** Returns -1 if n < 0, else returns 0
diff --git a/src/core/SkPoint.cpp b/src/core/SkPoint.cpp
index aabde2786d..345ef37448 100644
--- a/src/core/SkPoint.cpp
+++ b/src/core/SkPoint.cpp
@@ -161,7 +161,7 @@ bool SkPoint::setLength(float x, float y, float length) {
// divide by inf. and return (0,0) vector.
double xx = x;
double yy = y;
- #ifdef SK_DISCARD_DENORMALIZED_FOR_SPEED
+ #ifdef SK_CPU_FLUSH_TO_ZERO
// The iOS ARM processor discards small denormalized numbers to go faster.
// Casting this to a float would cause the scale to go to zero. Keeping it
// as a double for the multiply keeps the scale non-zero.