Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/net - Fix a bug in the double-loop version of ether_crc3...



details:   https://anonhg.NetBSD.org/src/rev/cfdca63e114c
branches:  trunk
changeset: 486063:cfdca63e114c
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Fri May 12 16:22:36 2000 +0000

description:
- Fix a bug in the double-loop version of ether_crc32_le() -- we're not't
  supposed to bubble carry through.
- Disable the double-loop version of ether_crc32_le() and add a
  table-driven version of ether_crc32_le() -- the table-driven
  version is faster.

diffstat:

 sys/net/if_ethersubr.c |  36 ++++++++++++++++++++++++++++++++++--
 1 files changed, 34 insertions(+), 2 deletions(-)

diffs (62 lines):

diff -r 3cb52920279b -r cfdca63e114c sys/net/if_ethersubr.c
--- a/sys/net/if_ethersubr.c    Fri May 12 15:25:25 2000 +0000
+++ b/sys/net/if_ethersubr.c    Fri May 12 16:22:36 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_ethersubr.c,v 1.55 2000/04/12 10:36:43 itojun Exp $ */
+/*     $NetBSD: if_ethersubr.c,v 1.56 2000/05/12 16:22:36 thorpej Exp $        */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -789,6 +789,12 @@
        /* Nothing. */
 }
 
+#if 0
+/*
+ * This is for reference.  We have a table-driven version
+ * of the little-endian crc32 generator, which is faster
+ * than the double-loop.
+ */
 u_int32_t
 ether_crc32_le(buf, len)
        const u_int8_t *buf;
@@ -806,12 +812,38 @@
                        crc >>= 1;
                        c >>= 1;
                        if (carry)
-                               crc = (crc ^ ETHER_CRC_POLY_LE) | carry;
+                               crc = (crc ^ ETHER_CRC_POLY_LE);
                }
        }
 
        return (crc);
 }
+#else
+u_int32_t
+ether_crc32_le(buf, len)
+       const u_int8_t *buf;
+       size_t len;
+{
+       static const u_int32_t crctab[] = {
+               0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac,
+               0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c,
+               0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c,
+               0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c
+       };
+       u_int32_t crc;
+       int i;
+
+       crc = 0xffffffffU;      /* initial value */
+
+       for (i = 0; i < len; i++) {
+               crc ^= buf[i];
+               crc = (crc >> 4) ^ crctab[crc & 0xf];
+               crc = (crc >> 4) ^ crctab[crc & 0xf];
+       }
+
+       return (crc);
+}
+#endif
 
 u_int32_t
 ether_crc32_be(buf, len)



Home | Main Index | Thread Index | Old Index