summaryrefslogtreecommitdiff
path: root/sys/arch
diff options
context:
space:
mode:
authorMiod Vallat <miod@cvs.openbsd.org>2005-05-04 22:31:49 +0000
committerMiod Vallat <miod@cvs.openbsd.org>2005-05-04 22:31:49 +0000
commit91453e10e7fc3a4454b8898fde59df8c10eebf3b (patch)
treeef675a3c5641dbd7be95286f26cf940bb481a149 /sys/arch
parent74525f1395a4c5a063c21132c219ed5b4b2f4471 (diff)
Switch m88k to a faster in_cksum implementation, the original 100%-C powerpc
version. The optimizer does a very good job on this, and there is nothing left to optimize in the generated output...
Diffstat (limited to 'sys/arch')
-rw-r--r--sys/arch/m88k/conf/files.m88k4
-rw-r--r--sys/arch/m88k/m88k/in_cksum.c83
2 files changed, 85 insertions, 2 deletions
diff --git a/sys/arch/m88k/conf/files.m88k b/sys/arch/m88k/conf/files.m88k
index 745ebcc2cdc..e4231cb22d4 100644
--- a/sys/arch/m88k/conf/files.m88k
+++ b/sys/arch/m88k/conf/files.m88k
@@ -1,9 +1,10 @@
-# $OpenBSD: files.m88k,v 1.10 2005/05/01 21:36:56 brad Exp $
+# $OpenBSD: files.m88k,v 1.11 2005/05/04 22:31:46 miod Exp $
file arch/m88k/m88k/cmmu.c
file arch/m88k/m88k/db_disasm.c ddb
file arch/m88k/m88k/db_sstep.c ddb
file arch/m88k/m88k/db_trace.c ddb
+file arch/m88k/m88k/in_cksum.c inet
file arch/m88k/m88k/m88100_fp.S m88100
file arch/m88k/m88k/m88100_machdep.c m88100
file arch/m88k/m88k/m88110_fp.S m88110
@@ -20,6 +21,5 @@ file arch/m88k/m88k/vectors_88100.S m88100
file arch/m88k/m88k/vectors_88110.S m88110
file arch/m88k/m88k/vm_machdep.c
-file netinet/in_cksum.c inet
file netinet/in4_cksum.c inet
file netns/ns_cksum.c ns
diff --git a/sys/arch/m88k/m88k/in_cksum.c b/sys/arch/m88k/m88k/in_cksum.c
new file mode 100644
index 00000000000..005f903307a
--- /dev/null
+++ b/sys/arch/m88k/m88k/in_cksum.c
@@ -0,0 +1,83 @@
+/* $OpenBSD: in_cksum.c,v 1.1 2005/05/04 22:31:48 miod Exp $ */
+
+/*
+ * Copyright (C) 1995, 1996 Wolfgang Solfrank.
+ * Copyright (C) 1995, 1996 TooLs GmbH.
+ * 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 TooLs GmbH.
+ * 4. The name of TooLs GmbH may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``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 TOOLS GMBH 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.
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/mbuf.h>
+#include <netinet/in.h>
+
+#define REDUCE (sum = (sum & 0xffff) + (sum >> 16))
+#define ROL (sum <<= 8)
+#define ADDB (ROL, sum += *w, byte_swapped ^= 1)
+#define ADDS (sum += *(u_short *)w)
+#define SHIFT(n) (w += (n), mlen -= (n))
+#define ADDCARRY do { while (sum > 0xffff) REDUCE; } while (0)
+
+int
+in_cksum(struct mbuf *m, int len)
+{
+ u_char *w;
+ u_int sum = 0;
+ int mlen;
+ int byte_swapped = 0;
+
+ register_t tmp;
+
+ for (; m && len; m = m->m_next) {
+ if (m->m_len == 0)
+ continue;
+ w = mtod(m, u_char *);
+ mlen = m->m_len;
+ if (len < mlen)
+ mlen = len;
+ len -= mlen;
+ if ((long)w & 1) {
+ REDUCE;
+ ADDB;
+ SHIFT(1);
+ }
+ while (mlen >= 2) {
+ ADDS;
+ SHIFT(2);
+ }
+ REDUCE;
+ if (mlen == 1)
+ ADDB;
+ }
+ if (byte_swapped) {
+ REDUCE;
+ ROL;
+ }
+ ADDCARRY;
+ return (0xffff ^ sum);
+}