summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhansr <hk-git@circlestorm.org>2014-10-09 15:10:33 +0200
committerhansr <hk-git@circlestorm.org>2014-10-09 15:10:33 +0200
commit1eecc12f19f75fd59f59fad5d36daa5e520f43fc (patch)
tree461b1749c5894080e4ba40a197c20cc6bba12636
parent279e637d951d3101d5509e60f4ca8c39178e3518 (diff)
downloadProject-Tick-1eecc12f19f75fd59f59fad5d36daa5e520f43fc.tar.gz
Project-Tick-1eecc12f19f75fd59f59fad5d36daa5e520f43fc.zip
Clean up likely/unlikely definitions
-rw-r--r--deflate.h4
-rw-r--r--deflate_medium.c6
-rw-r--r--match.c2
-rw-r--r--zutil.h25
4 files changed, 21 insertions, 16 deletions
diff --git a/deflate.h b/deflate.h
index 2edf21a528..027a075ab8 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 4beada8d85..0d4d98a7da 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 9ad52d0a11..22077bfcf1 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 20fb985527..62ff87fa18 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 */