2 * A fast checksum+copy routine using movem
3 * Copyright (c) 1998, 2001, 2003 Axis Communications AB
7 * csum_partial_copy_nocheck(const char *src, char *dst,
8 * int len, unsigned int sum)
11 .globl csum_partial_copy_nocheck
12 csum_partial_copy_nocheck:
19 ;; check for breakeven length between movem and normal word looping versions
20 ;; we also do _NOT_ want to compute a checksum over more than the
21 ;; actual length when length < 40
27 ;; need to save the registers we use below in the movem loop
28 ;; this overhead is why we have a check above for breakeven length
29 ;; only r0 - r8 have to be saved, the other ones are clobber-able
30 ;; according to the ABI
33 subq 10*4,$r12 ; update length for the first loop
36 ;; do a movem copy and checksum
38 1: ;; A failing userspace access (the read) will have this as PC.
39 _mloop: movem [$r10+],$r9 ; read 10 longwords
40 movem $r9,[$r11+] ; write 10 longwords
42 ;; perform dword checksumming on the 10 longwords
55 ;; fold the carry into the checksum, to avoid having to loop the carry
59 addc 0,$r13 ; do it again, since we might have generated a carry
65 addq 10*4,$r12 ; compensate for last loop underflowing length
67 movem [$sp+],$r8 ; restore regs
70 ;; only fold if there is anything to fold.
75 ;; fold 32-bit checksum into a 16-bit checksum, to avoid carries below
76 ;; r9 can be used as temporary.
79 lsrq 16,$r9 ; r0 = checksum >> 16
80 and.d 0xffff,$r13 ; checksum = checksum & 0xffff
81 add.d $r9,$r13 ; checksum += r0
82 move.d $r13,$r9 ; do the same again, maybe we got a carry last add
92 ;; copy and checksum the rest of the words
96 2: ;; A failing userspace access for the read below will have this as PC.
97 _wloop: move.w [$r10+],$r9
106 ;; see if we have one odd byte more
114 ;; copy and checksum the last byte
115 3: ;; A failing userspace access for the read below will have this as PC.