From cef3c93f82219b7dcf0922742c57cd611f27481c Mon Sep 17 00:00:00 2001 From: jdolecek Date: Thu, 6 Apr 2000 13:37:49 +0000 Subject: [PATCH] Switch to MI ns_cksum.c - the MD ns_cksum.c is equivalent to it (modulo some u_intX_t vs. u_char type usage). In particular, the MD version didn't contain any MD code. --- sys/arch/i386/conf/files.i386 | 16 ++- sys/arch/i386/i386/ns_cksum.c | 207 --------------------------------- sys/arch/m68k/conf/files.m68k | 4 +- sys/arch/m68k/m68k/ns_cksum.c | 207 --------------------------------- sys/arch/sh3/conf/files.sh3 | 4 +- sys/arch/sh3/sh3/ns_cksum.c | 208 ---------------------------------- 6 files changed, 15 insertions(+), 631 deletions(-) delete mode 100644 sys/arch/i386/i386/ns_cksum.c delete mode 100644 sys/arch/m68k/m68k/ns_cksum.c delete mode 100644 sys/arch/sh3/sh3/ns_cksum.c diff --git a/sys/arch/i386/conf/files.i386 b/sys/arch/i386/conf/files.i386 index c368792afbdf..081f630061d8 100644 --- a/sys/arch/i386/conf/files.i386 +++ b/sys/arch/i386/conf/files.i386 @@ -1,4 +1,4 @@ -# $NetBSD: files.i386,v 1.153 2000/03/26 15:36:49 martin Exp $ +# $NetBSD: files.i386,v 1.154 2000/04/06 13:37:50 jdolecek Exp $ # # new style config file for i386 architecture # @@ -60,7 +60,7 @@ file arch/i386/i386/machdep.c file arch/i386/i386/math_emulate.c math_emulate file arch/i386/i386/mem.c file arch/i386/i386/microtime.s -file arch/i386/i386/ns_cksum.c ns +file netns/ns_cksum.c ns file arch/i386/i386/pmap.c file arch/i386/i386/process_machdep.c file arch/i386/i386/sys_machdep.c @@ -108,12 +108,10 @@ file arch/i386/i386/bios32.c bios32 needs-flag define mainbus { } # XXX BIOS32 only if something that uses it is configured! -device mainbus: isabus, eisabus, pcibus, mainbus, bios32 +device mainbus: isabus, eisabus, mcabus, pcibus, mainbus, bios32 attach mainbus at root file arch/i386/i386/mainbus.c mainbus -#device mca at root {...} - # # PCI-only drivers # XXX MUST BE INCLUDED BEFORE files.isa, as long as files.isa attaches @@ -253,6 +251,14 @@ file arch/i386/isa/ahc_isa.c ahc_isa include "dev/eisa/files.eisa" file arch/i386/eisa/eisa_machdep.c eisa +# +# MCA-only drivers +# + +device mca {[slot = -1]} : bioscall +include "dev/mca/files.mca" +file arch/i386/mca/mca_machdep.c mca + # ISA Plug 'n Play devices file arch/i386/isa/isapnp_machdep.c isapnp diff --git a/sys/arch/i386/i386/ns_cksum.c b/sys/arch/i386/i386/ns_cksum.c deleted file mode 100644 index b979784ba059..000000000000 --- a/sys/arch/i386/i386/ns_cksum.c +++ /dev/null @@ -1,207 +0,0 @@ -/* $NetBSD: ns_cksum.c,v 1.5 1996/05/03 19:42:20 christos Exp $ */ - -/* - * Copyright (c) 1982, 1988 Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)ns_cksum.c 7.7 (Berkeley) 4/29/91 - */ - -#include -#include -#include - -/* - * Checksum routine for Network Systems Protocol Packets (Big-Endian). - * - * This routine is very heavily used in the network - * code and should be modified for each CPU to be as fast as possible. - */ - -#define ADDCARRY(x) { if ((x) > 65535) (x) -= 65535; } -#define FOLD(x) {l_util.l = (x); (x) = l_util.s[0] + l_util.s[1]; ADDCARRY(x);} - -u_short -ns_cksum(m, len) - register struct mbuf *m; - register int len; -{ - register u_short *w; - register int sum = 0; - register int mlen = 0; - register int sum2; - - union { - u_short s[2]; - long l; - } l_util; - - for (;m && len; m = m->m_next) { - if (m->m_len == 0) - continue; - /* - * Each trip around loop adds in - * word from one mbuf segment. - */ - w = mtod(m, u_short *); - if (mlen == -1) { - /* - * There is a byte left from the last segment; - * ones-complement add it into the checksum. - */ -#if BYTE_ORDER == BIG_ENDIAN - sum += *(u_char *)w; -#else - sum += *(u_char *)w << 8; -#endif - sum += sum; - w = (u_short *)(1 + (char *)w); - mlen = m->m_len - 1; - len--; - FOLD(sum); - } else - mlen = m->m_len; - if (len < mlen) - mlen = len; - len -= mlen; - /* - * We can do a 16 bit ones complement sum using - * 32 bit arithmetic registers for adding, - * with carries from the low added - * into the high (by normal carry-chaining) - * so long as we fold back before 16 carries have occured. - */ - if (1 & (int) w) - goto uuuuglyy; -#ifndef TINY -/* -DTINY reduces the size from 1250 to 550, but slows it down by 22% */ - while ((mlen -= 32) >= 0) { - sum += w[0]; sum += sum; sum += w[1]; sum += sum; - sum += w[2]; sum += sum; sum += w[3]; sum += sum; - sum += w[4]; sum += sum; sum += w[5]; sum += sum; - sum += w[6]; sum += sum; sum += w[7]; sum += sum; - FOLD(sum); - sum += w[8]; sum += sum; sum += w[9]; sum += sum; - sum += w[10]; sum += sum; sum += w[11]; sum += sum; - sum += w[12]; sum += sum; sum += w[13]; sum += sum; - sum += w[14]; sum += sum; sum += w[15]; sum += sum; - FOLD(sum); - w += 16; - } - mlen += 32; -#endif - while ((mlen -= 8) >= 0) { - sum += w[0]; sum += sum; sum += w[1]; sum += sum; - sum += w[2]; sum += sum; sum += w[3]; sum += sum; - FOLD(sum); - w += 4; - } - mlen += 8; - while ((mlen -= 2) >= 0) { - sum += *w++; sum += sum; - } - goto commoncase; -uuuuglyy: -#if BYTE_ORDER == BIG_ENDIAN -#define ww(n) (((u_char *)w)[n + n + 1]) -#define vv(n) (((u_char *)w)[n + n]) -#else -#if BYTE_ORDER == LITTLE_ENDIAN -#define vv(n) (((u_char *)w)[n + n + 1]) -#define ww(n) (((u_char *)w)[n + n]) -#endif -#endif - sum2 = 0; -#ifndef TINY - while ((mlen -= 32) >= 0) { - sum += ww(0); sum += sum; sum += ww(1); sum += sum; - sum += ww(2); sum += sum; sum += ww(3); sum += sum; - sum += ww(4); sum += sum; sum += ww(5); sum += sum; - sum += ww(6); sum += sum; sum += ww(7); sum += sum; - FOLD(sum); - sum += ww(8); sum += sum; sum += ww(9); sum += sum; - sum += ww(10); sum += sum; sum += ww(11); sum += sum; - sum += ww(12); sum += sum; sum += ww(13); sum += sum; - sum += ww(14); sum += sum; sum += ww(15); sum += sum; - FOLD(sum); - sum2 += vv(0); sum2 += sum2; sum2 += vv(1); sum2 += sum2; - sum2 += vv(2); sum2 += sum2; sum2 += vv(3); sum2 += sum2; - sum2 += vv(4); sum2 += sum2; sum2 += vv(5); sum2 += sum2; - sum2 += vv(6); sum2 += sum2; sum2 += vv(7); sum2 += sum2; - FOLD(sum2); - sum2 += vv(8); sum2 += sum2; sum2 += vv(9); sum2 += sum2; - sum2 += vv(10); sum2 += sum2; sum2 += vv(11); sum2 += sum2; - sum2 += vv(12); sum2 += sum2; sum2 += vv(13); sum2 += sum2; - sum2 += vv(14); sum2 += sum2; sum2 += vv(15); sum2 += sum2; - FOLD(sum2); - w += 16; - } - mlen += 32; -#endif - while ((mlen -= 8) >= 0) { - sum += ww(0); sum += sum; sum += ww(1); sum += sum; - sum += ww(2); sum += sum; sum += ww(3); sum += sum; - FOLD(sum); - sum2 += vv(0); sum2 += sum2; sum2 += vv(1); sum2 += sum2; - sum2 += vv(2); sum2 += sum2; sum2 += vv(3); sum2 += sum2; - FOLD(sum2); - w += 4; - } - mlen += 8; - while ((mlen -= 2) >= 0) { - sum += ww(0); sum += sum; - sum2 += vv(0); sum2 += sum2; - w++; - } - sum += (sum2 << 8); -commoncase: - if (mlen == -1) { -#if BYTE_ORDER == BIG_ENDIAN - sum += *(u_char *)w << 8; -#else - sum += *(u_char *)w; -#endif - } - FOLD(sum); - } - if (mlen == -1) { - /* We had an odd number of bytes to sum; assume a garbage - byte of zero and clean up */ - sum += sum; - FOLD(sum); - } - /* - * sum has already been kept to low sixteen bits. - * just examine result and exit. - */ - if(sum==0xffff) sum = 0; - return (sum); -} diff --git a/sys/arch/m68k/conf/files.m68k b/sys/arch/m68k/conf/files.m68k index 1399665cccef..0976b5524014 100644 --- a/sys/arch/m68k/conf/files.m68k +++ b/sys/arch/m68k/conf/files.m68k @@ -1,4 +1,4 @@ -# $NetBSD: files.m68k,v 1.27 2000/02/14 21:42:52 thorpej Exp $ +# $NetBSD: files.m68k,v 1.28 2000/04/06 13:37:50 jdolecek Exp $ # file arch/m68k/m68k/bcopy.s file arch/m68k/m68k/copy.s @@ -11,7 +11,7 @@ file netinet/in4_cksum.c inet file arch/m68k/m68k/kgdb_m68k.c kgdb file arch/m68k/m68k/m68k_machdep.c file arch/m68k/m68k/mappedcopy.c mappedcopy -file arch/m68k/m68k/ns_cksum.c ns +file netns/ns_cksum.c ns file arch/m68k/m68k/oc_cksum.s inet file arch/m68k/m68k/process_machdep.c file arch/m68k/m68k/regdump.c diff --git a/sys/arch/m68k/m68k/ns_cksum.c b/sys/arch/m68k/m68k/ns_cksum.c deleted file mode 100644 index 29aa42ef4f82..000000000000 --- a/sys/arch/m68k/m68k/ns_cksum.c +++ /dev/null @@ -1,207 +0,0 @@ -/* $NetBSD: ns_cksum.c,v 1.5 1996/04/01 01:38:15 briggs Exp $ */ - -/* - * Copyright (c) 1982, 1988 Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)ns_cksum.c 7.7 (Berkeley) 4/29/91 - */ - -#include -#include -#include - -/* - * Checksum routine for Network Systems Protocol Packets (Big-Endian). - * - * This routine is very heavily used in the network - * code and should be modified for each CPU to be as fast as possible. - */ - -#define ADDCARRY(x) { if ((x) > 65535) (x) -= 65535; } -#define FOLD(x) {l_util.l = (x); (x) = l_util.s[0] + l_util.s[1]; ADDCARRY(x);} - -u_short -ns_cksum(m, len) - register struct mbuf *m; - register int len; -{ - register u_short *w; - register int sum = 0; - register int mlen = 0; - register int sum2; - - union { - u_short s[2]; - long l; - } l_util; - - for (;m && len; m = m->m_next) { - if (m->m_len == 0) - continue; - /* - * Each trip around loop adds in - * word from one mbuf segment. - */ - w = mtod(m, u_short *); - if (mlen == -1) { - /* - * There is a byte left from the last segment; - * ones-complement add it into the checksum. - */ -#if BYTE_ORDER == BIG_ENDIAN - sum += *(u_char *)w; -#else - sum += *(u_char *)w << 8; -#endif - sum += sum; - w = (u_short *)(1 + (char *)w); - mlen = m->m_len - 1; - len--; - FOLD(sum); - } else - mlen = m->m_len; - if (len < mlen) - mlen = len; - len -= mlen; - /* - * We can do a 16 bit ones complement sum using - * 32 bit arithmetic registers for adding, - * with carries from the low added - * into the high (by normal carry-chaining) - * so long as we fold back before 16 carries have occured. - */ - if (1 & (int) w) - goto uuuuglyy; -#ifndef TINY -/* -DTINY reduces the size from 1250 to 550, but slows it down by 22% */ - while ((mlen -= 32) >= 0) { - sum += w[0]; sum += sum; sum += w[1]; sum += sum; - sum += w[2]; sum += sum; sum += w[3]; sum += sum; - sum += w[4]; sum += sum; sum += w[5]; sum += sum; - sum += w[6]; sum += sum; sum += w[7]; sum += sum; - FOLD(sum); - sum += w[8]; sum += sum; sum += w[9]; sum += sum; - sum += w[10]; sum += sum; sum += w[11]; sum += sum; - sum += w[12]; sum += sum; sum += w[13]; sum += sum; - sum += w[14]; sum += sum; sum += w[15]; sum += sum; - FOLD(sum); - w += 16; - } - mlen += 32; -#endif - while ((mlen -= 8) >= 0) { - sum += w[0]; sum += sum; sum += w[1]; sum += sum; - sum += w[2]; sum += sum; sum += w[3]; sum += sum; - FOLD(sum); - w += 4; - } - mlen += 8; - while ((mlen -= 2) >= 0) { - sum += *w++; sum += sum; - } - goto commoncase; -uuuuglyy: -#if BYTE_ORDER == BIG_ENDIAN -#define ww(n) (((u_char *)w)[n + n + 1]) -#define vv(n) (((u_char *)w)[n + n]) -#else -#if BYTE_ORDER == LITTLE_ENDIAN -#define vv(n) (((u_char *)w)[n + n + 1]) -#define ww(n) (((u_char *)w)[n + n]) -#endif -#endif - sum2 = 0; -#ifndef TINY - while ((mlen -= 32) >= 0) { - sum += ww(0); sum += sum; sum += ww(1); sum += sum; - sum += ww(2); sum += sum; sum += ww(3); sum += sum; - sum += ww(4); sum += sum; sum += ww(5); sum += sum; - sum += ww(6); sum += sum; sum += ww(7); sum += sum; - FOLD(sum); - sum += ww(8); sum += sum; sum += ww(9); sum += sum; - sum += ww(10); sum += sum; sum += ww(11); sum += sum; - sum += ww(12); sum += sum; sum += ww(13); sum += sum; - sum += ww(14); sum += sum; sum += ww(15); sum += sum; - FOLD(sum); - sum2 += vv(0); sum2 += sum2; sum2 += vv(1); sum2 += sum2; - sum2 += vv(2); sum2 += sum2; sum2 += vv(3); sum2 += sum2; - sum2 += vv(4); sum2 += sum2; sum2 += vv(5); sum2 += sum2; - sum2 += vv(6); sum2 += sum2; sum2 += vv(7); sum2 += sum2; - FOLD(sum2); - sum2 += vv(8); sum2 += sum2; sum2 += vv(9); sum2 += sum2; - sum2 += vv(10); sum2 += sum2; sum2 += vv(11); sum2 += sum2; - sum2 += vv(12); sum2 += sum2; sum2 += vv(13); sum2 += sum2; - sum2 += vv(14); sum2 += sum2; sum2 += vv(15); sum2 += sum2; - FOLD(sum2); - w += 16; - } - mlen += 32; -#endif - while ((mlen -= 8) >= 0) { - sum += ww(0); sum += sum; sum += ww(1); sum += sum; - sum += ww(2); sum += sum; sum += ww(3); sum += sum; - FOLD(sum); - sum2 += vv(0); sum2 += sum2; sum2 += vv(1); sum2 += sum2; - sum2 += vv(2); sum2 += sum2; sum2 += vv(3); sum2 += sum2; - FOLD(sum2); - w += 4; - } - mlen += 8; - while ((mlen -= 2) >= 0) { - sum += ww(0); sum += sum; - sum2 += vv(0); sum2 += sum2; - w++; - } - sum += (sum2 << 8); -commoncase: - if (mlen == -1) { -#if BYTE_ORDER == BIG_ENDIAN - sum += *(u_char *)w << 8; -#else - sum += *(u_char *)w; -#endif - } - FOLD(sum); - } - if (mlen == -1) { - /* We had an odd number of bytes to sum; assume a garbage - byte of zero and clean up */ - sum += sum; - FOLD(sum); - } - /* - * sum has already been kept to low sixteen bits. - * just examine result and exit. - */ - if(sum==0xffff) sum = 0; - return (sum); -} diff --git a/sys/arch/sh3/conf/files.sh3 b/sys/arch/sh3/conf/files.sh3 index 486739384b93..78b5ee3fd013 100644 --- a/sys/arch/sh3/conf/files.sh3 +++ b/sys/arch/sh3/conf/files.sh3 @@ -1,4 +1,4 @@ -# $NetBSD: files.sh3,v 1.7 2000/02/14 21:42:53 thorpej Exp $ +# $NetBSD: files.sh3,v 1.8 2000/04/06 13:37:50 jdolecek Exp $ # # new style config file for sh3 architecture # @@ -23,7 +23,7 @@ file arch/sh3/sh3/kgdb_machdep.c kgdb file arch/sh3/sh3/Locore.c file arch/sh3/sh3/math_emulate.c math_emulate file arch/sh3/sh3/mem.c -file arch/sh3/sh3/ns_cksum.c ns +file netns/ns_cksum.c ns file arch/sh3/sh3/pmap.c file arch/sh3/sh3/process_machdep.c file arch/sh3/sh3/sh3_machdep.c diff --git a/sys/arch/sh3/sh3/ns_cksum.c b/sys/arch/sh3/sh3/ns_cksum.c deleted file mode 100644 index ce78d714893c..000000000000 --- a/sys/arch/sh3/sh3/ns_cksum.c +++ /dev/null @@ -1,208 +0,0 @@ -/* $NetBSD: ns_cksum.c,v 1.1 1999/09/13 10:31:30 itojun Exp $ */ - -/* - * Copyright (c) 1982, 1988 Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)ns_cksum.c 7.7 (Berkeley) 4/29/91 - */ - -#include -#include -#include - -/* - * Checksum routine for Network Systems Protocol Packets (Big-Endian). - * - * This routine is very heavily used in the network - * code and should be modified for each CPU to be as fast as possible. - */ - -#define ADDCARRY(x) { if ((x) > 65535) (x) -= 65535; } -#define FOLD(x) {l_util.l = (x); (x) = l_util.s[0] + l_util.s[1]; ADDCARRY(x);} - -u_short -ns_cksum(m, len) - register struct mbuf *m; - register int len; -{ - register u_short *w; - register int sum = 0; - register int mlen = 0; - register int sum2; - - union { - u_short s[2]; - long l; - } l_util; - - for (;m && len; m = m->m_next) { - if (m->m_len == 0) - continue; - /* - * Each trip around loop adds in - * word from one mbuf segment. - */ - w = mtod(m, u_short *); - if (mlen == -1) { - /* - * There is a byte left from the last segment; - * ones-complement add it into the checksum. - */ -#if BYTE_ORDER == BIG_ENDIAN - sum += *(u_char *)w; -#else - sum += *(u_char *)w << 8; -#endif - sum += sum; - w = (u_short *)(1 + (char *)w); - mlen = m->m_len - 1; - len--; - FOLD(sum); - } else - mlen = m->m_len; - if (len < mlen) - mlen = len; - len -= mlen; - /* - * We can do a 16 bit ones complement sum using - * 32 bit arithmetic registers for adding, - * with carries from the low added - * into the high (by normal carry-chaining) - * so long as we fold back before 16 carries have occured. - */ - if (1 & (int) w) - goto uuuuglyy; -#ifndef TINY -/* -DTINY reduces the size from 1250 to 550, but slows it down by 22% */ - while ((mlen -= 32) >= 0) { - sum += w[0]; sum += sum; sum += w[1]; sum += sum; - sum += w[2]; sum += sum; sum += w[3]; sum += sum; - sum += w[4]; sum += sum; sum += w[5]; sum += sum; - sum += w[6]; sum += sum; sum += w[7]; sum += sum; - FOLD(sum); - sum += w[8]; sum += sum; sum += w[9]; sum += sum; - sum += w[10]; sum += sum; sum += w[11]; sum += sum; - sum += w[12]; sum += sum; sum += w[13]; sum += sum; - sum += w[14]; sum += sum; sum += w[15]; sum += sum; - FOLD(sum); - w += 16; - } - mlen += 32; -#endif - while ((mlen -= 8) >= 0) { - sum += w[0]; sum += sum; sum += w[1]; sum += sum; - sum += w[2]; sum += sum; sum += w[3]; sum += sum; - FOLD(sum); - w += 4; - } - mlen += 8; - while ((mlen -= 2) >= 0) { - sum += *w++; sum += sum; - } - goto commoncase; -uuuuglyy: -#if BYTE_ORDER == BIG_ENDIAN -#define ww(n) (((u_char *)w)[n + n + 1]) -#define vv(n) (((u_char *)w)[n + n]) -#else -#if BYTE_ORDER == LITTLE_ENDIAN -#define vv(n) (((u_char *)w)[n + n + 1]) -#define ww(n) (((u_char *)w)[n + n]) -#endif -#endif - sum2 = 0; -#ifndef TINY - while ((mlen -= 32) >= 0) { - sum += ww(0); sum += sum; sum += ww(1); sum += sum; - sum += ww(2); sum += sum; sum += ww(3); sum += sum; - sum += ww(4); sum += sum; sum += ww(5); sum += sum; - sum += ww(6); sum += sum; sum += ww(7); sum += sum; - FOLD(sum); - sum += ww(8); sum += sum; sum += ww(9); sum += sum; - sum += ww(10); sum += sum; sum += ww(11); sum += sum; - sum += ww(12); sum += sum; sum += ww(13); sum += sum; - sum += ww(14); sum += sum; sum += ww(15); sum += sum; - FOLD(sum); - sum2 += vv(0); sum2 += sum2; sum2 += vv(1); sum2 += sum2; - sum2 += vv(2); sum2 += sum2; sum2 += vv(3); sum2 += sum2; - sum2 += vv(4); sum2 += sum2; sum2 += vv(5); sum2 += sum2; - sum2 += vv(6); sum2 += sum2; sum2 += vv(7); sum2 += sum2; - FOLD(sum2); - sum2 += vv(8); sum2 += sum2; sum2 += vv(9); sum2 += sum2; - sum2 += vv(10); sum2 += sum2; sum2 += vv(11); sum2 += sum2; - sum2 += vv(12); sum2 += sum2; sum2 += vv(13); sum2 += sum2; - sum2 += vv(14); sum2 += sum2; sum2 += vv(15); sum2 += sum2; - FOLD(sum2); - w += 16; - } - mlen += 32; -#endif - while ((mlen -= 8) >= 0) { - sum += ww(0); sum += sum; sum += ww(1); sum += sum; - sum += ww(2); sum += sum; sum += ww(3); sum += sum; - FOLD(sum); - sum2 += vv(0); sum2 += sum2; sum2 += vv(1); sum2 += sum2; - sum2 += vv(2); sum2 += sum2; sum2 += vv(3); sum2 += sum2; - FOLD(sum2); - w += 4; - } - mlen += 8; - while ((mlen -= 2) >= 0) { - sum += ww(0); sum += sum; - sum2 += vv(0); sum2 += sum2; - w++; - } - sum += (sum2 << 8); -commoncase: - if (mlen == -1) { -#if BYTE_ORDER == BIG_ENDIAN - sum += *(u_char *)w << 8; -#else - sum += *(u_char *)w; -#endif - } - FOLD(sum); - } - if (mlen == -1) { - /* We had an odd number of bytes to sum; assume a garbage - byte of zero and clean up */ - sum += sum; - FOLD(sum); - } - /* - * sum has already been kept to low sixteen bits. - * just examine result and exit. - */ - if (sum == 0xffff) - sum = 0; - return (sum); -}