summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Fuzzer/FuzzerValueBitMap.h
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Fuzzer/FuzzerValueBitMap.h')
-rw-r--r--llvm/lib/Fuzzer/FuzzerValueBitMap.h15
1 files changed, 10 insertions, 5 deletions
diff --git a/llvm/lib/Fuzzer/FuzzerValueBitMap.h b/llvm/lib/Fuzzer/FuzzerValueBitMap.h
index 22e06641fa1..68dc3a9fc3a 100644
--- a/llvm/lib/Fuzzer/FuzzerValueBitMap.h
+++ b/llvm/lib/Fuzzer/FuzzerValueBitMap.h
@@ -18,12 +18,12 @@ namespace fuzzer {
// A bit map containing kMapSizeInWords bits.
struct ValueBitMap {
- static const size_t kMapSizeInBits = 65371; // Prime.
- static const size_t kMapSizeInBitsAligned = 1 << 16; // 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)); }
@@ -31,7 +31,7 @@ struct ValueBitMap {
// 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];
@@ -40,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;
OpenPOWER on IntegriCloud