1 /* SPDX-License-Identifier: GPL-2.0 */
3 * A fast checksum+copy routine using movem
4 * Copyright (c) 1998, 2001 Axis Communications AB
8 * csum_partial_copy_nocheck(const char *src, char *dst,
9 * int len, unsigned int sum)
12 .globl csum_partial_copy_nocheck
13 csum_partial_copy_nocheck:
20 ;; check for breakeven length between movem and normal word looping versions
21 ;; we also do _NOT_ want to compute a checksum over more than the
22 ;; actual length when length < 40
28 ;; need to save the registers we use below in the movem loop
29 ;; this overhead is why we have a check above for breakeven length
30 ;; only r0 - r8 have to be saved, the other ones are clobber-able
31 ;; according to the ABI
36 ;; do a movem copy and checksum
38 subq 10*4, $r12 ; update length for the first loop
40 _mloop: movem [$r10+],$r9 ; read 10 longwords
41 1: ;; A failing userspace access will have this as PC.
42 movem $r9,[$r11+] ; write 10 longwords
44 ;; perform dword checksumming on the 10 longwords
66 ;; fold the carry into the checksum, to avoid having to loop the carry
76 addq 10*4,$r12 ; compensate for last loop underflowing length
78 movem [$sp+],$r8 ; restore regs
81 ;; only fold if there is anything to fold.
86 ;; fold 32-bit checksum into a 16-bit checksum, to avoid carries below
87 ;; r9 can be used as temporary.
90 lsrq 16,$r9 ; r0 = checksum >> 16
91 and.d 0xffff,$r13 ; checksum = checksum & 0xffff
92 add.d $r9,$r13 ; checksum += r0
99 ;; copy and checksum the rest of the words
103 _wloop: move.w [$r10+],$r9
104 2: ;; A failing userspace access will have this as PC.
113 ;; see if we have one odd byte more
121 ;; copy and checksum the last byte
123 3: ;; A failing userspace access will have this as PC.