[U-Boot] [PATCH] crc32: minor cleanups and smaller size.
Joakim Tjernlund
Joakim.Tjernlund at transmode.se
Wed Nov 4 09:23:04 CET 2009
Don't optimize for len < 4. This reduces size with
8 bytes too.
This crc32 impl is smaller that the orginal if crc32
and crc32_no_comp is impl. two separate functions(like the orginal).
That would, however, be a waste of space when both are defined.
Signed-off-by: Joakim Tjernlund <Joakim.Tjernlund at transmode.se>
---
lib_generic/crc32.c | 44 +++++++++++++++++++++-----------------------
1 files changed, 21 insertions(+), 23 deletions(-)
diff --git a/lib_generic/crc32.c b/lib_generic/crc32.c
index 05b1431..737587a 100644
--- a/lib_generic/crc32.c
+++ b/lib_generic/crc32.c
@@ -14,6 +14,7 @@
#include <stdint.h>
#endif
#include <asm/byteorder.h>
+#include <u-boot/crc.h>
#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
#include <watchdog.h>
@@ -175,47 +176,44 @@ const uint32_t * ZEXPORT get_crc_table()
/* No ones complement version. JFFS2 (and other things ?)
* don't use ones compliment in their CRC calculations.
*/
-uint32_t ZEXPORT crc32_no_comp(uint32_t crc, const Bytef *p, uInt len)
+uint32_t ZEXPORT crc32_no_comp(uint32_t crc, const Bytef *buf, uInt len)
{
const uint32_t *tab = crc_table;
- const uint32_t *b =(uint32_t *)p;
-
+ const uint32_t *b =(uint32_t *)buf;
+ size_t save_len;
#ifdef DYNAMIC_CRC_TABLE
if (crc_table_empty)
make_crc_table();
#endif
crc = __cpu_to_le32(crc);
/* Align it */
- if(((long)b)&3 && len){
+ if(((long)b)&3 && len) {
do {
uint8_t *p = (uint8_t *)b;
DO_CRC(*p++);
b = (void *)p;
} while ((--len) && ((long)b)&3 );
}
- if(len >= 4){
+
+ save_len = len & 3;
+ len = len >> 2;
+ for (--b; len; --len) {
/* load data 32 bits wide, xor data 32 bits wide. */
- size_t save_len = len & 3;
- len = len >> 2;
- --b; /* use pre increment below(*++b) for speed */
- do {
- crc ^= *++b;
- DO_CRC(0);
- DO_CRC(0);
- DO_CRC(0);
- DO_CRC(0);
- } while (--len);
- b++; /* point to next byte(s) */
- len = save_len;
+ crc ^= *++b; /* use pre increment below(*++b) for speed */
+ DO_CRC(0);
+ DO_CRC(0);
+ DO_CRC(0);
+ DO_CRC(0);
}
+ b++; /* point to next byte(s) */
+ len = save_len;
/* And the last few bytes */
- if(len){
- do {
- uint8_t *p = (uint8_t *)b;
- DO_CRC(*p++);
- b = (void *)p;
- } while (--len);
+ for (; len; --len) {
+ uint8_t *p = (uint8_t *)b;
+ DO_CRC(*p++);
+ b = (void *)p;
}
+
return __le32_to_cpu(crc);
}
#undef DO_CRC
--
1.6.4.4
More information about the U-Boot
mailing list