tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

TestCountZeroes.cpp (4832B)


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