All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joakim Tjernlund <Joakim.Tjernlund@transmode.se>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] crc32: minor cleanups and smaller size.
Date: Wed, 4 Nov 2009 09:23:04 +0100	[thread overview]
Message-ID: <1257322984-20533-1-git-send-email-Joakim.Tjernlund@transmode.se> (raw)

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@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

                 reply	other threads:[~2009-11-04  8:23 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1257322984-20533-1-git-send-email-Joakim.Tjernlund@transmode.se \
    --to=joakim.tjernlund@transmode.se \
    --cc=u-boot@lists.denx.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.