| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   63     return (h & 0x7c00) != 0x7c00; |   63     return (h & 0x7c00) != 0x7c00; | 
|   64 } |   64 } | 
|   65  |   65  | 
|   66 DEF_TEST(SkHalfToFloat_finite_ftz, r) { |   66 DEF_TEST(SkHalfToFloat_finite_ftz, r) { | 
|   67     for (uint32_t h = 0; h <= 0xffff; h++) { |   67     for (uint32_t h = 0; h <= 0xffff; h++) { | 
|   68         if (!is_finite(h)) { |   68         if (!is_finite(h)) { | 
|   69             // _finite_ftz() only works for values that can be represented as a 
     finite half float. |   69             // _finite_ftz() only works for values that can be represented as a 
     finite half float. | 
|   70             continue; |   70             continue; | 
|   71         } |   71         } | 
|   72  |   72  | 
|   73         // _finite_ftz() flushes denorms to zero.  0.0f will compare == with bot
     h +0.0f and -0.0f. |   73         // _finite_ftz() may flush denorms to zero.  0.0f will compare == with b
     oth +0.0f and -0.0f. | 
|   74         float expected = is_denorm(h) ? 0.0f : SkHalfToFloat(h); |   74         float expected  = SkHalfToFloat(h), | 
 |   75               alternate = is_denorm(h) ? 0.0f : expected; | 
|   75  |   76  | 
|   76         REPORTER_ASSERT(r, SkHalfToFloat_finite_ftz(h)[0] == expected); |   77         float actual = SkHalfToFloat_finite_ftz(h)[0]; | 
 |   78  | 
 |   79         REPORTER_ASSERT(r, actual == expected || actual == alternate); | 
|   77     } |   80     } | 
|   78 } |   81 } | 
|   79  |   82  | 
|   80 DEF_TEST(SkFloatToHalf_finite_ftz, r) { |   83 DEF_TEST(SkFloatToHalf_finite_ftz, r) { | 
|   81 #if 0 |   84 #if 0 | 
|   82     for (uint64_t bits = 0; bits <= 0xffffffff; bits++) { |   85     for (uint64_t bits = 0; bits <= 0xffffffff; bits++) { | 
|   83 #else |   86 #else | 
|   84     SkRandom rand; |   87     SkRandom rand; | 
|   85     for (int i = 0; i < 1000000; i++) { |   88     for (int i = 0; i < 1000000; i++) { | 
|   86         uint32_t bits = rand.nextU(); |   89         uint32_t bits = rand.nextU(); | 
|   87 #endif |   90 #endif | 
|   88         float f; |   91         float f; | 
|   89         memcpy(&f, &bits, 4); |   92         memcpy(&f, &bits, 4); | 
|   90  |   93  | 
|   91         uint16_t expected = SkFloatToHalf(f); |   94         uint16_t expected = SkFloatToHalf(f); | 
|   92         if (!is_finite(expected)) { |   95         if (!is_finite(expected)) { | 
|   93             // _finite_ftz() only works for values that can be represented as a 
     finite half float. |   96             // _finite_ftz() only works for values that can be represented as a 
     finite half float. | 
|   94             continue; |   97             continue; | 
|   95         } |   98         } | 
|   96  |   99  | 
 |  100         uint16_t alternate = expected; | 
|   97         if (is_denorm(expected)) { |  101         if (is_denorm(expected)) { | 
|   98             // _finite_ftz() flushes denorms to zero, and happens to keep the si
     gn bit. |  102             // _finite_ftz() may flush denorms to zero, and happens to keep the 
     sign bit. | 
|   99             expected = signbit(f) ? 0x8000 : 0x0000; |  103             alternate = signbit(f) ? 0x8000 : 0x0000; | 
|  100         } |  104         } | 
|  101  |  105  | 
|  102         uint16_t actual = SkFloatToHalf_finite_ftz(Sk4f{f})[0]; |  106         uint16_t actual = SkFloatToHalf_finite_ftz(Sk4f{f})[0]; | 
|  103         // _finite_ftz() truncates instead of rounding, so it may be one too sma
     ll. |  107         // _finite_ftz() may truncate instead of rounding, so it may be one too 
     small. | 
|  104         REPORTER_ASSERT(r, actual == expected || actual == expected - 1); |  108         REPORTER_ASSERT(r, actual == expected  || actual == expected  - 1 || | 
 |  109                            actual == alternate || actual == alternate - 1); | 
|  105     } |  110     } | 
|  106 } |  111 } | 
| OLD | NEW |