diff options
author | Kuan-Wei Chiu <visitorckw@gmail.com> | 2024-06-24 05:51:55 +0800 |
---|---|---|
committer | Kuan-Wei Chiu <visitorckw@gmail.com> | 2024-06-24 06:52:07 +0800 |
commit | ac5815d994fe8ff151e0f13088891acc506662ed (patch) | |
tree | 2534f0f9524dbe69254441d693e41816bf850aab /src/afl-fuzz-bitmap.c | |
parent | 540d741df0541e0e41e600672245ca1e867c5ef4 (diff) | |
download | afl++-ac5815d994fe8ff151e0f13088891acc506662ed.tar.gz |
Optimize bit counting using __builtin_popcount
Use the __builtin_popcount intrinsic to optimize the bit counting function if the compiler supports it. This change replaces the manual bit counting algorithm with the more efficient built-in function, which leverages hardware support on compatible processors. This modification ensures that the code remains backward-compatible by falling back to the original implementation when __builtin_popcount is not available.
Diffstat (limited to 'src/afl-fuzz-bitmap.c')
-rw-r--r-- | src/afl-fuzz-bitmap.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/src/afl-fuzz-bitmap.c b/src/afl-fuzz-bitmap.c index 03bc5d6c..405d2dd6 100644 --- a/src/afl-fuzz-bitmap.c +++ b/src/afl-fuzz-bitmap.c @@ -75,9 +75,13 @@ u32 count_bits(afl_state_t *afl, u8 *mem) { } +#if __has_builtin(__builtin_popcount) + ret += __builtin_popcount(v); +#else v -= ((v >> 1) & 0x55555555); v = (v & 0x33333333) + ((v >> 2) & 0x33333333); ret += (((v + (v >> 4)) & 0xF0F0F0F) * 0x01010101) >> 24; +#endif } |