summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
authorMiika Pekkarinen <miipekk@ihme.org>2006-04-18 18:56:56 +0000
committerMiika Pekkarinen <miipekk@ihme.org>2006-04-18 18:56:56 +0000
commitfa893c6b88d823dcdd3c746a94cfcde9765342cd (patch)
tree3aea16925a89b78f80dce844ce48d8e8fea60a22 /firmware
parent2b18727a8abe08cf5f9d267d5f664bff13bd1cb2 (diff)
downloadrockbox-fa893c6b88d823dcdd3c746a94cfcde9765342cd.tar.gz
rockbox-fa893c6b88d823dcdd3c746a94cfcde9765342cd.zip
Performance optimizations for tagcache commit. Still more left to be done.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@9721 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware')
-rw-r--r--firmware/SOURCES1
-rw-r--r--firmware/common/crc32.c57
-rw-r--r--firmware/include/crc32.h25
3 files changed, 83 insertions, 0 deletions
diff --git a/firmware/SOURCES b/firmware/SOURCES
index 4b2e63d378..07f4ffd796 100644
--- a/firmware/SOURCES
+++ b/firmware/SOURCES
@@ -5,6 +5,7 @@ logf.c
5backlight.c 5backlight.c
6buffer.c 6buffer.c
7common/atoi.c 7common/atoi.c
8common/crc32.c
8common/ctype.c 9common/ctype.c
9#ifndef SIMULATOR 10#ifndef SIMULATOR
10common/dir.c 11common/dir.c
diff --git a/firmware/common/crc32.c b/firmware/common/crc32.c
new file mode 100644
index 0000000000..18ee6ac710
--- /dev/null
+++ b/firmware/common/crc32.c
@@ -0,0 +1,57 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2003 Jörg Hohensohn [IDC]Dragon
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20/* Code copied from firmware_flash plugin. */
21
22/* Tool function to calculate a CRC32 across some buffer */
23/* third argument is either 0xFFFFFFFF to start or value from last piece */
24unsigned crc_32(unsigned char* buf, unsigned len, unsigned crc32)
25{
26 /* CCITT standard polynomial 0x04C11DB7 */
27 static const unsigned crc32_lookup[16] =
28 { /* lookup table for 4 bits at a time is affordable */
29 0x00000000, 0x04C11DB7, 0x09823B6E, 0x0D4326D9,
30 0x130476DC, 0x17C56B6B, 0x1A864DB2, 0x1E475005,
31 0x2608EDB8, 0x22C9F00F, 0x2F8AD6D6, 0x2B4BCB61,
32 0x350C9B64, 0x31CD86D3, 0x3C8EA00A, 0x384FBDBD
33 };
34
35 unsigned char byte;
36 unsigned t;
37
38 while (len--)
39 {
40 byte = *buf++; /* get one byte of data */
41
42 /* upper nibble of our data */
43 t = crc32 >> 28; /* extract the 4 most significant bits */
44 t ^= byte >> 4; /* XOR in 4 bits of data into the extracted bits */
45 crc32 <<= 4; /* shift the CRC register left 4 bits */
46 crc32 ^= crc32_lookup[t]; /* do the table lookup and XOR the result */
47
48 /* lower nibble of our data */
49 t = crc32 >> 28; /* extract the 4 most significant bits */
50 t ^= byte & 0x0F; /* XOR in 4 bits of data into the extracted bits */
51 crc32 <<= 4; /* shift the CRC register left 4 bits */
52 crc32 ^= crc32_lookup[t]; /* do the table lookup and XOR the result */
53 }
54
55 return crc32;
56}
57
diff --git a/firmware/include/crc32.h b/firmware/include/crc32.h
new file mode 100644
index 0000000000..5e998ab1b9
--- /dev/null
+++ b/firmware/include/crc32.h
@@ -0,0 +1,25 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2003 Jörg Hohensohn [IDC]Dragon
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#ifndef _CRC32_H
20#define _CRC32_H
21
22unsigned crc_32(unsigned char* buf, unsigned len, unsigned crc32);
23
24#endif
25