-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathbitvec.h
64 lines (41 loc) · 1.58 KB
/
bitvec.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#pragma once
// (c) Robert Muth - see LICENSE for more info
#include <cstdint>
#include <iostream>
namespace cwerg {
constexpr const unsigned BITVEC_MAX_BITS = 64 * 255; // = 16320
struct BitVec {
// BITVEC_MAX_BITS is the maximum number of bits in a bit vector.
// Since we are using them for register liveness, this is also a limit
// on the number of registers per Fun.
static BitVec New(unsigned num_bits);
// Note: if bv has zero length Del is a nop
static void Del(BitVec bv);
unsigned raw_width() const { return index & 0xff; }
unsigned byte_width() const { return 8 * raw_width(); }
unsigned bit_width() const { return 64 * raw_width(); }
uint64_t* BackingStorage() const;
void BitSet(unsigned bit);
void BitClear(unsigned bit);
bool BitGet(unsigned bit) const;
void AndWith(BitVec other);
void AndNotWith(BitVec other);
void OrWith(BitVec other);
void OrNotWith(BitVec other);
void CopyFrom(BitVec other);
void Clear();
bool Equal(BitVec other) const;
bool Intersects(BitVec other) const;
bool operator==(const BitVec& other) const { return index == other.index; }
bool operator!=(const BitVec& other) const { return index != other.index; }
unsigned Popcnt() const;
// Encodes both the width and an offset into backing storage
// Currently see encoding is:
// top 24 bits: MemPool index
// low 8 bits: MemPool size
// We can increase the width of the size field if necessary
uint32_t index;
};
constexpr const BitVec BitVecInvalid{0};
extern std::ostream& operator<<(std::ostream& os, const BitVec& bv);
} // namespace cwerg