summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiod Vallat <miod@cvs.openbsd.org>2008-02-16 23:02:42 +0000
committerMiod Vallat <miod@cvs.openbsd.org>2008-02-16 23:02:42 +0000
commit50ed81fe36b0ef7a13f2030708448de3b4c41c70 (patch)
tree8f6ef0e90d0619f4df2ad7cd52894b65f521059b
parent0592c29257083389b0b4302c8b2cd297359f071a (diff)
On these platforms, REDUCEing unconditionnaly a second time is faster and
shorter code than a conditional ADDCARRY, so use it; inspired by hppa.
-rw-r--r--sys/arch/m88k/m88k/in_cksum.c4
-rw-r--r--sys/arch/sparc/sparc/in_cksum.c6
2 files changed, 5 insertions, 5 deletions
diff --git a/sys/arch/m88k/m88k/in_cksum.c b/sys/arch/m88k/m88k/in_cksum.c
index 87fef1b7789..b5f3e652796 100644
--- a/sys/arch/m88k/m88k/in_cksum.c
+++ b/sys/arch/m88k/m88k/in_cksum.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: in_cksum.c,v 1.2 2005/05/05 14:28:34 miod Exp $ */
+/* $OpenBSD: in_cksum.c,v 1.3 2008/02/16 23:02:39 miod Exp $ */
/*
* Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -45,7 +45,7 @@
#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)
+#define ADDCARRY do { REDUCE; REDUCE; } while (0)
static __inline__ int
in_cksum_internal(struct mbuf *m, int off, int len, u_int sum)
diff --git a/sys/arch/sparc/sparc/in_cksum.c b/sys/arch/sparc/sparc/in_cksum.c
index 850e6eb42ea..deb192634b9 100644
--- a/sys/arch/sparc/sparc/in_cksum.c
+++ b/sys/arch/sparc/sparc/in_cksum.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: in_cksum.c,v 1.11 2005/05/03 00:39:39 brad Exp $ */
+/* $OpenBSD: in_cksum.c,v 1.12 2008/02/16 23:02:41 miod Exp $ */
/* $NetBSD: in_cksum.c,v 1.7 1996/10/05 23:44:34 mrg Exp $ */
/*
@@ -125,7 +125,6 @@
: "0" (sum), "r" (w))
#define REDUCE {sum = (sum & 0xffff) + (sum >> 16);}
-#define ADDCARRY {if (sum > 0xffff) sum -= 0xffff;}
#define ROL {sum = sum << 8;} /* depends on recent REDUCE */
#define ADDBYTE {ROL; sum += *w; byte_swapped ^= 1;}
#define ADDSHORT {sum += *(u_short *)w;}
@@ -212,8 +211,9 @@ in_cksum_internal(struct mbuf *m, int off, int len, u_int sum)
REDUCE;
ROL;
}
+ /* Two REDUCEs is faster than REDUCE1; if (sum > 65535) sum -= 65535; */
+ REDUCE;
REDUCE;
- ADDCARRY;
return (0xffff ^ sum);
}