1 /* SPDX-License-Identifier: GPL-2.0 */
3 * A fast checksum routine using movem
4 * Copyright (c) 1998-2001 Axis Communications AB
6 * csum_partial(const unsigned char * buff, int len, unsigned int sum)
16 ;; check for breakeven length between movem and normal word looping versions
17 ;; we also do _NOT_ want to compute a checksum over more than the
18 ;; actual length when length < 40
24 ;; need to save the registers we use below in the movem loop
25 ;; this overhead is why we have a check above for breakeven length
26 ;; only r0 - r8 have to be saved, the other ones are clobber-able
27 ;; according to the ABI
32 ;; do a movem checksum
34 subq 10*4,$r11 ; update length for the first loop
36 _mloop: movem [$r10+],$r9 ; read 10 longwords
38 ;; perform dword checksumming on the 10 longwords
60 ;; fold the carry into the checksum, to avoid having to loop the carry
70 addq 10*4,$r11 ; compensate for last loop underflowing length
72 movem [$sp+],$r8 ; restore regs
75 ;; only fold if there is anything to fold.
80 ;; fold 32-bit checksum into a 16-bit checksum, to avoid carries below.
81 ;; r9 and r13 can be used as temporaries.
83 moveq -1,$r9 ; put 0xffff in r9, faster than move.d 0xffff,r9
87 lsrq 16,$r13 ; r13 = checksum >> 16
88 and.d $r9,$r12 ; checksum = checksum & 0xffff
89 add.d $r13,$r12 ; checksum += r13
96 ;; checksum the rest of the words
107 ;; see if we have one odd byte more
115 ;; copy and checksum the last byte