From: hansr Date: Thu, 9 Oct 2014 13:10:33 +0000 (+0200) Subject: Clean up likely/unlikely definitions X-Git-Tag: 1.9.9-b1~925 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1eecc12f19f75fd59f59fad5d36daa5e520f43fc;p=thirdparty%2Fzlib-ng.git Clean up likely/unlikely definitions --- diff --git a/deflate.h b/deflate.h index 2edf21a52..027a075ab 100644 --- a/deflate.h +++ b/deflate.h @@ -459,8 +459,4 @@ local void send_bits(s, value, length) } #endif - -#define likely(x) __builtin_expect((x),1) -#define unlikely(x) __builtin_expect((x),0) - #endif /* DEFLATE_H */ diff --git a/deflate_medium.c b/deflate_medium.c index 4beada8d8..0d4d98a7d 100644 --- a/deflate_medium.c +++ b/deflate_medium.c @@ -54,7 +54,7 @@ static int emit_match(deflate_state *s, struct match match, IPos hash_head) static void insert_match(deflate_state *s, struct match match) { - if (zunlikely(s->lookahead <= match.match_length + MIN_MATCH)) + if (unlikely(s->lookahead <= match.match_length + MIN_MATCH)) return; /* matches that are not long enough we need to emit as litterals */ @@ -80,7 +80,7 @@ static void insert_match(deflate_state *s, struct match match) match.match_length--; /* string at strstart already in table */ do { match.strstart++; - if (zlikely(match.strstart >= match.orgstart)) { + if (likely(match.strstart >= match.orgstart)) { insert_string(s, match.strstart); } /* strstart never exceeds WSIZE-MAX_MATCH, so there are @@ -118,7 +118,7 @@ static void fizzle_matches(deflate_state *s, struct match *current, struct match orig = s->window - current->match_length + 1 + next->strstart ; /* quick exit check.. if this fails then don't bother with anything else */ - if (zlikely(*match != *orig)) + if (likely(*match != *orig)) return; /* diff --git a/match.c b/match.c index 9ad52d0a1..22077bfcf 100644 --- a/match.c +++ b/match.c @@ -201,7 +201,7 @@ local unsigned std2_longest_match(deflate_state *z_const s, IPos cur_match) * is limited to the lookahead, so the output of deflate is not * affected by the uninitialized values. */ - if (zlikely((*(unsigned short *)(match + best_len - 1) != scan_end))) + if (likely((*(unsigned short *)(match + best_len - 1) != scan_end))) continue; if (*(unsigned short *)match != scan_start) continue; diff --git a/zutil.h b/zutil.h index 20fb98552..62ff87fa1 100644 --- a/zutil.h +++ b/zutil.h @@ -121,14 +121,6 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ #pragma warn -8066 #endif -#if defined(__GNUC__) -# define zlikely(x) __builtin_expect(!!(x), 1) -# define zunlikely(x) __builtin_expect(!!(x), 0) -#else -# define zlikely(x) x -# define zunlikely(x) x -#endif - /* provide prototypes for these when building zlib without LFS */ #if !defined(_WIN32) && \ (!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0) @@ -235,4 +227,21 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ (((q) & 0xff00) << 8) + (((q) & 0xff) << 24)) #endif /* ZSWAP32 */ +/* Only enable likely/unlikely if the compiler is known to support it */ +#if defined(__GNUC__) && (__GNUC__ >= 3) +# ifndef likely +# define likely(x) __builtin_expect(!!(x),1) +# endif +# ifndef unlikely +# define unlikely(x) __builtin_expect(!!(x),0) +# endif +#else +# ifndef likely +# define likely(x) x +# endif +# ifndef unlikely +# define unlikely(x) x +# endif +#endif /* (un)likely */ + #endif /* ZUTIL_H */