Skip to content

Commit

Permalink
[libFuzzer] force proper popcnt instruction
Browse files Browse the repository at this point in the history
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279002 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
kcc committed Aug 17, 2016
1 parent 03c1f4b commit ac9c0f4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/Fuzzer/FuzzerTraceState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,7 @@ static void AddValueForStrcmp(void *caller_pc, const char *s1, const char *s2,
VP.AddValue((PC & 4095) | (LastSameByte << 12));
}

__attribute__((target("popcnt")))
static void AddValueForCmp(uintptr_t PC, uint64_t Arg1, uint64_t Arg2) {
VP.AddValue((PC & 4095) | (__builtin_popcountl(Arg1 ^ Arg2) << 12));
}
Expand Down
3 changes: 2 additions & 1 deletion lib/Fuzzer/FuzzerValueBitMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct ValueBitMap {
void Reset() { memset(Map, 0, sizeof(Map)); }

// Computed a hash function of Value and sets the corresponding bit.
void AddValue(uintptr_t Value) {
inline void AddValue(uintptr_t Value) {
uintptr_t Idx = Value < kMapSizeInBits ? Value : Value % kMapSizeInBits;
uintptr_t WordIdx = Idx / kBitsInWord;
uintptr_t BitIdx = Idx % kBitsInWord;
Expand All @@ -34,6 +34,7 @@ struct ValueBitMap {

// Merges 'Other' into 'this', clears 'Other',
// returns the number of set bits in 'this'.
__attribute__((target("popcnt")))
size_t MergeFrom(ValueBitMap &Other) {
uintptr_t Res = 0;
for (size_t i = 0; i < kMapSizeInWords; i++) {
Expand Down

0 comments on commit ac9c0f4

Please sign in to comment.