summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Fuzzer/FuzzerTracePC.cpp
diff options
context:
space:
mode:
authorKostya Serebryany <kcc@google.com>2016-12-17 02:23:35 +0000
committerKostya Serebryany <kcc@google.com>2016-12-17 02:23:35 +0000
commit01c82f50f7f2dc2f93e354374b5a6e14c71839a0 (patch)
tree09b45fe9bcb4c6d23b563fc865994c353e721d27 /llvm/lib/Fuzzer/FuzzerTracePC.cpp
parent2c36a30770e4b2183c612ed9a926062e41c2357d (diff)
downloadbcm5719-llvm-01c82f50f7f2dc2f93e354374b5a6e14c71839a0.tar.gz
bcm5719-llvm-01c82f50f7f2dc2f93e354374b5a6e14c71839a0.zip
[libFuzzer] speed up __sanitizer_cov_trace_switch a bit more (remove DIV)
llvm-svn: 290034
Diffstat (limited to 'llvm/lib/Fuzzer/FuzzerTracePC.cpp')
-rw-r--r--llvm/lib/Fuzzer/FuzzerTracePC.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/llvm/lib/Fuzzer/FuzzerTracePC.cpp b/llvm/lib/Fuzzer/FuzzerTracePC.cpp
index 74eb854ef76..3c6130e0090 100644
--- a/llvm/lib/Fuzzer/FuzzerTracePC.cpp
+++ b/llvm/lib/Fuzzer/FuzzerTracePC.cpp
@@ -299,7 +299,17 @@ void __sanitizer_cov_trace_switch(uint64_t Val, uint64_t *Cases) {
uint64_t N = Cases[0];
uint64_t *Vals = Cases + 2;
char *PC = (char*)__builtin_return_address(0);
- size_t Idx = Counter % N;
+ // We need a random number < N using Counter as a seed. But w/o DIV.
+ // * find a power of two >= N
+ // * mask Counter with this power of two.
+ // * maybe subtract N.
+ size_t Nlog = sizeof(long) * 8 - __builtin_clzl((long)N);
+ size_t PowerOfTwoGeN = 1U << Nlog;
+ assert(PowerOfTwoGeN >= N);
+ size_t Idx = Counter & (PowerOfTwoGeN - 1);
+ if (Idx >= N)
+ Idx -= N;
+ assert(Idx < N);
uint64_t TwoIn32 = 1ULL << 32;
if ((Val | Vals[Idx]) < TwoIn32)
fuzzer::TPC.HandleCmp(PC + Idx, static_cast<uint32_t>(Val),
OpenPOWER on IntegriCloud