diff options
-rw-r--r-- | src/core/SkHalf.h | 4 | ||||
-rw-r--r-- | tests/Float16Test.cpp | 19 |
2 files changed, 14 insertions, 9 deletions
diff --git a/src/core/SkHalf.h b/src/core/SkHalf.h index cc57823cb7..dd978a2347 100644 --- a/src/core/SkHalf.h +++ b/src/core/SkHalf.h @@ -26,8 +26,8 @@ float SkHalfToFloat(SkHalf h); SkHalf SkFloatToHalf(float f); // Convert between half and single precision floating point, -// assuming inputs and outputs are both finite, and -// flushing values which would be denormal half floats to zero. +// assuming inputs and outputs are both finite, and may +// flush values which would be denormal half floats to zero. static inline Sk4f SkHalfToFloat_finite_ftz(uint64_t); static inline Sk4h SkFloatToHalf_finite_ftz(const Sk4f&); diff --git a/tests/Float16Test.cpp b/tests/Float16Test.cpp index 3e057587c9..99835686fa 100644 --- a/tests/Float16Test.cpp +++ b/tests/Float16Test.cpp @@ -70,10 +70,13 @@ DEF_TEST(SkHalfToFloat_finite_ftz, r) { continue; } - // _finite_ftz() flushes denorms to zero. 0.0f will compare == with both +0.0f and -0.0f. - float expected = is_denorm(h) ? 0.0f : SkHalfToFloat(h); + // _finite_ftz() may flush denorms to zero. 0.0f will compare == with both +0.0f and -0.0f. + float expected = SkHalfToFloat(h), + alternate = is_denorm(h) ? 0.0f : expected; - REPORTER_ASSERT(r, SkHalfToFloat_finite_ftz(h)[0] == expected); + float actual = SkHalfToFloat_finite_ftz(h)[0]; + + REPORTER_ASSERT(r, actual == expected || actual == alternate); } } @@ -94,13 +97,15 @@ DEF_TEST(SkFloatToHalf_finite_ftz, r) { continue; } + uint16_t alternate = expected; if (is_denorm(expected)) { - // _finite_ftz() flushes denorms to zero, and happens to keep the sign bit. - expected = signbit(f) ? 0x8000 : 0x0000; + // _finite_ftz() may flush denorms to zero, and happens to keep the sign bit. + alternate = signbit(f) ? 0x8000 : 0x0000; } uint16_t actual = SkFloatToHalf_finite_ftz(Sk4f{f})[0]; - // _finite_ftz() truncates instead of rounding, so it may be one too small. - REPORTER_ASSERT(r, actual == expected || actual == expected - 1); + // _finite_ftz() may truncate instead of rounding, so it may be one too small. + REPORTER_ASSERT(r, actual == expected || actual == expected - 1 || + actual == alternate || actual == alternate - 1); } } |