patch-1.3.98 linux/include/asm-i386/checksum.h
Next file: linux/include/asm-i386/fcntl.h
Previous file: linux/include/asm-alpha/fcntl.h
Back to the patch index
Back to the overall index
- Lines: 96
- Date:
Thu May 2 06:44:19 1996
- Orig file:
v1.3.97/linux/include/asm-i386/checksum.h
- Orig date:
Tue Oct 3 11:45:59 1995
diff -u --recursive --new-file v1.3.97/linux/include/asm-i386/checksum.h linux/include/asm-i386/checksum.h
@@ -65,14 +65,30 @@
notl %0
2:
"
- : "=&r" (sum), "=&r" (iph), "=&r" (ihl)
+ /* Since the input registers which are loaded with iph and ipl
+ are modified, we must also specify them as outputs, or gcc
+ will assume they contain their original values. */
+ : "=r" (sum), "=r" (iph), "=r" (ihl)
: "1" (iph), "2" (ihl));
return(sum);
}
+/*
+ * Fold a partial checksum
+ */
-
-
+static inline unsigned int csum_fold(unsigned int sum)
+{
+ __asm__("
+ addl %1, %0
+ adcl $0xffff, %0
+ "
+ : "=r" (sum)
+ : "r" (sum << 16), "0" (sum & 0xffff0000)
+ );
+ return (~sum) >> 16;
+}
+
/*
* computes the checksum of the TCP/UDP pseudo-header
* returns a 16-bit checksum, already complemented
@@ -85,55 +101,21 @@
unsigned int sum) {
__asm__("
addl %1, %0
- adcl %4, %0
- adcl %5, %0
- adcl $0, %0
- movl %0, %1
- shrl $16, %1
- addw %w1, %w0
+ adcl %2, %0
+ adcl %3, %0
adcl $0, %0
- notl %0
"
- : "=&r" (sum), "=&r" (saddr)
- : "0" (daddr), "1"(saddr), "r"((ntohs(len)<<16)+proto*256), "r"(sum));
- return((unsigned short)sum);
-}
-
-/*
- * Fold a partial checksum without adding pseudo headers
- */
-
-static inline unsigned int csum_fold(unsigned int sum)
-{
- __asm__("
- addl %1, %0
- adcl $0xffff, %0
- "
- : "=r" (sum)
- : "r" (sum << 16), "0" (sum & 0xffff0000)
- );
- return (~sum) >> 16;
+ : "=r" (sum)
+ : "g" (daddr), "g"(saddr), "g"((ntohs(len)<<16)+proto*256), "0"(sum));
+ return csum_fold(sum);
}
-
/*
* this routine is used for miscellaneous IP-like checksums, mainly
* in icmp.c
*/
static inline unsigned short ip_compute_csum(unsigned char * buff, int len) {
- unsigned int sum;
-
- unsigned int scratch;
- __asm__("
- movl %0, %1
- shrl $16, %1
- addw %w1, %w0
- adcl $0, %0
- notl %0
- "
- : "=a"(sum), "=r" (scratch)
- : "0" (csum_partial(buff, len, 0)));
- return(sum);
+ return csum_fold (csum_partial(buff, len, 0));
}
#endif
FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov
with Sam's (original) version of this