Skip to content

Commit

Permalink
zlib_deflate/deftree: remove bi_reverse()
Browse files Browse the repository at this point in the history
Remove bi_reverse() and use generic bitrev32() instead - it should have
better performance on some platforms.

Signed-off-by: yalin wang <yalin.wang2010@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
yalin wang authored and torvalds committed Sep 10, 2015
1 parent e4e29dc commit 8b235f2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 19 deletions.
6 changes: 3 additions & 3 deletions lib/zlib_deflate/deftree.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
/* #include "deflate.h" */

#include <linux/zutil.h>
#include <linux/bitrev.h>
#include "defutil.h"

#ifdef DEBUG_ZLIB
Expand Down Expand Up @@ -146,7 +147,6 @@ static void send_all_trees (deflate_state *s, int lcodes, int dcodes,
static void compress_block (deflate_state *s, ct_data *ltree,
ct_data *dtree);
static void set_data_type (deflate_state *s);
static unsigned bi_reverse (unsigned value, int length);
static void bi_windup (deflate_state *s);
static void bi_flush (deflate_state *s);
static void copy_block (deflate_state *s, char *buf, unsigned len,
Expand Down Expand Up @@ -284,7 +284,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 = bi_reverse((unsigned)n, 5);
static_dtree[n].Code = bitrev32((u32)n) >> (32 - 5);
}
static_init_done = 1;
}
Expand Down Expand Up @@ -520,7 +520,7 @@ static void gen_codes(
int len = tree[n].Len;
if (len == 0) continue;
/* Now reverse the bits */
tree[n].Code = bi_reverse(next_code[len]++, len);
tree[n].Code = bitrev32((u32)(next_code[len]++)) >> (32 - len);

Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
Expand Down
16 changes: 0 additions & 16 deletions lib/zlib_deflate/defutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,22 +292,6 @@ void zlib_tr_stored_type_only (deflate_state *);
put_byte(s, (uch)((ush)(w) >> 8)); \
}

/* ===========================================================================
* Reverse the first len bits of a code, using straightforward code (a faster
* method would use a table)
* IN assertion: 1 <= len <= 15
*/
static inline unsigned bi_reverse(unsigned code, /* the value to invert */
int len) /* its bit length */
{
register unsigned res = 0;
do {
res |= code & 1;
code >>= 1, res <<= 1;
} while (--len > 0);
return res >> 1;
}

/* ===========================================================================
* Flush the bit buffer, keeping at most 7 bits in it.
*/
Expand Down

0 comments on commit 8b235f2

Please sign in to comment.