2 * INET An implementation of the TCP/IP protocol suite for the LINUX
3 * operating system. INET is implemented using the BSD Socket
4 * interface as the means of communication with the user level.
6 * IP/TCP/UDP checksumming routines
8 * Authors: Jorge Cwik, <jorge@laser.satlink.net>
9 * Arnt Gulbrandsen, <agulbra@nvg.unit.no>
10 * Tom May, <ftom@netcom.com>
11 * Pentium Pro/II routines:
12 * Alexander Kjeldaas <astor@guardian.no>
13 * Finn Arne Gangstad <finnag@guardian.no>
14 * Lots of code moved from tcp.c and ip.c; see those files
17 * Changes: Ingo Molnar, converted csum_partial_copy() to 2.1 exception
19 * Andi Kleen, add zeroing on error
20 * converted to pure assembler
22 * This program is free software; you can redistribute it and/or
23 * modify it under the terms of the GNU General Public License
24 * as published by the Free Software Foundation; either version
25 * 2 of the License, or (at your option) any later version.
28 #include <asm/errno.h>
30 #include <asm/export.h>
33 * computes a partial checksum, e.g. for TCP/UDP fragments
37 unsigned int csum_partial(const unsigned char * buff, int len, unsigned int sum)
44 #ifndef CONFIG_X86_USE_PPRO_CHECKSUM
47 * Experiments with Ethernet and SLIP connections show that buff
48 * is aligned on either a 2-byte or 4-byte boundary. We get at
49 * least a twofold speedup on 486 and Pentium if it is 4-byte aligned.
50 * Fortunately, it is easy to convert 2-byte alignment to 4-byte
51 * alignment for the unrolled loop.
56 movl 20(%esp),%eax # Function arg: unsigned int sum
57 movl 16(%esp),%ecx # Function arg: int len
58 movl 12(%esp),%esi # Function arg: unsigned char *buff
59 testl $2, %esi # Check alignment.
60 jz 2f # Jump if alignment is ok.
61 subl $2, %ecx # Alignment uses up two bytes.
62 jae 1f # Jump if we had at least two bytes.
63 addl $2, %ecx # ecx was < 2. Deal with it.
97 shrl $2, %edx # This clears CF
121 /* Version for PentiumII/PPro */
126 movl 20(%esp),%eax # Function arg: unsigned int sum
127 movl 16(%esp),%ecx # Function arg: int len
128 movl 12(%esp),%esi # Function arg: const unsigned char *buf
140 lea 45f(%ebx,%ebx,2), %ebx
144 # Handle 2-byte-aligned regions
153 movzbl (%esi),%ebx # csumming 1 byte, 2-aligned
158 addw (%esi), %ax # csumming 2 bytes, 2-aligned
163 addl -128(%esi), %eax
164 adcl -124(%esi), %eax
165 adcl -120(%esi), %eax
166 adcl -116(%esi), %eax
167 adcl -112(%esi), %eax
168 adcl -108(%esi), %eax
169 adcl -104(%esi), %eax
170 adcl -100(%esi), %eax
204 # Handle the last 1-3 bytes without jumping
205 notl %ecx # 1->2, 2->1, 3->0, higher bits are masked
206 movl $0xffffff,%ebx # by the shll and shrl instructions
209 andl -128(%esi),%ebx # esi is 4-aligned so should be ok
218 EXPORT_SYMBOL(csum_partial)