From: Matt Mackall <mpm@selenic.com>
To: Andrew Morton <akpm@osdl.org>
Cc: linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org,
linux-tiny@selenic.com
Subject: [PATCH 20/20] inflate: make in-core inflate share common CRC
Date: Thu, 22 Dec 2005 12:27:13 -0600 [thread overview]
Message-ID: <21.150843412@selenic.com> (raw)
In-Reply-To: <20.150843412@selenic.com>
inflate: make in-core inflate share common CRC code
Signed-off-by: Matt Mackall <mpm@selenic.com>
Index: 2.6.14-inflate/lib/inflate.c
===================================================================
--- 2.6.14-inflate.orig/lib/inflate.c 2005-12-21 21:19:36.000000000 -0600
+++ 2.6.14-inflate/lib/inflate.c 2005-12-21 21:20:51.000000000 -0600
@@ -142,24 +142,46 @@ static void free(void *where)
static u8 window[0x8000]; /* use a statically allocated window */
+/* simple CRC calculation */
+static u32 crc_32_tab[256];
+#define CRCPOLY_LE 0xedb88320
+
#define INIT
#define INITDATA const
+static void makecrc(void)
+{
+ unsigned i, j;
+ u32 c = 1;
+
+ for (i = 128; i; i >>= 1) {
+ c = (c >> 1) ^ ((c & 1) ? CRCPOLY_LE : 0);
+ for (j = 0; j < 256; j += 2 * i)
+ crc_32_tab[i + j] = c ^ crc_32_tab[j];
+ }
+}
+
+static u32 crc32_le(u32 crc, unsigned char const *p, size_t len)
+{
+ while (len--)
+ crc = crc_32_tab[(*p++ ^ crc) & 0xff] ^ (crc >> 8);
+
+ return crc;
+}
#else
#include <linux/module.h>
+#include <linux/crc32.h>
static u8 *window; /* dynamically allocate */
#define malloc(a) kmalloc(a, GFP_KERNEL)
#define free(a) kfree(a)
+#define makecrc()
#define INIT __init
#define INITDATA __initdata
#endif
-static u32 crc_32_tab[256];
-#define CRCPOLY_LE 0xedb88320
-
/* Huffman code lookup table entry--this entry is four bytes for machines
that have 16-bit pointers (e.g. PC's in the small or medium model).
Valid extra bits are 0..13. e == 15 is EOB (end of block), e == 16
@@ -204,12 +226,7 @@ static int INIT inflate(struct iostate *
static void flush_output(struct iostate *io)
{
- int i;
-
- for (i = 0; i < io->opos; i++)
- io->crc = crc_32_tab[(io->window[i] ^ (int)io->crc) & 0xff]
- ^ (io->crc >> 8);
-
+ io->crc = crc32_le(io->crc, io->window, io->opos);
io->flush(io->window, io->opos);
io->ototal += io->opos;
io->opos = 0;
@@ -905,24 +922,6 @@ static int INIT inflate(struct iostate *
return 0;
}
-/**********************************************************************
- *
- * The following are support routines for inflate.c
- *
- **********************************************************************/
-
-static void INIT makecrc(void)
-{
- unsigned i, j;
- u32 c = 1;
-
- for (i = 128; i; i >>= 1) {
- c = (c >> 1) ^ ((c & 1) ? CRCPOLY_LE : 0);
- for (j = 0; j < 256; j += 2 * i)
- crc_32_tab[i + j] = c ^ crc_32_tab[j];
- }
-}
-
/* gzip flag byte */
#define ASCII_FLAG 0x01 /* bit 0 set: file probably ASCII text */
#define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
next prev parent reply other threads:[~2005-12-22 18:29 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-12-22 18:26 [PATCH 0/20] inflate: refactor boot-time inflate code Matt Mackall
2005-12-22 18:26 ` [PATCH 1/20] inflate: lindent and manual formatting changes Matt Mackall
2005-12-22 18:26 ` [PATCH 2/20] inflate: kill legacy bits Matt Mackall
2005-12-22 18:26 ` [PATCH 3/20] inflate: clean up input logic Matt Mackall
2005-12-22 18:26 ` [PATCH 4/20] inflate: start moving globals into iostate Matt Mackall
2005-12-22 18:26 ` [PATCH 5/20] inflate: cleanup Huffman table code Matt Mackall
2005-12-22 18:26 ` [PATCH 6/20] inflate: internalize CRC calculation, cleanup table calculation Matt Mackall
2005-12-22 18:26 ` [PATCH 7/20] inflate: eliminate memzero usage Matt Mackall
2005-12-22 18:26 ` [PATCH 8/20] inflate: (arch) kill unneeded declarations Matt Mackall
2005-12-22 18:26 ` [PATCH 9/20] inflate: (arch) refactor inflate malloc code Matt Mackall
2005-12-22 18:26 ` [PATCH 10/20] inflate: (arch) kill external CRC calculation Matt Mackall
2005-12-22 18:26 ` [PATCH 11/20] inflate: (arch) kill get_byte Matt Mackall
2005-12-22 18:26 ` [PATCH 12/20] inflate: internalize (arch) most of the output window handling Matt Mackall
2005-12-22 18:26 ` [PATCH 13/20] inflate: (arch) kill silly zlib typedefs Matt Mackall
2005-12-22 18:26 ` [PATCH 14/20] inflate: (arch) use an error callback rather than a global Matt Mackall
2005-12-22 18:26 ` [PATCH 15/20] inflate: (arch) tidy user declarations Matt Mackall
2005-12-22 18:26 ` [PATCH 16/20] inflate: remove legacy DEBG macros Matt Mackall
2005-12-22 18:26 ` [PATCH 17/20] inflate: mark some arrays as initdata Matt Mackall
2005-12-22 18:27 ` [PATCH 18/20] inflate: minor const changes Matt Mackall
2005-12-22 18:27 ` [PATCH 19/20] inflate: (arch) use proper linking Matt Mackall
2005-12-22 18:27 ` Matt Mackall [this message]
2006-01-05 3:50 ` [PATCH 0/20] inflate: refactor boot-time inflate code Andrew Morton
2006-01-05 5:09 ` Matt Mackall
-- strict thread matches above, loose matches on Subject: below --
2005-10-31 20:54 [PATCH 19/20] inflate: (arch) use proper linking Matt Mackall
2005-10-31 20:54 ` [PATCH 20/20] inflate: make in-core inflate share common CRC Matt Mackall
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=21.150843412@selenic.com \
--to=mpm@selenic.com \
--cc=akpm@osdl.org \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tiny@selenic.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox