|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
|
4 * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 #include "mozilla/MathAlgorithms.h" |
|
7 |
|
8 using mozilla::CountLeadingZeroes32; |
|
9 using mozilla::CountLeadingZeroes64; |
|
10 using mozilla::CountTrailingZeroes32; |
|
11 using mozilla::CountTrailingZeroes64; |
|
12 |
|
13 static void |
|
14 TestLeadingZeroes32() |
|
15 { |
|
16 MOZ_RELEASE_ASSERT(CountLeadingZeroes32(0xF0FF1000) == 0); |
|
17 MOZ_RELEASE_ASSERT(CountLeadingZeroes32(0x7F8F0001) == 1); |
|
18 MOZ_RELEASE_ASSERT(CountLeadingZeroes32(0x3FFF0100) == 2); |
|
19 MOZ_RELEASE_ASSERT(CountLeadingZeroes32(0x1FF50010) == 3); |
|
20 MOZ_RELEASE_ASSERT(CountLeadingZeroes32(0x00800000) == 8); |
|
21 MOZ_RELEASE_ASSERT(CountLeadingZeroes32(0x00400000) == 9); |
|
22 MOZ_RELEASE_ASSERT(CountLeadingZeroes32(0x00008000) == 16); |
|
23 MOZ_RELEASE_ASSERT(CountLeadingZeroes32(0x00004000) == 17); |
|
24 MOZ_RELEASE_ASSERT(CountLeadingZeroes32(0x00000080) == 24); |
|
25 MOZ_RELEASE_ASSERT(CountLeadingZeroes32(0x00000040) == 25); |
|
26 MOZ_RELEASE_ASSERT(CountLeadingZeroes32(0x00000001) == 31); |
|
27 } |
|
28 |
|
29 static void |
|
30 TestLeadingZeroes64() |
|
31 { |
|
32 MOZ_RELEASE_ASSERT(CountLeadingZeroes64(0xF000F0F010000000) == 0); |
|
33 MOZ_RELEASE_ASSERT(CountLeadingZeroes64(0x70F080F000000001) == 1); |
|
34 MOZ_RELEASE_ASSERT(CountLeadingZeroes64(0x30F0F0F000100000) == 2); |
|
35 MOZ_RELEASE_ASSERT(CountLeadingZeroes64(0x10F0F05000000100) == 3); |
|
36 MOZ_RELEASE_ASSERT(CountLeadingZeroes64(0x0080000000000001) == 8); |
|
37 MOZ_RELEASE_ASSERT(CountLeadingZeroes64(0x0040000010001000) == 9); |
|
38 MOZ_RELEASE_ASSERT(CountLeadingZeroes64(0x000080F010000000) == 16); |
|
39 MOZ_RELEASE_ASSERT(CountLeadingZeroes64(0x000040F010000000) == 17); |
|
40 MOZ_RELEASE_ASSERT(CountLeadingZeroes64(0x0000008000100100) == 24); |
|
41 MOZ_RELEASE_ASSERT(CountLeadingZeroes64(0x0000004100010010) == 25); |
|
42 MOZ_RELEASE_ASSERT(CountLeadingZeroes64(0x0000000080100100) == 32); |
|
43 MOZ_RELEASE_ASSERT(CountLeadingZeroes64(0x0000000041001010) == 33); |
|
44 MOZ_RELEASE_ASSERT(CountLeadingZeroes64(0x0000000000800100) == 40); |
|
45 MOZ_RELEASE_ASSERT(CountLeadingZeroes64(0x0000000000411010) == 41); |
|
46 MOZ_RELEASE_ASSERT(CountLeadingZeroes64(0x0000000000008001) == 48); |
|
47 MOZ_RELEASE_ASSERT(CountLeadingZeroes64(0x0000000000004010) == 49); |
|
48 MOZ_RELEASE_ASSERT(CountLeadingZeroes64(0x0000000000000081) == 56); |
|
49 MOZ_RELEASE_ASSERT(CountLeadingZeroes64(0x0000000000000040) == 57); |
|
50 MOZ_RELEASE_ASSERT(CountLeadingZeroes64(0x0000000000000001) == 63); |
|
51 } |
|
52 |
|
53 static void |
|
54 TestTrailingZeroes32() |
|
55 { |
|
56 MOZ_RELEASE_ASSERT(CountTrailingZeroes32(0x0100FFFF) == 0); |
|
57 MOZ_RELEASE_ASSERT(CountTrailingZeroes32(0x7000FFFE) == 1); |
|
58 MOZ_RELEASE_ASSERT(CountTrailingZeroes32(0x0080FFFC) == 2); |
|
59 MOZ_RELEASE_ASSERT(CountTrailingZeroes32(0x0080FFF8) == 3); |
|
60 MOZ_RELEASE_ASSERT(CountTrailingZeroes32(0x010FFF00) == 8); |
|
61 MOZ_RELEASE_ASSERT(CountTrailingZeroes32(0x7000FE00) == 9); |
|
62 MOZ_RELEASE_ASSERT(CountTrailingZeroes32(0x10CF0000) == 16); |
|
63 MOZ_RELEASE_ASSERT(CountTrailingZeroes32(0x0BDE0000) == 17); |
|
64 MOZ_RELEASE_ASSERT(CountTrailingZeroes32(0x0F000000) == 24); |
|
65 MOZ_RELEASE_ASSERT(CountTrailingZeroes32(0xDE000000) == 25); |
|
66 MOZ_RELEASE_ASSERT(CountTrailingZeroes32(0x80000000) == 31); |
|
67 } |
|
68 |
|
69 static void |
|
70 TestTrailingZeroes64() |
|
71 { |
|
72 MOZ_RELEASE_ASSERT(CountTrailingZeroes64(0x000100000F0F0F0F) == 0); |
|
73 MOZ_RELEASE_ASSERT(CountTrailingZeroes64(0x070000000F0F0F0E) == 1); |
|
74 MOZ_RELEASE_ASSERT(CountTrailingZeroes64(0x000008000F0F0F0C) == 2); |
|
75 MOZ_RELEASE_ASSERT(CountTrailingZeroes64(0x000008000F0F0F08) == 3); |
|
76 MOZ_RELEASE_ASSERT(CountTrailingZeroes64(0xC001000F0F0F0F00) == 8); |
|
77 MOZ_RELEASE_ASSERT(CountTrailingZeroes64(0x0200000F0F0F0E00) == 9); |
|
78 MOZ_RELEASE_ASSERT(CountTrailingZeroes64(0xB0C10F0FEFDF0000) == 16); |
|
79 MOZ_RELEASE_ASSERT(CountTrailingZeroes64(0x0AAA00F0FF0E0000) == 17); |
|
80 MOZ_RELEASE_ASSERT(CountTrailingZeroes64(0xD010F0FEDF000000) == 24); |
|
81 MOZ_RELEASE_ASSERT(CountTrailingZeroes64(0x7AAF0CF0BE000000) == 25); |
|
82 MOZ_RELEASE_ASSERT(CountTrailingZeroes64(0x20F0A5D100000000) == 32); |
|
83 MOZ_RELEASE_ASSERT(CountTrailingZeroes64(0x489BF0B200000000) == 33); |
|
84 MOZ_RELEASE_ASSERT(CountTrailingZeroes64(0xE0F0D10000000000) == 40); |
|
85 MOZ_RELEASE_ASSERT(CountTrailingZeroes64(0x97F0B20000000000) == 41); |
|
86 MOZ_RELEASE_ASSERT(CountTrailingZeroes64(0x2C07000000000000) == 48); |
|
87 MOZ_RELEASE_ASSERT(CountTrailingZeroes64(0x1FBA000000000000) == 49); |
|
88 MOZ_RELEASE_ASSERT(CountTrailingZeroes64(0x0100000000000000) == 56); |
|
89 MOZ_RELEASE_ASSERT(CountTrailingZeroes64(0x0200000000000000) == 57); |
|
90 MOZ_RELEASE_ASSERT(CountTrailingZeroes64(0x8000000000000000) == 63); |
|
91 } |
|
92 |
|
93 int main() |
|
94 { |
|
95 TestLeadingZeroes32(); |
|
96 TestLeadingZeroes64(); |
|
97 TestTrailingZeroes32(); |
|
98 TestTrailingZeroes64(); |
|
99 return 0; |
|
100 } |