]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Clean up likely/unlikely definitions
authorhansr <hk-git@circlestorm.org>
Thu, 9 Oct 2014 13:10:33 +0000 (15:10 +0200)
committerhansr <hk-git@circlestorm.org>
Thu, 9 Oct 2014 13:10:33 +0000 (15:10 +0200)
deflate.h
deflate_medium.c
match.c
zutil.h

index 2edf21a52851ae9a0e9f8ba421b35af765a379f8..027a075ab817a1f08ee7ddc9a101663247b46fbb 100644 (file)
--- 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 */
index 4beada8d85ae5c52fbbb6b03844e1d1f5a9d956e..0d4d98a7da321b48bb7ee062d47bf390ad9337a7 100644 (file)
@@ -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 9ad52d0a11c33c22f26a6592758f43da6b0bd51d..22077bfcf10defac22b2cf365301286255dacaca 100644 (file)
--- 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 20fb98552788dbeb31fee0d089dc33485d0d91d2..62ff87fa18644f48c59bdf972c743308e4e298ad 100644 (file)
--- 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 */