2 * Optmized version of the ip_fast_csum() function
3 * Used for calculating IP header checksum
5 * Return: 16bit checksum, complemented
8 * in0: address of buffer to checksum (char *)
9 * in1: length of the buffer (int)
11 * Copyright (C) 2002, 2006 Intel Corp.
12 * Copyright (C) 2002, 2006 Ken Chen <kenneth.w.chen@intel.com>
15 #include <asm/asmmacro.h>
18 * Since we know that most likely this function is called with buf aligned
19 * on 4-byte boundary and 20 bytes in length, we can execution rather quickly
20 * versus calling generic version of do_csum, which has lots of overhead in
21 * handling various alignments and sizes. However, due to lack of constrains
22 * put on the function input argument, cases with alignment not on 4-byte or
23 * size not equal to 20 bytes will be handled by the generic do_csum function.
33 GLOBAL_ENTRY(ip_fast_csum)
36 cmp.ne p6,p7=5,in1 // size other than 20 byte?
37 and r14=3,in0 // is it aligned on 4-byte?
38 add r15=4,in0 // second source pointer
40 cmp.ne.or.andcm p6,p7=r14,r0
57 shr.u ret0=r20,16 // now need to add the carry
62 shr.u ret0=r20,16 // add carry again
74 .restore sp // reset frame state
81 alloc r35=ar.pfs,2,2,2,0
88 br.call.sptk.many b0=do_csum
96 GLOBAL_ENTRY(csum_ipv6_magic)
103 dep r15=in3,in2,32,16
126 shr.u r10=r8,32 // now fold sum into short
131 shr.u r10=r8,16 // yeah, keep it rolling
136 shr.u r10=r8,16 // three times lucky