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

Side by Side Diff: tests/Float16Test.cpp

Issue 2151023003: Revert of Expand _01 half<->float limitation to _finite. Simplify. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 5 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 unified diff | Download patch
« no previous file with comments | « src/opts/SkNx_sse.h ('k') | tests/SkNxTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2016 Google Inc. 2 * Copyright 2016 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "Test.h" 8 #include "Test.h"
9 #include "SkAutoPixmapStorage.h" 9 #include "SkAutoPixmapStorage.h"
10 #include "SkColor.h" 10 #include "SkColor.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 } 54 }
55 } 55 }
56 } 56 }
57 57
58 static uint32_t u(float f) { 58 static uint32_t u(float f) {
59 uint32_t x; 59 uint32_t x;
60 memcpy(&x, &f, 4); 60 memcpy(&x, &f, 4);
61 return x; 61 return x;
62 } 62 }
63 63
64 DEF_TEST(HalfToFloat_finite, r) { 64 DEF_TEST(HalfToFloat_01, r) {
65 for (uint32_t h = 0; h <= 0xffff; h++) { 65 for (uint16_t h = 0; h < 0x8000; h++) {
66 float f = SkHalfToFloat(h); 66 float f = SkHalfToFloat(h);
67 if (isfinite(f)) { 67 if (f >= 0 && f <= 1) {
68 float got = SkHalfToFloat_finite(h)[0]; 68 float got = SkHalfToFloat_01(h)[0];
69 if (got != f) { 69 if (got != f) {
70 SkDebugf("0x%04x -> 0x%08x (%g), want 0x%08x (%g)\n", 70 SkDebugf("0x%04x -> 0x%08x (%g), want 0x%08x (%g)\n",
71 h, 71 h,
72 u(got), got, 72 u(got), got,
73 u(f), f); 73 u(f), f);
74 } 74 }
75 REPORTER_ASSERT(r, SkHalfToFloat_finite(h)[0] == f); 75 REPORTER_ASSERT(r, SkHalfToFloat_01(h)[0] == f);
76 REPORTER_ASSERT(r, SkFloatToHalf_finite(SkHalfToFloat_finite(h)) == h); 76 REPORTER_ASSERT(r, SkFloatToHalf_01(SkHalfToFloat_01(h)) == h);
77 } 77 }
78 } 78 }
79 } 79 }
80 80
81 DEF_TEST(FloatToHalf_finite, r) { 81 DEF_TEST(FloatToHalf_01, r) {
82 #if 0 82 #if 0
83 for (uint64_t bits = 0; bits <= 0xffffffff; bits++) { 83 for (uint32_t bits = 0; bits < 0x80000000; bits++) {
84 #else 84 #else
85 SkRandom rand; 85 SkRandom rand;
86 for (int i = 0; i < 1000000; i++) { 86 for (int i = 0; i < 1000000; i++) {
87 uint32_t bits = rand.nextU(); 87 uint32_t bits = rand.nextU();
88 #endif 88 #endif
89 float f; 89 float f;
90 memcpy(&f, &bits, 4); 90 memcpy(&f, &bits, 4);
91 if (isfinite(f) && isfinite(SkHalfToFloat(SkFloatToHalf(f)))) { 91 if (f >= 0 && f <= 1) {
92 uint16_t h1 = (uint16_t)SkFloatToHalf_finite(Sk4f(f,0,0,0)), 92 uint16_t h1 = (uint16_t)SkFloatToHalf_01(Sk4f(f,0,0,0)),
93 h2 = SkFloatToHalf(f); 93 h2 = SkFloatToHalf(f);
94 bool ok = (h1 == h2 || h1 == h2-1); 94 bool ok = (h1 == h2 || h1 == h2-1);
95 REPORTER_ASSERT(r, ok); 95 REPORTER_ASSERT(r, ok);
96 if (!ok) { 96 if (!ok) {
97 SkDebugf("%08x (%g) -> %04x, want %04x (%g)\n", 97 SkDebugf("%08x (%d) -> %04x (%d), want %04x (%d)\n",
98 bits, f, h1, h2, SkHalfToFloat(h2)); 98 bits, bits>>23, h1, h1>>10, h2, h2>>10);
99 break; 99 break;
100 } 100 }
101 } 101 }
102 } 102 }
103 } 103 }
OLDNEW
« no previous file with comments | « src/opts/SkNx_sse.h ('k') | tests/SkNxTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698