1 /* SPDX-License-Identifier: GPL-2.0 */
3 * A fast checksum routine using movem
4 * Copyright (c) 1998-2007 Axis Communications AB
6 * csum_partial(const unsigned char * buff, int len, unsigned int sum)
10 .type csum_partial,@function
17 ;; Optimized for large packets
26 ;; do a movem checksum
28 _mloop: movem [$r10+],$r9 ; read 10 longwords
29 ;; Loop count without touching the c flag.
30 addoq -10*4, $acr, $acr
31 ;; perform dword checksumming on the 10 longwords
44 ;; test $acr without trashing carry.
47 ;; r11 <= acr is not really needed in the mloop, just using the dslot
48 ;; to prepare for what is needed after mloop.
51 ;; fold the last carry into r13
53 movem [$sp+],$r8 ; restore regs
56 addq 10*4,$r11 ; compensate for last loop underflowing length
58 moveq -1,$r9 ; put 0xffff in r9, faster than move.d 0xffff,r9
62 lsrq 16,$r13 ; r13 = checksum >> 16
63 and.d $r9,$r12 ; checksum = checksum & 0xffff
68 add.d $r13,$r12 ; checksum += r13
70 ;; checksum the rest of the words
77 ;; see if we have one odd byte more
84 ;; copy and checksum the last byte
89 .size csum_partial, .-csum_partial