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

Side by Side Diff: tests/Float16Test.cpp

Issue 2145663003: Expand _01 half<->float limitation to _finite. Simplify. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: typo 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
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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 SkOpts::half_to_float(fscratch, hs, 7); 67 SkOpts::half_to_float(fscratch, hs, 7);
68 REPORTER_ASSERT(reporter, 0 == memcmp(fscratch, fs, sizeof(fs))); 68 REPORTER_ASSERT(reporter, 0 == memcmp(fscratch, fs, sizeof(fs)));
69 } 69 }
70 70
71 static uint32_t u(float f) { 71 static uint32_t u(float f) {
72 uint32_t x; 72 uint32_t x;
73 memcpy(&x, &f, 4); 73 memcpy(&x, &f, 4);
74 return x; 74 return x;
75 } 75 }
76 76
77 DEF_TEST(HalfToFloat_01, r) { 77 DEF_TEST(HalfToFloat_finite, r) {
78 for (uint16_t h = 0; h < 0x8000; h++) { 78 for (uint32_t h = 0; h <= 0xffff; h++) {
79 float f = SkHalfToFloat(h); 79 float f = SkHalfToFloat(h);
80 if (f >= 0 && f <= 1) { 80 if (isfinite(f)) {
81 float got = SkHalfToFloat_01(h)[0]; 81 float got = SkHalfToFloat_finite(h)[0];
82 if (got != f) { 82 if (got != f) {
83 SkDebugf("0x%04x -> 0x%08x (%g), want 0x%08x (%g)\n", 83 SkDebugf("0x%04x -> 0x%08x (%g), want 0x%08x (%g)\n",
84 h, 84 h,
85 u(got), got, 85 u(got), got,
86 u(f), f); 86 u(f), f);
87 } 87 }
88 REPORTER_ASSERT(r, SkHalfToFloat_01(h)[0] == f); 88 REPORTER_ASSERT(r, SkHalfToFloat_finite(h)[0] == f);
89 REPORTER_ASSERT(r, SkFloatToHalf_01(SkHalfToFloat_01(h)) == h); 89 REPORTER_ASSERT(r, SkFloatToHalf_finite(SkHalfToFloat_finite(h)) == h);
90 } 90 }
91 } 91 }
92 } 92 }
93 93
94 DEF_TEST(FloatToHalf_01, r) { 94 DEF_TEST(FloatToHalf_finite, r) {
95 #if 0 95 #if 0
96 for (uint32_t bits = 0; bits < 0x80000000; bits++) { 96 for (uint64_t bits = 0; bits <= 0xffffffff; bits++) {
97 #else 97 #else
98 SkRandom rand; 98 SkRandom rand;
99 for (int i = 0; i < 1000000; i++) { 99 for (int i = 0; i < 1000000; i++) {
100 uint32_t bits = rand.nextU(); 100 uint32_t bits = rand.nextU();
101 #endif 101 #endif
102 float f; 102 float f;
103 memcpy(&f, &bits, 4); 103 memcpy(&f, &bits, 4);
104 if (f >= 0 && f <= 1) { 104 if (isfinite(f) && isfinite(SkHalfToFloat(SkFloatToHalf(f)))) {
105 uint16_t h1 = (uint16_t)SkFloatToHalf_01(Sk4f(f,0,0,0)), 105 uint16_t h1 = (uint16_t)SkFloatToHalf_finite(Sk4f(f,0,0,0)),
106 h2 = SkFloatToHalf(f); 106 h2 = SkFloatToHalf(f);
107 bool ok = (h1 == h2 || h1 == h2-1); 107 bool ok = (h1 == h2 || h1 == h2-1);
108 REPORTER_ASSERT(r, ok); 108 REPORTER_ASSERT(r, ok);
109 if (!ok) { 109 if (!ok) {
110 SkDebugf("%08x (%d) -> %04x (%d), want %04x (%d)\n", 110 SkDebugf("%08x (%g) -> %04x, want %04x (%g)\n",
111 bits, bits>>23, h1, h1>>10, h2, h2>>10); 111 bits, f, h1, h2, SkHalfToFloat(h2));
112 break; 112 break;
113 } 113 }
114 } 114 }
115 } 115 }
116 } 116 }
OLDNEW
« src/opts/SkNx_sse.h ('K') | « src/opts/SkNx_sse.h ('k') | tests/SkNxTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698