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

Side by Side Diff: tests/Float16Test.cpp

Issue 1688233002: new version of SkHalfToFloat_01 (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: swap cast order, neon on the brain Created 4 years, 10 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/core/SkHalf.h ('k') | no next file » | 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 "SkColor.h" 9 #include "SkColor.h"
10 #include "SkHalf.h" 10 #include "SkHalf.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 59
60 uint16_t hscratch[7]; 60 uint16_t hscratch[7];
61 SkOpts::float_to_half(hscratch, fs, 7); 61 SkOpts::float_to_half(hscratch, fs, 7);
62 REPORTER_ASSERT(reporter, 0 == memcmp(hscratch, hs, sizeof(hs))); 62 REPORTER_ASSERT(reporter, 0 == memcmp(hscratch, hs, sizeof(hs)));
63 63
64 float fscratch[7]; 64 float fscratch[7];
65 SkOpts::half_to_float(fscratch, hs, 7); 65 SkOpts::half_to_float(fscratch, hs, 7);
66 REPORTER_ASSERT(reporter, 0 == memcmp(fscratch, fs, sizeof(fs))); 66 REPORTER_ASSERT(reporter, 0 == memcmp(fscratch, fs, sizeof(fs)));
67 } 67 }
68 68
69 static uint32_t u(float f) {
70 uint32_t x;
71 memcpy(&x, &f, 4);
72 return x;
73 }
74
69 DEF_TEST(HalfToFloat_01, r) { 75 DEF_TEST(HalfToFloat_01, r) {
70 for (uint16_t h = 0; h < 0x8000; h++) { 76 for (uint16_t h = 0; h < 0x8000; h++) {
71 float f = SkHalfToFloat(h); 77 float f = SkHalfToFloat(h);
72 if (f >= 0 && f <= 1) { 78 if (f >= 0 && f <= 1) {
79 float got = SkHalfToFloat_01(h)[0];
80 if (got != f) {
81 SkDebugf("0x%04x -> 0x%08x (%g), want 0x%08x (%g)\n",
82 h,
83 u(got), got,
84 u(f), f);
85 }
73 REPORTER_ASSERT(r, SkHalfToFloat_01(h)[0] == f); 86 REPORTER_ASSERT(r, SkHalfToFloat_01(h)[0] == f);
74 REPORTER_ASSERT(r, SkFloatToHalf_01(SkHalfToFloat_01(h)) == h); 87 REPORTER_ASSERT(r, SkFloatToHalf_01(SkHalfToFloat_01(h)) == h);
75 } 88 }
76 } 89 }
77 } 90 }
78 91
79 DEF_TEST(FloatToHalf_01, r) { 92 DEF_TEST(FloatToHalf_01, r) {
80 #if 0 93 #if 0
81 for (uint32_t bits = 0; bits < 0x80000000; bits++) { 94 for (uint32_t bits = 0; bits < 0x80000000; bits++) {
82 #else 95 #else
83 SkRandom rand; 96 SkRandom rand;
84 for (int i = 0; i < 1000000; i++) { 97 for (int i = 0; i < 1000000; i++) {
85 uint32_t bits = rand.nextU(); 98 uint32_t bits = rand.nextU();
86 #endif 99 #endif
87 float f; 100 float f;
88 memcpy(&f, &bits, 4); 101 memcpy(&f, &bits, 4);
89 if (f >= 0 && f <= 1) { 102 if (f >= 0 && f <= 1) {
90 uint16_t h1 = (uint16_t)SkFloatToHalf_01(Sk4f(f,0,0,0)), 103 uint16_t h1 = (uint16_t)SkFloatToHalf_01(Sk4f(f,0,0,0)),
91 h2 = SkFloatToHalf(f); 104 h2 = SkFloatToHalf(f);
92 bool ok = (h1 == h2 || h1 == h2-1); 105 bool ok = (h1 == h2 || h1 == h2-1);
93 REPORTER_ASSERT(r, ok); 106 REPORTER_ASSERT(r, ok);
94 if (!ok) { 107 if (!ok) {
95 SkDebugf("%08x (%d) -> %04x (%d), want %04x (%d)\n", 108 SkDebugf("%08x (%d) -> %04x (%d), want %04x (%d)\n",
96 bits, bits>>23, h1, h1>>10, h2, h2>>10); 109 bits, bits>>23, h1, h1>>10, h2, h2>>10);
97 break; 110 break;
98 } 111 }
99 } 112 }
100 } 113 }
101 } 114 }
OLDNEW
« no previous file with comments | « src/core/SkHalf.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698