]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Inline bi_reverse develop
authorHans Kristian Rosbach <hk-git@circlestorm.org>
Fri, 22 Aug 2025 07:39:25 +0000 (09:39 +0200)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Sat, 23 Aug 2025 15:26:45 +0000 (17:26 +0200)
arch/s390/dfltcc_deflate.c
deflate.h
deflate_p.h
tools/maketrees.c
trees.c

index 90b4b96e9ce33509e717eebd71749dc5b4b9128c..8216771f3d72b83cb4cefff4ff3e14dd1041f10e 100644 (file)
@@ -15,6 +15,7 @@
 
 #include "zbuild.h"
 #include "deflate.h"
+#include "deflate_p.h"
 #include "trees_emit.h"
 #include "dfltcc_deflate.h"
 #include "dfltcc_detail.h"
@@ -90,7 +91,7 @@ static inline dfltcc_cc dfltcc_cmpr(PREFIX3(streamp) strm) {
 static inline void send_eobs(PREFIX3(streamp) strm, const struct dfltcc_param_v0 *param) {
     deflate_state *state = (deflate_state *)strm->state;
 
-    send_bits(state, PREFIX(bi_reverse)(param->eobs >> (15 - param->eobl), param->eobl), param->eobl, state->bi_buf, state->bi_valid);
+    send_bits(state, bi_reverse(param->eobs >> (15 - param->eobl), param->eobl), param->eobl, state->bi_buf, state->bi_valid);
     PREFIX(flush_pending)(strm);
     if (state->pending != 0) {
         /* The remaining data is located in pending_out[0:pending]. If someone
index 02d68211a318d2121cd72b4ef3501ca6b2271caa..e6b010885079086bc2e1f816f25449bc826713d1 100644 (file)
--- a/deflate.h
+++ b/deflate.h
@@ -432,7 +432,6 @@ void Z_INTERNAL zng_tr_flush_block(deflate_state *s, char *buf, uint32_t stored_
 void Z_INTERNAL zng_tr_flush_bits(deflate_state *s);
 void Z_INTERNAL zng_tr_align(deflate_state *s);
 void Z_INTERNAL zng_tr_stored_block(deflate_state *s, char *buf, uint32_t stored_len, int last);
-uint16_t Z_INTERNAL PREFIX(bi_reverse)(unsigned code, int len);
 void Z_INTERNAL PREFIX(flush_pending)(PREFIX3(streamp) strm);
 #define d_code(dist) ((dist) < 256 ? zng_dist_code[dist] : zng_dist_code[256+((dist)>>7)])
 /* Mapping from a distance to a distance code. dist is the distance - 1 and
index abcc8b1c7c1255e211d7979afa2fdbcb34eb5fea..24d1c35b1ddcaaef541dc8cca4ff1f19cd265e73 100644 (file)
@@ -97,6 +97,18 @@ static inline int zng_tr_tally_dist(deflate_state* s, uint32_t dist, uint32_t le
     return (s->sym_next == s->sym_end);
 }
 
+/* ===========================================================================
+ * Reverse the first len bits of a code using bit manipulation
+ */
+static inline uint16_t bi_reverse(unsigned code, int len) {
+    /* code: the value to invert */
+    /* len: its bit length */
+    Assert(len >= 1 && len <= 15, "code length must be 1-15");
+#define bitrev8(b) \
+    (uint8_t)((((uint8_t)(b) * 0x80200802ULL) & 0x0884422110ULL) * 0x0101010101ULL >> 32)
+    return (bitrev8(code >> 8) | (uint16_t)bitrev8(code) << 8) >> (16 - len);
+}
+
 /* ===========================================================================
  * Flush the current block, with given end-of-file flag.
  * IN assertion: strstart is set to the end of the current match.
index 2c32ccae08e89f62f86af72d865aaf16f6566d29..317c2d46b4d1e0472d2a884603abd107e356337e 100644 (file)
@@ -6,6 +6,7 @@
 #include <stdio.h>
 #include "zbuild.h"
 #include "deflate.h"
+#include "deflate_p.h"
 #include "trees.h"
 
 static ct_data static_ltree[L_CODES+2];
@@ -90,7 +91,7 @@ static void tr_static_init(void) {
     /* The static distance tree is trivial: */
     for (n = 0; n < D_CODES; n++) {
         static_dtree[n].Len = 5;
-        static_dtree[n].Code = PREFIX(bi_reverse)((unsigned)n, 5);
+        static_dtree[n].Code = bi_reverse((unsigned)n, 5);
     }
 }
 
diff --git a/trees.c b/trees.c
index 8debd63f3c19d0f4014218b34ec5f8e716754d88..5fc1fc924b680e4ffa673f4aa24217b37eab013d 100644 (file)
--- a/trees.c
+++ b/trees.c
@@ -32,6 +32,7 @@
 
 #include "zbuild.h"
 #include "deflate.h"
+#include "deflate_p.h"
 #include "trees.h"
 #include "trees_emit.h"
 #include "trees_tbl.h"
@@ -399,7 +400,7 @@ Z_INTERNAL void gen_codes(ct_data *tree, int max_code, uint16_t *bl_count) {
         if (len == 0)
             continue;
         /* Now reverse the bits */
-        tree[n].Code = PREFIX(bi_reverse)(next_code[len]++, len);
+        tree[n].Code = bi_reverse(next_code[len]++, len);
 
         Tracecv(tree != static_ltree, (stderr, "\nn %3d %c l %2d c %4x (%x) ",
              n, (isgraph(n & 0xff) ? n : ' '), len, tree[n].Code, next_code[len]-1));
@@ -815,15 +816,3 @@ void Z_INTERNAL zng_tr_flush_bits(deflate_state *s) {
         s->bi_valid -= 8;
     }
 }
-
-/* ===========================================================================
- * Reverse the first len bits of a code using bit manipulation
- */
-Z_INTERNAL uint16_t PREFIX(bi_reverse)(unsigned code, int len) {
-    /* code: the value to invert */
-    /* len: its bit length */
-    Assert(len >= 1 && len <= 15, "code length must be 1-15");
-#define bitrev8(b) \
-    (uint8_t)((((uint8_t)(b) * 0x80200802ULL) & 0x0884422110ULL) * 0x0101010101ULL >> 32)
-    return (bitrev8(code >> 8) | (uint16_t)bitrev8(code) << 8) >> (16 - len);
-}