patch-2.4.22 linux-2.4.22/include/asm-mips/checksum.h

Next file: linux-2.4.22/include/asm-mips/cobalt/cobalt.h
Previous file: linux-2.4.22/include/asm-mips/cacheops.h
Back to the patch index
Back to the overall index

diff -urN linux-2.4.21/include/asm-mips/checksum.h linux-2.4.22/include/asm-mips/checksum.h
@@ -92,49 +92,35 @@
  *	By Jorge Cwik <jorge@laser.satlink.net>, adapted for linux by
  *	Arnt Gulbrandsen.
  */
-static inline unsigned short ip_fast_csum(unsigned char *iph,
-					  unsigned int ihl)
+static inline unsigned short ip_fast_csum(unsigned char *iph, unsigned int ihl)
 {
-	unsigned int sum;
-	unsigned long dummy;
+	unsigned int *word = (unsigned int *) iph;
+	unsigned int *stop = word + ihl;
+	unsigned int csum;
+	int carry;
+
+	csum = word[0];
+	csum += word[1];
+	carry = (csum < word[1]);
+	csum += carry;
+
+	csum += word[2];
+	carry = (csum < word[2]);
+	csum += carry;
+
+	csum += word[3];
+	carry = (csum < word[3]);
+	csum += carry;
+
+	word += 4;
+	do {
+		csum += *word;
+		carry = (csum < *word);
+		csum += carry;
+		word++;
+	} while (word != stop);
 
-	/*
-	 * This is for 32-bit MIPS processors.
-	 */
-	__asm__ __volatile__(
-	".set\tnoreorder\t\t\t# ip_fast_csum\n\t"
-	".set\tnoat\n\t"
-	"lw\t%0, (%1)\n\t"
-	"subu\t%2, 4\n\t"
-	"#blez\t%2, 2f\n\t"
-	" sll\t%2, 2\n\t"
-	"lw\t%3, 4(%1)\n\t"
-	"addu\t%2, %1\n\t"
-	"addu\t%0, %3\n\t"
-	"sltu\t$1, %0, %3\n\t"
-	"lw\t%3, 8(%1)\n\t"
-	"addu\t%0, $1\n\t"
-	"addu\t%0, %3\n\t"
-	"sltu\t$1, %0, %3\n\t"
-	"lw\t%3, 12(%1)\n\t"
-	"addu\t%0, $1\n\t"
-	"addu\t%0, %3\n\t"
-	"sltu\t$1, %0, %3\n\t"
-	"addu\t%0, $1\n"
-
-	"1:\tlw\t%3, 16(%1)\n\t"
-	"addiu\t%1, 4\n\t"
-	"addu\t%0, %3\n\t"
-	"sltu\t$1, %0, %3\n\t"
-	"bne\t%2, %1, 1b\n\t"
-	" addu\t%0, $1\n"
-
-	"2:\t.set\tat\n\t"
-	".set\treorder"
-	: "=&r" (sum), "=&r" (iph), "=&r" (ihl), "=&r" (dummy)
-	: "1" (iph), "2" (ihl));
-
-	return csum_fold(sum);
+	return csum_fold(csum);
 }
 
 /*
@@ -203,7 +189,8 @@
 						     unsigned int sum)
 {
 	__asm__(
-	".set\tnoreorder\t\t\t# csum_ipv6_magic\n\t"
+	".set\tpush\t\t\t# csum_ipv6_magic\n\t"
+	".set\tnoreorder\n\t"
 	".set\tnoat\n\t"
 	"addu\t%0, %5\t\t\t# proto (long in network byte order)\n\t"
 	"sltu\t$1, %0, %5\n\t"
@@ -252,8 +239,7 @@
 	"sltu\t$1, %0, %1\n\t"
 
 	"addu\t%0, $1\t\t\t# Add final carry\n\t"
-	".set\tnoat\n\t"
-	".set\tnoreorder"
+	".set\tpop"
 	: "=r" (sum), "=r" (proto)
 	: "r" (saddr), "r" (daddr),
 	  "0" (htonl(len)), "1" (htonl(proto)), "r" (sum));

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)