File tree Expand file tree Collapse file tree 3 files changed +57
-1
lines changed Expand file tree Collapse file tree 3 files changed +57
-1
lines changed Original file line number Diff line number Diff line change @@ -45,7 +45,18 @@ class Bitset {
45
45
StorageType Bits{};
46
46
47
47
protected:
48
- constexpr Bitset (const StorageType &B) : Bits{B} {}
48
+ constexpr Bitset (const std::array<uint64_t , (NumBits + 63 ) / 64> &B) {
49
+ if (sizeof (BitWord) == sizeof (uint64_t )) {
50
+ for (size_t I = 0 ; I != B.size (); ++I)
51
+ Bits[I] = B[I];
52
+ } else {
53
+ for (size_t I = 0 ; I != B.size (); ++I) {
54
+ uint64_t Elt = B[I];
55
+ Bits[2 * I] = static_cast <uint32_t >(Elt);
56
+ Bits[2 * I + 1 ] = static_cast <uint32_t >(Elt >> 32 );
57
+ }
58
+ }
59
+ }
49
60
50
61
public:
51
62
constexpr Bitset () = default;
Original file line number Diff line number Diff line change
1
+ // ===- llvm/unittest/Support/BitsetTest.cpp -------------------------------===//
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
+ // ===----------------------------------------------------------------------===//
8
+
9
+ #include " llvm/ADT/Bitset.h"
10
+ #include " gtest/gtest.h"
11
+
12
+ using namespace llvm ;
13
+
14
+ namespace {
15
+
16
+ template <unsigned NumBits>
17
+ class TestBitsetUInt64Array : public Bitset <NumBits> {
18
+ static constexpr unsigned NumElts = (NumBits + 63 ) / 64 ;
19
+
20
+ public:
21
+ TestBitsetUInt64Array (const std::array<uint64_t , NumElts> &B)
22
+ : Bitset<NumBits>(B) {}
23
+
24
+ bool verifyValue (const std::array<uint64_t , NumElts> &B) const {
25
+ for (unsigned I = 0 ; I != NumBits; ++I) {
26
+ bool ReferenceVal =
27
+ (B[(I / 64 )] & (static_cast <uint64_t >(1 ) << (I % 64 ))) != 0 ;
28
+ if (ReferenceVal != this ->test (I))
29
+ return false ;
30
+ }
31
+
32
+ return true ;
33
+ }
34
+ };
35
+
36
+ TEST (BitsetTest, Construction) {
37
+ std::array<uint64_t , 2 > TestVals = {0x123456789abcdef3 , 0x1337d3a0b22c24 };
38
+ TestBitsetUInt64Array<96 > Test (TestVals);
39
+ EXPECT_TRUE (Test.verifyValue (TestVals));
40
+
41
+ TestBitsetUInt64Array<65 > Test1 (TestVals);
42
+ EXPECT_TRUE (Test1.verifyValue (TestVals));
43
+ }
44
+ } // namespace
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ add_llvm_unittest(ADTTests
12
12
BitFieldsTest.cpp
13
13
BitmaskEnumTest.cpp
14
14
BitTest.cpp
15
+ BitsetTest.cpp
15
16
BitVectorTest.cpp
16
17
BreadthFirstIteratorTest.cpp
17
18
BumpPtrListTest.cpp
You can’t perform that action at this time.
0 commit comments