diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2017-04-16 16:01:22 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2017-04-16 16:01:22 +0000 |
commit | 71d5a2540a98c81f5bcaeb48805e0e2881f530ef (patch) | |
tree | 5343938942df402b49ec7300a1c25a2d4ccd5821 /lib/Fuzzer/FuzzerValueBitMap.h | |
parent | 31bbf64f3a4974a2d6c8b3b27ad2f519caf74057 (diff) |
Diffstat (limited to 'lib/Fuzzer/FuzzerValueBitMap.h')
-rw-r--r-- | lib/Fuzzer/FuzzerValueBitMap.h | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/lib/Fuzzer/FuzzerValueBitMap.h b/lib/Fuzzer/FuzzerValueBitMap.h index 0692acd13ee3..8f7ff74300f4 100644 --- a/lib/Fuzzer/FuzzerValueBitMap.h +++ b/lib/Fuzzer/FuzzerValueBitMap.h @@ -18,19 +18,20 @@ namespace fuzzer { // A bit map containing kMapSizeInWords bits. struct ValueBitMap { - static const size_t kMapSizeInBits = 65371; // Prime. - static const size_t kMapSizeInBitsAligned = 65536; // 2^16 + static const size_t kMapSizeInBits = 1 << 16; + static const size_t kMapPrimeMod = 65371; // Largest Prime < kMapSizeInBits; static const size_t kBitsInWord = (sizeof(uintptr_t) * 8); - static const size_t kMapSizeInWords = kMapSizeInBitsAligned / kBitsInWord; + static const size_t kMapSizeInWords = kMapSizeInBits / kBitsInWord; public: - static const size_t kNumberOfItems = kMapSizeInBits; + // Clears all bits. void Reset() { memset(Map, 0, sizeof(Map)); } // Computes a hash function of Value and sets the corresponding bit. // Returns true if the bit was changed from 0 to 1. + ATTRIBUTE_NO_SANITIZE_ALL inline bool AddValue(uintptr_t Value) { - uintptr_t Idx = Value < kMapSizeInBits ? Value : Value % kMapSizeInBits; + uintptr_t Idx = Value % kMapSizeInBits; uintptr_t WordIdx = Idx / kBitsInWord; uintptr_t BitIdx = Idx % kBitsInWord; uintptr_t Old = Map[WordIdx]; @@ -39,6 +40,11 @@ struct ValueBitMap { return New != Old; } + ATTRIBUTE_NO_SANITIZE_ALL + inline bool AddValueModPrime(uintptr_t Value) { + return AddValue(Value % kMapPrimeMod); + } + inline bool Get(uintptr_t Idx) { assert(Idx < kMapSizeInBits); uintptr_t WordIdx = Idx / kBitsInWord; @@ -62,14 +68,15 @@ struct ValueBitMap { Other.Map[i] = 0; } if (M) - Res += __builtin_popcountl(M); + Res += __builtin_popcountll(M); } NumBits = Res; return OldNumBits < NumBits; } template <class Callback> - void ForEach(Callback CB) { + ATTRIBUTE_NO_SANITIZE_ALL + void ForEach(Callback CB) const { for (size_t i = 0; i < kMapSizeInWords; i++) if (uintptr_t M = Map[i]) for (size_t j = 0; j < sizeof(M) * 8; j++) |