1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mfbt/tests/TestCountPopulation.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,32 @@ 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::CountPopulation32; 1.12 + 1.13 +static void 1.14 +TestCountPopulation32() 1.15 +{ 1.16 + MOZ_RELEASE_ASSERT(CountPopulation32(0xFFFFFFFF) == 32); 1.17 + MOZ_RELEASE_ASSERT(CountPopulation32(0xF0FF1000) == 13); 1.18 + MOZ_RELEASE_ASSERT(CountPopulation32(0x7F8F0001) == 13); 1.19 + MOZ_RELEASE_ASSERT(CountPopulation32(0x3FFF0100) == 15); 1.20 + MOZ_RELEASE_ASSERT(CountPopulation32(0x1FF50010) == 12); 1.21 + MOZ_RELEASE_ASSERT(CountPopulation32(0x00800000) == 1); 1.22 + MOZ_RELEASE_ASSERT(CountPopulation32(0x00400000) == 1); 1.23 + MOZ_RELEASE_ASSERT(CountPopulation32(0x00008000) == 1); 1.24 + MOZ_RELEASE_ASSERT(CountPopulation32(0x00004000) == 1); 1.25 + MOZ_RELEASE_ASSERT(CountPopulation32(0x00000080) == 1); 1.26 + MOZ_RELEASE_ASSERT(CountPopulation32(0x00000040) == 1); 1.27 + MOZ_RELEASE_ASSERT(CountPopulation32(0x00000001) == 1); 1.28 + MOZ_RELEASE_ASSERT(CountPopulation32(0x00000000) == 0); 1.29 +} 1.30 + 1.31 +int main() 1.32 +{ 1.33 + TestCountPopulation32(); 1.34 + return 0; 1.35 +}