Skip to content

Commit

Permalink
2.18b
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-huet committed Jul 24, 2016
1 parent 8d579f2 commit 81680ec
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 55 deletions.
102 changes: 49 additions & 53 deletions afl-fuzz.c
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ static u64 get_cur_time_us(void) {

static inline u32 UR(u32 limit) {

if (!rand_cnt--) {
if (unlikely(!rand_cnt--)) {

u32 seed[2];

Expand Down Expand Up @@ -863,9 +863,6 @@ EXP_ST void read_bitmap(u8* fname) {
This function is called after every exec() on a fairly large buffer, so
it needs to be fast. We do this in 32-bit and 64-bit flavors. */

#define FFL(_b) (0xffULL << ((_b) << 3))
#define FF(_b) (0xff << ((_b) << 3))

static inline u8 has_new_bits(u8* virgin_map) {

#ifdef __x86_64__
Expand All @@ -888,53 +885,39 @@ static inline u8 has_new_bits(u8* virgin_map) {

while (i--) {

#ifdef __x86_64__
/* Optimize for (*current & *virgin) == 0 - i.e., no bits in current bitmap
that have not been already cleared from the virgin map - since this will
almost always be the case. */

u64 cur = *current;
u64 vir = *virgin;
if (unlikely(*current) && unlikely(*current & *virgin)) {

#else
if (likely(ret < 2)) {

u32 cur = *current;
u32 vir = *virgin;
u8* cur = (u8*)current;
u8* vir = (u8*)virgin;

#endif /* ^__x86_64__ */

/* Optimize for *current == ~*virgin, since this will almost always be the
case. */

if (cur & vir) {

if (ret < 2) {

/* This trace did not have any new bytes yet; see if there's any
current[] byte that is non-zero when virgin[] is 0xff. */
/* Looks like we have not found any new bytes yet; see if any non-zero
bytes in current[] are pristine in virgin[]. */

#ifdef __x86_64__

if (((cur & FFL(0)) && (vir & FFL(0)) == FFL(0)) ||
((cur & FFL(1)) && (vir & FFL(1)) == FFL(1)) ||
((cur & FFL(2)) && (vir & FFL(2)) == FFL(2)) ||
((cur & FFL(3)) && (vir & FFL(3)) == FFL(3)) ||
((cur & FFL(4)) && (vir & FFL(4)) == FFL(4)) ||
((cur & FFL(5)) && (vir & FFL(5)) == FFL(5)) ||
((cur & FFL(6)) && (vir & FFL(6)) == FFL(6)) ||
((cur & FFL(7)) && (vir & FFL(7)) == FFL(7))) ret = 2;
if ((cur[0] && vir[0] == 0xff) || (cur[1] && vir[1] == 0xff) ||
(cur[2] && vir[2] == 0xff) || (cur[3] && vir[3] == 0xff) ||
(cur[4] && vir[4] == 0xff) || (cur[5] && vir[5] == 0xff) ||
(cur[6] && vir[6] == 0xff) || (cur[7] && vir[7] == 0xff)) ret = 2;
else ret = 1;

#else

if (((cur & FF(0)) && (vir & FF(0)) == FF(0)) ||
((cur & FF(1)) && (vir & FF(1)) == FF(1)) ||
((cur & FF(2)) && (vir & FF(2)) == FF(2)) ||
((cur & FF(3)) && (vir & FF(3)) == FF(3))) ret = 2;
if ((cur[0] && vir[0] == 0xff) || (cur[1] && vir[1] == 0xff) ||
(cur[2] && vir[2] == 0xff) || (cur[3] && vir[3] == 0xff)) ret = 2;
else ret = 1;

#endif /* ^__x86_64__ */

}

*virgin = vir & ~cur;
*virgin &= ~*current;

}

Expand Down Expand Up @@ -982,6 +965,8 @@ static u32 count_bits(u8* mem) {
}


#define FF(_b) (0xff << ((_b) << 3))

/* Count the number of bytes set in the bitmap. Called fairly sporadically,
mostly to update the status screen or calibrate and examine confirmed
new paths. */
Expand Down Expand Up @@ -1060,7 +1045,7 @@ static void simplify_trace(u64* mem) {

/* Optimize for sparse bitmaps. */

if (*mem) {
if (unlikely(*mem)) {

u8* mem8 = (u8*)mem;

Expand Down Expand Up @@ -1091,7 +1076,7 @@ static void simplify_trace(u32* mem) {

/* Optimize for sparse bitmaps. */

if (*mem) {
if (unlikely(*mem)) {

u8* mem8 = (u8*)mem;

Expand All @@ -1114,7 +1099,7 @@ static void simplify_trace(u32* mem) {
preprocessing step for any newly acquired traces. Called on every exec,
must be fast. */

static const u8 count_class_lookup[256] = {
static const u8 count_class_lookup8[256] = {

[0] = 0,
[1] = 1,
Expand All @@ -1128,6 +1113,22 @@ static const u8 count_class_lookup[256] = {

};

static u16 count_class_lookup16[65536];


static void init_count_class16(void) {

u32 b1, b2;

for (b1 = 0; b1 < 256; b1++)
for (b2 = 0; b2 < 256; b2++)
count_class_lookup16[(b1 << 8) + b2] =
(count_class_lookup8[b1] << 8) |
count_class_lookup8[b2];

}


#ifdef __x86_64__

static inline void classify_counts(u64* mem) {
Expand All @@ -1138,18 +1139,14 @@ static inline void classify_counts(u64* mem) {

/* Optimize for sparse bitmaps. */

if (*mem) {
if (unlikely(*mem)) {

u8* mem8 = (u8*)mem;
u16* mem16 = (u16*)mem;

mem8[0] = count_class_lookup[mem8[0]];
mem8[1] = count_class_lookup[mem8[1]];
mem8[2] = count_class_lookup[mem8[2]];
mem8[3] = count_class_lookup[mem8[3]];
mem8[4] = count_class_lookup[mem8[4]];
mem8[5] = count_class_lookup[mem8[5]];
mem8[6] = count_class_lookup[mem8[6]];
mem8[7] = count_class_lookup[mem8[7]];
mem16[0] = count_class_lookup16[mem16[0]];
mem16[1] = count_class_lookup16[mem16[1]];
mem16[2] = count_class_lookup16[mem16[2]];
mem16[3] = count_class_lookup16[mem16[3]];

}

Expand All @@ -1169,14 +1166,12 @@ static inline void classify_counts(u32* mem) {

/* Optimize for sparse bitmaps. */

if (*mem) {
if (unlikely(*mem)) {

u8* mem8 = (u8*)mem;
u16* mem16 = (u16*)mem;

mem8[0] = count_class_lookup[mem8[0]];
mem8[1] = count_class_lookup[mem8[1]];
mem8[2] = count_class_lookup[mem8[2]];
mem8[3] = count_class_lookup[mem8[3]];
mem16[0] = count_class_lookup16[mem16[0]];
mem16[1] = count_class_lookup16[mem16[1]];

}

Expand Down Expand Up @@ -7764,6 +7759,7 @@ int main(int argc, char** argv) {

setup_post();
setup_shm();
init_count_class16();

setup_dirs_fds();
read_testcases();
Expand Down
2 changes: 1 addition & 1 deletion config.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

/* Version string: */

#define VERSION "2.17b"
#define VERSION "2.18b"

/******************************************************
* *
Expand Down
10 changes: 9 additions & 1 deletion docs/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,17 @@ Want to stay in the loop on major new features? Join our mailing list by
sending a mail to <[email protected]>.

Not sure if you should upgrade? The lowest currently recommended version
is 2.07b. If you're stuck on an earlier release, it's strongly advisable
is 2.18b. If you're stuck on an earlier release, it's strongly advisable
to get on with the times.

--------------
Version 2.18b:
--------------

- Made several performance improvements to has_new_bits() and
classify_counts(). This should offer a robust performance bump with
fast targets.

--------------
Version 2.17b:
--------------
Expand Down
3 changes: 3 additions & 0 deletions types.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,7 @@ typedef int64_t s64;
#define MEM_BARRIER() \
asm volatile("" ::: "memory")

#define likely(_x) __builtin_expect(!!(_x), 1)
#define unlikely(_x) __builtin_expect(!!(_x), 0)

#endif /* ! _HAVE_TYPES_H */

0 comments on commit 81680ec

Please sign in to comment.