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.
29 * computes a partial checksum, e.g. for TCP/UDP fragments
33 unsigned int csum_partial(const unsigned char * buff, int len, unsigned int sum)
40 #ifndef CONFIG_X86_USE_PPRO_CHECKSUM
43 * Experiments with Ethernet and SLIP connections show that buff
44 * is aligned on either a 2-byte or 4-byte boundary. We get at
45 * least a twofold speedup on 486 and Pentium if it is 4-byte aligned.
46 * Fortunately, it is easy to convert 2-byte alignment to 4-byte
47 * alignment for the unrolled loop.
52 movl 20(%esp),%eax # Function arg: unsigned int sum
53 movl 16(%esp),%ecx # Function arg: int len
54 movl 12(%esp),%esi # Function arg: unsigned char *buff
55 testl $3, %esi # Check alignment.
56 jz 2f # Jump if alignment is ok.
57 testl $1, %esi # Check alignment.
58 jz 10f # Jump if alignment is boundary of 2bytes.
70 subl $2, %ecx # Alignment uses up two bytes.
71 jae 1f # Jump if we had at least two bytes.
72 addl $2, %ecx # ecx was < 2. Deal with it.
106 shrl $2, %edx # This clears CF
134 /* Version for PentiumII/PPro */
139 movl 20(%esp),%eax # Function arg: unsigned int sum
140 movl 16(%esp),%ecx # Function arg: int len
141 movl 12(%esp),%esi # Function arg: const unsigned char *buf
153 lea 45f(%ebx,%ebx,2), %ebx
157 # Handle 2-byte-aligned regions
181 movzbl (%esi),%ebx # csumming 1 byte, 2-aligned
186 addw (%esi), %ax # csumming 2 bytes, 2-aligned
191 addl -128(%esi), %eax
192 adcl -124(%esi), %eax
193 adcl -120(%esi), %eax
194 adcl -116(%esi), %eax
195 adcl -112(%esi), %eax
196 adcl -108(%esi), %eax
197 adcl -104(%esi), %eax
198 adcl -100(%esi), %eax
232 # Handle the last 1-3 bytes without jumping
233 notl %ecx # 1->2, 2->1, 3->0, higher bits are masked
234 movl $0xffffff,%ebx # by the shll and shrl instructions
237 andl -128(%esi),%ebx # esi is 4-aligned so should be ok