2 * A fast checksum routine using movem
3 * Copyright (c) 1998-2007 Axis Communications AB
5 * csum_partial(const unsigned char * buff, int len, unsigned int sum)
9 .type csum_partial,@function
16 ;; Optimized for large packets
25 ;; do a movem checksum
27 _mloop: movem [$r10+],$r9 ; read 10 longwords
28 ;; Loop count without touching the c flag.
29 addoq -10*4, $acr, $acr
30 ;; perform dword checksumming on the 10 longwords
43 ;; test $acr without trashing carry.
46 ;; r11 <= acr is not really needed in the mloop, just using the dslot
47 ;; to prepare for what is needed after mloop.
50 ;; fold the last carry into r13
52 movem [$sp+],$r8 ; restore regs
55 addq 10*4,$r11 ; compensate for last loop underflowing length
57 moveq -1,$r9 ; put 0xffff in r9, faster than move.d 0xffff,r9
61 lsrq 16,$r13 ; r13 = checksum >> 16
62 and.d $r9,$r12 ; checksum = checksum & 0xffff
67 add.d $r13,$r12 ; checksum += r13
69 ;; checksum the rest of the words
76 ;; see if we have one odd byte more
83 ;; copy and checksum the last byte
88 .size csum_partial, .-csum_partial