OLD | NEW |
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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 float f = SkHalfToFloat(h); | 66 float f = SkHalfToFloat(h); |
67 if (isfinite(f)) { | 67 if (isfinite(f)) { |
68 float got = SkHalfToFloat_finite(h)[0]; | 68 float got = SkHalfToFloat_finite(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_finite(h)[0] == f); |
76 REPORTER_ASSERT(r, SkFloatToHalf_finite(SkHalfToFloat_finite(h)) ==
h); | 76 uint64_t result; |
| 77 SkFloatToHalf_finite(SkHalfToFloat_finite(h)).store(&result); |
| 78 REPORTER_ASSERT(r, result == h); |
77 } | 79 } |
78 } | 80 } |
79 } | 81 } |
80 | 82 |
81 DEF_TEST(FloatToHalf_finite, r) { | 83 DEF_TEST(FloatToHalf_finite, r) { |
82 #if 0 | 84 #if 0 |
83 for (uint64_t bits = 0; bits <= 0xffffffff; bits++) { | 85 for (uint64_t bits = 0; bits <= 0xffffffff; bits++) { |
84 #else | 86 #else |
85 SkRandom rand; | 87 SkRandom rand; |
86 for (int i = 0; i < 1000000; i++) { | 88 for (int i = 0; i < 1000000; i++) { |
87 uint32_t bits = rand.nextU(); | 89 uint32_t bits = rand.nextU(); |
88 #endif | 90 #endif |
89 float f; | 91 float f; |
90 memcpy(&f, &bits, 4); | 92 memcpy(&f, &bits, 4); |
91 if (isfinite(f) && isfinite(SkHalfToFloat(SkFloatToHalf(f)))) { | 93 if (isfinite(f) && isfinite(SkHalfToFloat(SkFloatToHalf(f)))) { |
92 uint16_t h1 = (uint16_t)SkFloatToHalf_finite(Sk4f(f,0,0,0)), | 94 uint16_t h1 = SkFloatToHalf_finite(Sk4f(f,0,0,0))[0], |
93 h2 = SkFloatToHalf(f); | 95 h2 = SkFloatToHalf(f); |
94 bool ok = (h1 == h2 || h1 == h2-1); | 96 bool ok = (h1 == h2 || h1 == h2-1); |
95 REPORTER_ASSERT(r, ok); | 97 REPORTER_ASSERT(r, ok); |
96 if (!ok) { | 98 if (!ok) { |
97 SkDebugf("%08x (%g) -> %04x, want %04x (%g)\n", | 99 SkDebugf("%08x (%g) -> %04x, want %04x (%g)\n", |
98 bits, f, h1, h2, SkHalfToFloat(h2)); | 100 bits, f, h1, h2, SkHalfToFloat(h2)); |
99 break; | 101 break; |
100 } | 102 } |
101 } | 103 } |
102 } | 104 } |
103 } | 105 } |
OLD | NEW |