]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Clean up LIKELY/UNLIKELY definitions, making them upper-case to improve visibility.
authorHans Kristian Rosbach <hk-git@circlestorm.org>
Mon, 23 Sep 2019 07:47:32 +0000 (09:47 +0200)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Tue, 22 Oct 2019 07:56:34 +0000 (09:56 +0200)
Add LIKELY_NULL hint.
Add PREFETCH_L1, PREFETCH_L2 and PREFETCH_RW for GCC, Clang, ICC and MSVC.

arch/arm/fill_window_arm.c
arch/arm/insert_string_acle.c
arch/x86/fill_window_sse.c
deflate.c
deflate_medium.c
deflate_slow.c
match_p.h
zutil.h

index 571585ba9bf7c6ad2d1da768c6b1722d61ca931c..4eccdc02e5e78bdb8ba461f439cb6038e3fa0d90 100644 (file)
@@ -112,7 +112,7 @@ void fill_window_arm(deflate_state *s) {
 
             s->ins_h = s->window[str];
 
-            if (unlikely(s->lookahead < MIN_MATCH))
+            if (UNLIKELY(s->lookahead < MIN_MATCH))
                 insert_cnt += s->lookahead - MIN_MATCH;
             slen = insert_cnt;
             if (str >= (MIN_MATCH - 2))
index 2b306fed8e4ffa6d1ff3eb882447dd0ccaa5cd49..363f050b041c208a258fc752f5fdb50648d14933 100644 (file)
@@ -21,7 +21,7 @@
 Pos insert_string_acle(deflate_state *const s, const Pos str, unsigned int count) {
     Pos p, lp, ret;
 
-    if (unlikely(count == 0)) {
+    if (UNLIKELY(count == 0)) {
         return s->prev[str & s->w_mask];
     }
 
index 818407d28f6fbb55a809a8028a2c99ca9ff90542..4a4f5fa2bedc43a083893f800c5bb076073b9df3 100644 (file)
@@ -95,7 +95,7 @@ ZLIB_INTERNAL void fill_window_sse(deflate_state *s) {
             }
 #else
             unsigned int count;
-            if (unlikely(s->lookahead == 1)){
+            if (UNLIKELY(s->lookahead == 1)){
                 count = s->insert - 1;
             }else{
                 count = s->insert;
index 48ad811329a6a51bd4aab7c3b00a5c937988bb71..61c51f6f7d8ad7a266b0429140b6a95629955676 100644 (file)
--- a/deflate.c
+++ b/deflate.c
@@ -1335,7 +1335,7 @@ void ZLIB_INTERNAL fill_window_c(deflate_state *s) {
             }
 #else
             unsigned int count;
-            if (unlikely(s->lookahead == 1)){
+            if (UNLIKELY(s->lookahead == 1)){
                 count = s->insert - 1;
             }else{
                 count = s->insert;
index 07dbf2af519e1b35683a4d4b5629e6e4e577a8bc..f320c3c8fa6080c160cfef74b1bd58dc655c4f47 100644 (file)
@@ -53,7 +53,7 @@ static int emit_match(deflate_state *s, struct match match) {
 }
 
 static void insert_match(deflate_state *s, struct match match) {
-    if (unlikely(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 literals */
@@ -95,7 +95,7 @@ static void insert_match(deflate_state *s, struct match match) {
         match.strstart++;
 #ifdef NOT_TWEAK_COMPILER
         do {
-            if (likely(match.strstart >= match.orgstart)) {
+            if (LIKELY(match.strstart >= match.orgstart)) {
                 functable.insert_string(s, match.strstart, 1);
             }
             match.strstart++;
@@ -104,8 +104,8 @@ static void insert_match(deflate_state *s, struct match match) {
              */
         } while (--match.match_length != 0);
 #else
-        if (likely(match.strstart >= match.orgstart)) {
-            if (likely(match.strstart + match.match_length - 1 >= match.orgstart)) {
+        if (LIKELY(match.strstart >= match.orgstart)) {
+            if (LIKELY(match.strstart + match.match_length - 1 >= match.orgstart)) {
                 functable.insert_string(s, match.strstart, match.match_length);
             } else {
                 functable.insert_string(s, match.strstart, match.orgstart - match.strstart + 1);
@@ -145,17 +145,17 @@ static void fizzle_matches(deflate_state *s, struct match *current, struct match
     if (current->match_length <= 1)
         return;
 
-    if (unlikely(current->match_length > 1 + next->match_start))
+    if (UNLIKELY(current->match_length > 1 + next->match_start))
         return;
 
-    if (unlikely(current->match_length > 1 + next->strstart))
+    if (UNLIKELY(current->match_length > 1 + next->strstart))
         return;
 
     match = s->window - current->match_length + 1 + next->match_start;
     orig  = s->window - current->match_length + 1 + next->strstart;
 
     /* quick exit check.. if this fails then don't bother with anything else */
-    if (likely(*match != *orig))
+    if (LIKELY(*match != *orig))
         return;
 
     c = *current;
index 7cb9c70f82f6681b950e05c985c66cb1deeddf64..9db8c1657bb41d5e9626907e7ac27e25bffc618a 100644 (file)
@@ -110,7 +110,7 @@ ZLIB_INTERNAL block_state deflate_slow(deflate_state *s, int flush) {
                 unsigned int mov_fwd = s->prev_length - 2;
                 if (max_insert > s->strstart) {
                     unsigned int insert_cnt = mov_fwd;
-                    if (unlikely(insert_cnt > max_insert - s->strstart))
+                    if (UNLIKELY(insert_cnt > max_insert - s->strstart))
                         insert_cnt = max_insert - s->strstart;
 
                     functable.insert_string(s, s->strstart + 1, insert_cnt);
index 363c7a3ced3f6f4d7aff8a4befbfa7124bd5ef66..742100ac939b3c81ddb6e7149db93f36ef77449b 100644 (file)
--- a/match_p.h
+++ b/match_p.h
@@ -226,7 +226,7 @@ static inline unsigned longest_match(deflate_state *const s, IPos cur_match) {
          */
         uint16_t val;
         memcpy(&val, match + best_len - 1, sizeof(val));
-        if (likely(val != scan_end))
+        if (LIKELY(val != scan_end))
             continue;
 
         memcpy(&val, match, sizeof(val));
@@ -432,7 +432,7 @@ static inline unsigned longest_match(deflate_state *const s, IPos cur_match) {
         int cont = 1;
         do {
             match = window + cur_match;
-            if (likely(memcmp(match+best_len-1, &scan_end, sizeof(scan_end)) != 0
+            if (LIKELY(memcmp(match+best_len-1, &scan_end, sizeof(scan_end)) != 0
                 || memcmp(match, &scan_start, sizeof(scan_start)) != 0)) {
                 if ((cur_match = prev[cur_match & wmask]) > limit
                     && --chain_length != 0) {
diff --git a/zutil.h b/zutil.h
index 9db42008865dd172a9ea3812a9697740a1b12168..f9cf3ff9fe539f4147c9f1890a8b9fa7cf6e6181 100644 (file)
--- a/zutil.h
+++ b/zutil.h
@@ -215,19 +215,27 @@ void ZLIB_INTERNAL   zng_cfree(void *opaque, void *ptr);
 
 /* Only enable likely/unlikely if the compiler is known to support it */
 #if (defined(__GNUC__) && (__GNUC__ >= 3)) || defined(__INTEL_COMPILER) || defined(__Clang__)
-#  ifndef likely
-#    define likely(x)      __builtin_expect(!!(x), 1)
-#  endif
-#  ifndef unlikely
-#    define unlikely(x)    __builtin_expect(!!(x), 0)
-#  endif
+#    define LIKELY_NULL(x)      __builtin_expect((x) != 0, 0)
+#    define LIKELY(x)           __builtin_expect(!!(x), 1)
+#    define UNLIKELY(x)         __builtin_expect(!!(x), 0)
+#    define PREFETCH_L1(addr)    __builtin_prefetch(addr, 0, 3)
+#    define PREFETCH_L2(addr)    __builtin_prefetch(addr, 0, 2)
+#    define PREFETCH_RW(addr)    __builtin_prefetch(addr, 1, 2)
+#elif defined(__WIN__)
+#    include <xmmintrin.h>
+#    define LIKELY_NULL(x) x
+#    define LIKELY(x)      x
+#    define UNLIKELY(x)    x
+#    define PREFETCH_L1(addr)    _mm_prefetch((char *) addr, _MM_HINT_T0)
+#    define PREFETCH_L2(addr)    _mm_prefetch((char *) addr, _MM_HINT_T1)
+#    define PREFETCH_RW(addr)    _mm_prefetch((char *) addr, _MM_HINT_T1)
 #else
-#  ifndef likely
-#    define likely(x)      x
-#  endif
-#  ifndef unlikely
-#    define unlikely(x)    x
-#  endif
+#    define LIKELY_NULL(x) x
+#    define LIKELY(x)      x
+#    define UNLIKELY(x)    x
+#    define PREFETCH_L1(addr)    addr
+#    define PREFETCH_L2(addr)    addr
+#    define PREFETCH_RW(addr)    addr
 #endif /* (un)likely */
 
 #if defined(_MSC_VER)