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
This commit is contained in:
bungeman 2015-06-24 13:08:51 -07:00 committed by Commit bot
parent 0c752f4760
commit 4760f32f2a
3 changed files with 10 additions and 6 deletions

View File

@ -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

View File

@ -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

View File

@ -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.