[parisc-linux-cvs] checksum.h patch
Helge Deller
deller@gmx.de
Sat, 12 May 2001 19:00:40 +0200
- The following patch simplyfies the csum_fold() instruction and will expand
to only 4 assembler statements in the new form instead of 8 assembler
instructions as before. So there is no need to convert this any longer to
inlined assembler, because a) we couldn't do any better and b) the compiler
will be able to schedule the assembler statements inside the caller code
better than us.
- csum_fold() should return an uint16 value which it now really does. In the
previous version the upper 16bits were 0xffff (ah, and why the heck isn't it
"unsigned __short__ csum_fold()" in all arches ????).
Index: checksum.h
===================================================================
RCS file: /home/cvs/parisc/linux/include/asm-parisc/checksum.h,v
retrieving revision 1.10
diff -u -r1.10 checksum.h
--- checksum.h 2001/04/26 05:01:59 1.10
+++ checksum.h 2001/05/12 16:45:22
@@ -98,9 +98,12 @@
*/
static inline unsigned int csum_fold(unsigned int sum)
{
- sum = (sum & 0xffff) + (sum >> 16);
- sum = (sum & 0xffff) + (sum >> 16);
- return ~sum;
+ /* add the swapped two 16-bit halves of sum,
+ a possible carry from adding the two 16-bit halves,
+ will carry from the lower half into the upper half,
+ giving us the correct sum in the upper half. */
+ sum += (sum << 16) + (sum >> 16);
+ return (~sum) >> 16;
}
static inline unsigned long csum_tcpudp_nofold(unsigned long saddr,