Update of /cvsroot/blob/blob/src/lib
In directory usw-pr-cvs1:/tmp/cvs-serv335/src/lib
Modified Files:
Makefile.am
Added Files:
crc32.c
Log Message:
I've been playing with Russ' JFFS2 patch and had some problems with its
CRC32 implementation (both size and performance). Luckily Russell King
wrote a CRC32 implementation without the huge table, and after some tuning
it is both small and fast (on ARM).
--- NEW FILE: crc32.c ---
/*
* crc32.c: calculate CRC32
*
* Copyright (C) 1995-2001 Russell King <rm...@ar...>
* based on linux/drivers/net/am79c961a.c
* Copyright (C) 2002 Erik Mouw <J.A...@it...>
*
* $Id: crc32.c,v 1.1 2002/01/20 23:16:18 erikm Exp $
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
/*
* Note: this implementation doesn't use the usual lookup table
* implementation by Gary S. Brown. The lookup table is quite large
* (1kB) and it's quite slow because we run with d-cache enabled. The
* i-cache is enabled, so computing the crc will be a lot faster. And
* of course this implementation is a lot smaller :)
*
*/
#ident "$Id: crc32.c,v 1.1 2002/01/20 23:16:18 erikm Exp $"
#ifdef HAVE_CONFIG_H
# include <blob/config.h>
#endif
#include <blob/types.h>
#define POLYNOME (0xedb88320)
static inline u32 update_crc(u32 crc, u8 byte)
{
int i;
u32 polynome = POLYNOME;
/* the above might look stupid, but it is a cludge to get
* better code. with the -Os flag, the compiler moves the
* POLYNOME into the .rodata segment and reloads it on every
* run. this kinda defeats the purpose of doing CRC32 without
* a lookup table. by moving the polynome explicitly out of
* the loop, the compiler will allocate a register for it
* making the resulting code faster. -- Erik
*/
for (i = 8; i != 0; i--) {
byte ^= crc & 1;
crc >>= 1;
if (byte & 1)
crc ^= polynome;
byte >>= 1;
}
return crc;
}
u32 crc32(u32 val, const void *data, int len)
{
u32 crc = val;
u8 *tmp = (u8 *)data;
while(len--)
crc = update_crc(crc, *tmp++);
return crc;
}
Index: Makefile.am
===================================================================
RCS file: /cvsroot/blob/blob/src/lib/Makefile.am,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- Makefile.am 2002/01/06 18:59:40 1.9
+++ Makefile.am 2002/01/20 23:16:18 1.10
@@ -27,6 +27,7 @@
libblob_a_SOURCES = \
command.c \
+ crc32.c \
error.c \
icache.c \
init.c \
|