[NFC][AArch64] Explicitly define undefined bits for instructions (#122129)
[llvm-project.git] / libc / test / src / __support / HashTable / bitmask_test.cpp
blobce56b2079d32eb978c088a290b5538771c471a7b
1 //===-- Unittests for bitmask ---------------------------------------------===//
2 //
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
6 //
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 {
13 namespace internal {
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);
23 data <<= 1;
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);
34 data <<= 1;
40 TEST(LlvmLibcHashTableBitMaskTest, SingleBitStrideIteration) {
41 using Iter = IteratableBitMaskAdaptor<ShortBitMask>;
42 uint16_t data = 0xffff;
43 for (size_t i = 0; i < 16; ++i) {
44 Iter iter = {data};
45 size_t j = i;
46 for (auto x : iter) {
47 ASSERT_EQ(x, j);
48 j++;
50 ASSERT_EQ(j, size_t{16});
51 data <<= 1;
55 TEST(LlvmLibcHashTableBitMaskTest, MultiBitStrideIteration) {
56 using Iter = IteratableBitMaskAdaptor<LargeBitMask>;
57 uint64_t data = 0x8080808080808080ul;
58 for (size_t i = 0; i < 8; ++i) {
59 Iter iter = {data};
60 size_t j = i;
61 for (auto x : iter) {
62 ASSERT_EQ(x, j);
63 j++;
65 ASSERT_EQ(j, size_t{8});
66 data <<= Iter::STRIDE;
69 } // namespace internal
70 } // namespace LIBC_NAMESPACE_DECL