1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mfbt/tests/TestCountZeroes.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,100 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.7 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "mozilla/MathAlgorithms.h" 1.10 + 1.11 +using mozilla::CountLeadingZeroes32; 1.12 +using mozilla::CountLeadingZeroes64; 1.13 +using mozilla::CountTrailingZeroes32; 1.14 +using mozilla::CountTrailingZeroes64; 1.15 + 1.16 +static void 1.17 +TestLeadingZeroes32() 1.18 +{ 1.19 + MOZ_RELEASE_ASSERT(CountLeadingZeroes32(0xF0FF1000) == 0); 1.20 + MOZ_RELEASE_ASSERT(CountLeadingZeroes32(0x7F8F0001) == 1); 1.21 + MOZ_RELEASE_ASSERT(CountLeadingZeroes32(0x3FFF0100) == 2); 1.22 + MOZ_RELEASE_ASSERT(CountLeadingZeroes32(0x1FF50010) == 3); 1.23 + MOZ_RELEASE_ASSERT(CountLeadingZeroes32(0x00800000) == 8); 1.24 + MOZ_RELEASE_ASSERT(CountLeadingZeroes32(0x00400000) == 9); 1.25 + MOZ_RELEASE_ASSERT(CountLeadingZeroes32(0x00008000) == 16); 1.26 + MOZ_RELEASE_ASSERT(CountLeadingZeroes32(0x00004000) == 17); 1.27 + MOZ_RELEASE_ASSERT(CountLeadingZeroes32(0x00000080) == 24); 1.28 + MOZ_RELEASE_ASSERT(CountLeadingZeroes32(0x00000040) == 25); 1.29 + MOZ_RELEASE_ASSERT(CountLeadingZeroes32(0x00000001) == 31); 1.30 +} 1.31 + 1.32 +static void 1.33 +TestLeadingZeroes64() 1.34 +{ 1.35 + MOZ_RELEASE_ASSERT(CountLeadingZeroes64(0xF000F0F010000000) == 0); 1.36 + MOZ_RELEASE_ASSERT(CountLeadingZeroes64(0x70F080F000000001) == 1); 1.37 + MOZ_RELEASE_ASSERT(CountLeadingZeroes64(0x30F0F0F000100000) == 2); 1.38 + MOZ_RELEASE_ASSERT(CountLeadingZeroes64(0x10F0F05000000100) == 3); 1.39 + MOZ_RELEASE_ASSERT(CountLeadingZeroes64(0x0080000000000001) == 8); 1.40 + MOZ_RELEASE_ASSERT(CountLeadingZeroes64(0x0040000010001000) == 9); 1.41 + MOZ_RELEASE_ASSERT(CountLeadingZeroes64(0x000080F010000000) == 16); 1.42 + MOZ_RELEASE_ASSERT(CountLeadingZeroes64(0x000040F010000000) == 17); 1.43 + MOZ_RELEASE_ASSERT(CountLeadingZeroes64(0x0000008000100100) == 24); 1.44 + MOZ_RELEASE_ASSERT(CountLeadingZeroes64(0x0000004100010010) == 25); 1.45 + MOZ_RELEASE_ASSERT(CountLeadingZeroes64(0x0000000080100100) == 32); 1.46 + MOZ_RELEASE_ASSERT(CountLeadingZeroes64(0x0000000041001010) == 33); 1.47 + MOZ_RELEASE_ASSERT(CountLeadingZeroes64(0x0000000000800100) == 40); 1.48 + MOZ_RELEASE_ASSERT(CountLeadingZeroes64(0x0000000000411010) == 41); 1.49 + MOZ_RELEASE_ASSERT(CountLeadingZeroes64(0x0000000000008001) == 48); 1.50 + MOZ_RELEASE_ASSERT(CountLeadingZeroes64(0x0000000000004010) == 49); 1.51 + MOZ_RELEASE_ASSERT(CountLeadingZeroes64(0x0000000000000081) == 56); 1.52 + MOZ_RELEASE_ASSERT(CountLeadingZeroes64(0x0000000000000040) == 57); 1.53 + MOZ_RELEASE_ASSERT(CountLeadingZeroes64(0x0000000000000001) == 63); 1.54 +} 1.55 + 1.56 +static void 1.57 +TestTrailingZeroes32() 1.58 +{ 1.59 + MOZ_RELEASE_ASSERT(CountTrailingZeroes32(0x0100FFFF) == 0); 1.60 + MOZ_RELEASE_ASSERT(CountTrailingZeroes32(0x7000FFFE) == 1); 1.61 + MOZ_RELEASE_ASSERT(CountTrailingZeroes32(0x0080FFFC) == 2); 1.62 + MOZ_RELEASE_ASSERT(CountTrailingZeroes32(0x0080FFF8) == 3); 1.63 + MOZ_RELEASE_ASSERT(CountTrailingZeroes32(0x010FFF00) == 8); 1.64 + MOZ_RELEASE_ASSERT(CountTrailingZeroes32(0x7000FE00) == 9); 1.65 + MOZ_RELEASE_ASSERT(CountTrailingZeroes32(0x10CF0000) == 16); 1.66 + MOZ_RELEASE_ASSERT(CountTrailingZeroes32(0x0BDE0000) == 17); 1.67 + MOZ_RELEASE_ASSERT(CountTrailingZeroes32(0x0F000000) == 24); 1.68 + MOZ_RELEASE_ASSERT(CountTrailingZeroes32(0xDE000000) == 25); 1.69 + MOZ_RELEASE_ASSERT(CountTrailingZeroes32(0x80000000) == 31); 1.70 +} 1.71 + 1.72 +static void 1.73 +TestTrailingZeroes64() 1.74 +{ 1.75 + MOZ_RELEASE_ASSERT(CountTrailingZeroes64(0x000100000F0F0F0F) == 0); 1.76 + MOZ_RELEASE_ASSERT(CountTrailingZeroes64(0x070000000F0F0F0E) == 1); 1.77 + MOZ_RELEASE_ASSERT(CountTrailingZeroes64(0x000008000F0F0F0C) == 2); 1.78 + MOZ_RELEASE_ASSERT(CountTrailingZeroes64(0x000008000F0F0F08) == 3); 1.79 + MOZ_RELEASE_ASSERT(CountTrailingZeroes64(0xC001000F0F0F0F00) == 8); 1.80 + MOZ_RELEASE_ASSERT(CountTrailingZeroes64(0x0200000F0F0F0E00) == 9); 1.81 + MOZ_RELEASE_ASSERT(CountTrailingZeroes64(0xB0C10F0FEFDF0000) == 16); 1.82 + MOZ_RELEASE_ASSERT(CountTrailingZeroes64(0x0AAA00F0FF0E0000) == 17); 1.83 + MOZ_RELEASE_ASSERT(CountTrailingZeroes64(0xD010F0FEDF000000) == 24); 1.84 + MOZ_RELEASE_ASSERT(CountTrailingZeroes64(0x7AAF0CF0BE000000) == 25); 1.85 + MOZ_RELEASE_ASSERT(CountTrailingZeroes64(0x20F0A5D100000000) == 32); 1.86 + MOZ_RELEASE_ASSERT(CountTrailingZeroes64(0x489BF0B200000000) == 33); 1.87 + MOZ_RELEASE_ASSERT(CountTrailingZeroes64(0xE0F0D10000000000) == 40); 1.88 + MOZ_RELEASE_ASSERT(CountTrailingZeroes64(0x97F0B20000000000) == 41); 1.89 + MOZ_RELEASE_ASSERT(CountTrailingZeroes64(0x2C07000000000000) == 48); 1.90 + MOZ_RELEASE_ASSERT(CountTrailingZeroes64(0x1FBA000000000000) == 49); 1.91 + MOZ_RELEASE_ASSERT(CountTrailingZeroes64(0x0100000000000000) == 56); 1.92 + MOZ_RELEASE_ASSERT(CountTrailingZeroes64(0x0200000000000000) == 57); 1.93 + MOZ_RELEASE_ASSERT(CountTrailingZeroes64(0x8000000000000000) == 63); 1.94 +} 1.95 + 1.96 +int main() 1.97 +{ 1.98 + TestLeadingZeroes32(); 1.99 + TestLeadingZeroes64(); 1.100 + TestTrailingZeroes32(); 1.101 + TestTrailingZeroes64(); 1.102 + return 0; 1.103 +}