1 //===-- Unittests for bitmask ---------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "src/__support/HashTable/bitmask.h"
10 #include "src/__support/macros/config.h"
11 #include "test/UnitTest/Test.h"
12 namespace LIBC_NAMESPACE_DECL
{
15 using ShortBitMask
= BitMaskAdaptor
<uint16_t, 1>;
16 using LargeBitMask
= BitMaskAdaptor
<uint64_t, 8>;
18 TEST(LlvmLibcHashTableBitMaskTest
, SingleBitStrideLowestSetBit
) {
19 uint16_t data
= 0xffff;
20 for (size_t i
= 0; i
< 16; ++i
) {
21 if (ShortBitMask
{data
}.any_bit_set()) {
22 ASSERT_EQ(ShortBitMask
{data
}.lowest_set_bit_nonzero(), i
);
28 TEST(LlvmLibcHashTableBitMaskTest
, MultiBitStrideLowestSetBit
) {
29 uint64_t data
= 0xffff'ffff'ffff'ffff;
30 for (size_t i
= 0; i
< 8; ++i
) {
31 for (size_t j
= 0; j
< 8; ++j
) {
32 if (LargeBitMask
{data
}.any_bit_set()) {
33 ASSERT_EQ(LargeBitMask
{data
}.lowest_set_bit_nonzero(), i
);
40 TEST(LlvmLibcHashTableBitMaskTest
, SingleBitStrideIteration
) {
41 using Iter
= IteratableBitMaskAdaptor
<ShortBitMask
>;
42 uint16_t data
= 0xffff;
43 for (size_t i
= 0; i
< 16; ++i
) {
50 ASSERT_EQ(j
, size_t{16});
55 TEST(LlvmLibcHashTableBitMaskTest
, MultiBitStrideIteration
) {
56 using Iter
= IteratableBitMaskAdaptor
<LargeBitMask
>;
57 uint64_t data
= 0x8080808080808080ul
;
58 for (size_t i
= 0; i
< 8; ++i
) {
65 ASSERT_EQ(j
, size_t{8});
66 data
<<= Iter::STRIDE
;
69 } // namespace internal
70 } // namespace LIBC_NAMESPACE_DECL