2 * linux/arch/arm/lib/csumpartial.S
4 * Copyright (C) 1995-1998 Russell King
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 #include <linux/linkage.h>
11 #include <asm/assembler.h>
12 #include <asm/export.h>
17 * Function: __u32 csum_partial(const char *src, int len, __u32 sum)
18 * Params : r0 = buffer, r1 = len, r2 = checksum
19 * Returns : r0 = new checksum
26 td1 .req r4 @ save before use
27 td2 .req r5 @ save before use
35 * Handle 0 to 7 bytes, with any alignment of source and
36 * destination pointers. Note that when we get here, C = 0
38 .Lless8: teq len, #0 @ check for zero count
41 /* we must have at least one byte. */
42 tst buf, #1 @ odd address?
43 movne sum, sum, ror #8
46 adcnes sum, sum, td0, put_byte_1
51 /* we are now half-word aligned */
54 #if __LINUX_ARM_ARCH__ >= 4
62 orr td0, td0, td3, lsl #8
64 orr td0, td3, td0, lsl #8
71 .Lless8_byte: tst len, #1 @ odd number of bytes
72 ldrneb td0, [buf], #1 @ include last byte
73 adcnes sum, sum, td0, put_byte_0 @ update checksum
75 .Ldone: adc r0, sum, #0 @ collect up the last carry
77 tst td0, #1 @ check buffer alignment
78 movne r0, r0, ror #8 @ rotate checksum by 8 bits
79 ldr pc, [sp], #4 @ return
81 .Lnot_aligned: tst buf, #1 @ odd address
82 ldrneb td0, [buf], #1 @ make even
84 adcnes sum, sum, td0, put_byte_1 @ update checksum
86 tst buf, #2 @ 32-bit aligned?
87 #if __LINUX_ARM_ARCH__ >= 4
88 ldrneh td0, [buf], #2 @ make 32-bit aligned
95 orrne td0, td0, ip, lsl #8
97 orrne td0, ip, td0, lsl #8
100 adcnes sum, sum, td0 @ update checksum
105 cmp len, #8 @ Ensure that we have at least
106 blo .Lless8 @ 8 bytes to copy.
109 movne sum, sum, ror #8
111 adds sum, sum, #0 @ C = 0
112 tst buf, #3 @ Test destination alignment
113 blne .Lnot_aligned @ align destination, return here
119 2: ldmia buf!, {td0, td1, td2, td3}
124 ldmia buf!, {td0, td1, td2, td3}
134 3: tst len, #0x1c @ should not change C
137 4: ldr td0, [buf], #4
143 ENDPROC(csum_partial)
144 EXPORT_SYMBOL(csum_partial)