OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 #include "Test.h" | 8 #include "Test.h" |
9 #include "SkFloatBits.h" | 9 #include "SkFloatBits.h" |
10 #include "SkFloatingPoint.h" | 10 #include "SkFloatingPoint.h" |
11 #include "SkMathPriv.h" | 11 #include "SkMathPriv.h" |
12 #include "SkPoint.h" | 12 #include "SkPoint.h" |
13 #include "SkRandom.h" | 13 #include "SkRandom.h" |
14 #include "SkColorPriv.h" | 14 #include "SkColorPriv.h" |
15 | 15 |
16 static void test_clz(skiatest::Reporter* reporter) { | 16 static void test_clz(skiatest::Reporter* reporter) { |
17 REPORTER_ASSERT(reporter, 32 == SkCLZ(0)); | 17 REPORTER_ASSERT(reporter, 32 == SkCLZ(0)); |
18 REPORTER_ASSERT(reporter, 31 == SkCLZ(1)); | 18 REPORTER_ASSERT(reporter, 31 == SkCLZ(1)); |
19 REPORTER_ASSERT(reporter, 1 == SkCLZ(1 << 30)); | 19 REPORTER_ASSERT(reporter, 1 == SkCLZ(1 << 30)); |
20 REPORTER_ASSERT(reporter, 0 == SkCLZ(~0U)); | 20 REPORTER_ASSERT(reporter, 0 == SkCLZ(~0U)); |
21 | 21 |
22 SkRandom rand; | 22 SkMWCRandom rand; |
23 for (int i = 0; i < 1000; ++i) { | 23 for (int i = 0; i < 1000; ++i) { |
24 uint32_t mask = rand.nextU(); | 24 uint32_t mask = rand.nextU(); |
25 // need to get some zeros for testing, but in some obscure way so the | 25 // need to get some zeros for testing, but in some obscure way so the |
26 // compiler won't "see" that, and work-around calling the functions. | 26 // compiler won't "see" that, and work-around calling the functions. |
27 mask >>= (mask & 31); | 27 mask >>= (mask & 31); |
28 int intri = SkCLZ(mask); | 28 int intri = SkCLZ(mask); |
29 int porta = SkCLZ_portable(mask); | 29 int porta = SkCLZ_portable(mask); |
30 REPORTER_ASSERT(reporter, intri == porta); | 30 REPORTER_ASSERT(reporter, intri == porta); |
31 } | 31 } |
32 } | 32 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 | 75 |
76 for (int a = 0; a <= 32767; ++a) { | 76 for (int a = 0; a <= 32767; ++a) { |
77 for (int b = 0; b <= 32767; ++b) { | 77 for (int b = 0; b <= 32767; ++b) { |
78 unsigned prod0 = SkMul16ShiftRound(a, b, 8); | 78 unsigned prod0 = SkMul16ShiftRound(a, b, 8); |
79 unsigned prod1 = SkMulDiv255Round(a, b); | 79 unsigned prod1 = SkMulDiv255Round(a, b); |
80 SkASSERT(prod0 == prod1); | 80 SkASSERT(prod0 == prod1); |
81 } | 81 } |
82 } | 82 } |
83 #endif | 83 #endif |
84 | 84 |
85 SkRandom rand; | 85 SkMWCRandom rand; |
86 for (int i = 0; i < 10000; ++i) { | 86 for (int i = 0; i < 10000; ++i) { |
87 unsigned a = rand.nextU() & 0x7FFF; | 87 unsigned a = rand.nextU() & 0x7FFF; |
88 unsigned b = rand.nextU() & 0x7FFF; | 88 unsigned b = rand.nextU() & 0x7FFF; |
89 | 89 |
90 unsigned prod0 = SkMul16ShiftRound(a, b, 8); | 90 unsigned prod0 = SkMul16ShiftRound(a, b, 8); |
91 unsigned prod1 = SkMulDiv255Round(a, b); | 91 unsigned prod1 = SkMulDiv255Round(a, b); |
92 | 92 |
93 REPORTER_ASSERT(reporter, prod0 == prod1); | 93 REPORTER_ASSERT(reporter, prod0 == prod1); |
94 } | 94 } |
95 } | 95 } |
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
684 } | 684 } |
685 for (size_t i = 0; i < SK_ARRAY_COUNT(g32); ++i) { | 685 for (size_t i = 0; i < SK_ARRAY_COUNT(g32); ++i) { |
686 REPORTER_ASSERT(reporter, g32[i].fYang == SkEndianSwap32(g32[i].fYin)); | 686 REPORTER_ASSERT(reporter, g32[i].fYang == SkEndianSwap32(g32[i].fYin)); |
687 } | 687 } |
688 for (size_t i = 0; i < SK_ARRAY_COUNT(g64); ++i) { | 688 for (size_t i = 0; i < SK_ARRAY_COUNT(g64); ++i) { |
689 REPORTER_ASSERT(reporter, g64[i].fYang == SkEndianSwap64(g64[i].fYin)); | 689 REPORTER_ASSERT(reporter, g64[i].fYang == SkEndianSwap64(g64[i].fYin)); |
690 } | 690 } |
691 } | 691 } |
692 | 692 |
693 DEFINE_TESTCLASS("Endian", EndianTestClass, TestEndian) | 693 DEFINE_TESTCLASS("Endian", EndianTestClass, TestEndian) |
OLD | NEW |