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

Unified Diff: tests/Float16Test.cpp

Issue 2256023002: Flush denorm half floats to zero. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: names Created 4 years, 4 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
« src/core/SkHalf.h ('K') | « src/effects/gradients/Sk4fGradientPriv.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/Float16Test.cpp
diff --git a/tests/Float16Test.cpp b/tests/Float16Test.cpp
index 8ab56048e9fac2cfc98a046c2575e92727d308a9..31fd861ca9de509d6f1dd086998378152ef17ef0 100644
--- a/tests/Float16Test.cpp
+++ b/tests/Float16Test.cpp
@@ -61,26 +61,37 @@ static uint32_t u(float f) {
return x;
}
-DEF_TEST(HalfToFloat_finite, r) {
+static bool is_ordinary(float f) {
+ return f == 0.0f || isfinite(f);
msarett 2016/08/18 13:19:55 nit: Why not sk_float_is_finite()? nit: Change fu
+}
+
+static bool is_denorm(uint16_t h) {
+ return (h & 0x7fff) < 0x0400;
+}
+
+DEF_TEST(SkHalfToFloat_ordinary, r) {
for (uint32_t h = 0; h <= 0xffff; h++) {
+ if (is_denorm(h)) {
+ continue;
msarett 2016/08/18 13:19:55 Can we assert that this converts to zero here?
+ }
float f = SkHalfToFloat(h);
- if (isfinite(f)) {
- float got = SkHalfToFloat_finite(h)[0];
+ if (is_ordinary(f)) {
+ float got = SkHalfToFloat_ordinary(h)[0];
if (got != f) {
SkDebugf("0x%04x -> 0x%08x (%g), want 0x%08x (%g)\n",
h,
u(got), got,
u(f), f);
}
- REPORTER_ASSERT(r, SkHalfToFloat_finite(h)[0] == f);
+ REPORTER_ASSERT(r, SkHalfToFloat_ordinary(h)[0] == f);
uint64_t result;
- SkFloatToHalf_finite(SkHalfToFloat_finite(h)).store(&result);
+ SkFloatToHalf_ordinary(SkHalfToFloat_ordinary(h)).store(&result);
REPORTER_ASSERT(r, result == h);
}
}
}
-DEF_TEST(FloatToHalf_finite, r) {
+DEF_TEST(SkFloatToHalf_ordinary, r) {
#if 0
for (uint64_t bits = 0; bits <= 0xffffffff; bits++) {
#else
@@ -90,9 +101,12 @@ DEF_TEST(FloatToHalf_finite, r) {
#endif
float f;
memcpy(&f, &bits, 4);
- if (isfinite(f) && isfinite(SkHalfToFloat(SkFloatToHalf(f)))) {
- uint16_t h1 = SkFloatToHalf_finite(Sk4f(f,0,0,0))[0],
+ if (is_ordinary(f) && is_ordinary(SkHalfToFloat(SkFloatToHalf(f)))) {
msarett 2016/08/18 13:19:55 Will this case ever not be true? is_ordinary(SkHal
+ uint16_t h1 = SkFloatToHalf_ordinary(Sk4f(f,0,0,0))[0],
h2 = SkFloatToHalf(f);
+ if (is_denorm(h2)) {
+ continue;
msarett 2016/08/18 13:19:55 Can we assert that h1 is zero in this case?
+ }
bool ok = (h1 == h2 || h1 == h2-1);
msarett 2016/08/18 13:19:55 Realize this is not new... But do we allow a tole
REPORTER_ASSERT(r, ok);
if (!ok) {
« src/core/SkHalf.h ('K') | « src/effects/gradients/Sk4fGradientPriv.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698