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