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)
15 ;; Optimized for large packets
24 ;; do a movem checksum
26 _mloop: movem [$r10+],$r9 ; read 10 longwords
27 ;; Loop count without touching the c flag.
28 addoq -10*4, $acr, $acr
29 ;; perform dword checksumming on the 10 longwords
42 ;; test $acr without trashing carry.
45 ;; r11 <= acr is not really needed in the mloop, just using the dslot
46 ;; to prepare for what is needed after mloop.
49 ;; fold the last carry into r13
51 movem [$sp+],$r8 ; restore regs
54 addq 10*4,$r11 ; compensate for last loop underflowing length
56 moveq -1,$r9 ; put 0xffff in r9, faster than move.d 0xffff,r9
60 lsrq 16,$r13 ; r13 = checksum >> 16
61 and.d $r9,$r12 ; checksum = checksum & 0xffff
66 add.d $r13,$r12 ; checksum += r13
68 ;; checksum the rest of the words
75 ;; see if we have one odd byte more
82 ;; copy and checksum the last byte