2005-07-28 02:44:44 +08:00
|
|
|
/*
|
|
|
|
* A fast checksum+copy routine using movem
|
2008-01-26 00:54:14 +08:00
|
|
|
* Copyright (c) 1998-2007 Axis Communications AB
|
2005-07-28 02:44:44 +08:00
|
|
|
*
|
|
|
|
* Authors: Bjorn Wesen
|
|
|
|
*
|
|
|
|
* csum_partial_copy_nocheck(const char *src, char *dst,
|
|
|
|
* int len, unsigned int sum)
|
|
|
|
*/
|
|
|
|
|
|
|
|
.globl csum_partial_copy_nocheck
|
2010-08-03 22:13:37 +08:00
|
|
|
.type csum_partial_copy_nocheck,@function
|
2005-07-28 02:44:44 +08:00
|
|
|
csum_partial_copy_nocheck:
|
|
|
|
|
|
|
|
;; r10 - src
|
|
|
|
;; r11 - dst
|
|
|
|
;; r12 - length
|
|
|
|
;; r13 - checksum
|
|
|
|
|
2008-01-26 00:54:14 +08:00
|
|
|
;; Optimized for large packets
|
|
|
|
subq 10*4, $r12
|
|
|
|
blt _word_loop
|
|
|
|
move.d $r12, $acr
|
2005-07-28 02:44:44 +08:00
|
|
|
|
|
|
|
subq 9*4,$sp
|
2008-01-26 00:54:14 +08:00
|
|
|
clearf c
|
2005-07-28 02:44:44 +08:00
|
|
|
movem $r8,[$sp]
|
|
|
|
|
|
|
|
;; do a movem copy and checksum
|
|
|
|
1: ;; A failing userspace access (the read) will have this as PC.
|
|
|
|
_mloop: movem [$r10+],$r9 ; read 10 longwords
|
2008-01-26 00:54:14 +08:00
|
|
|
addoq -10*4, $acr, $acr ; loop counter in latency cycle
|
2005-07-28 02:44:44 +08:00
|
|
|
movem $r9,[$r11+] ; write 10 longwords
|
|
|
|
|
|
|
|
;; perform dword checksumming on the 10 longwords
|
2008-01-26 00:54:14 +08:00
|
|
|
addc $r0,$r13
|
2005-07-28 02:44:44 +08:00
|
|
|
addc $r1,$r13
|
|
|
|
addc $r2,$r13
|
|
|
|
addc $r3,$r13
|
|
|
|
addc $r4,$r13
|
|
|
|
addc $r5,$r13
|
|
|
|
addc $r6,$r13
|
|
|
|
addc $r7,$r13
|
|
|
|
addc $r8,$r13
|
|
|
|
addc $r9,$r13
|
|
|
|
|
2008-01-26 00:54:14 +08:00
|
|
|
;; test $acr, without trashing carry.
|
|
|
|
move.d $acr, $acr
|
|
|
|
bpl _mloop
|
|
|
|
;; r12 <= acr is needed after mloop and in the exception handlers.
|
|
|
|
move.d $acr, $r12
|
2005-07-28 02:44:44 +08:00
|
|
|
|
2008-01-26 00:54:14 +08:00
|
|
|
;; fold the last carry into r13
|
|
|
|
addc 0, $r13
|
2005-07-28 02:44:44 +08:00
|
|
|
movem [$sp+],$r8 ; restore regs
|
|
|
|
|
|
|
|
_word_loop:
|
2008-01-26 00:54:14 +08:00
|
|
|
addq 10*4,$r12 ; compensate for last loop underflowing length
|
2005-07-28 02:44:44 +08:00
|
|
|
|
|
|
|
;; fold 32-bit checksum into a 16-bit checksum, to avoid carries below
|
|
|
|
;; r9 can be used as temporary.
|
|
|
|
move.d $r13,$r9
|
|
|
|
lsrq 16,$r9 ; r0 = checksum >> 16
|
|
|
|
and.d 0xffff,$r13 ; checksum = checksum & 0xffff
|
|
|
|
|
2008-01-26 00:54:14 +08:00
|
|
|
subq 2, $r12
|
2005-07-28 02:44:44 +08:00
|
|
|
blt _no_words
|
2008-01-26 00:54:14 +08:00
|
|
|
add.d $r9,$r13 ; checksum += r0
|
2005-07-28 02:44:44 +08:00
|
|
|
|
|
|
|
;; copy and checksum the rest of the words
|
|
|
|
2: ;; A failing userspace access for the read below will have this as PC.
|
|
|
|
_wloop: move.w [$r10+],$r9
|
|
|
|
addu.w $r9,$r13
|
|
|
|
subq 2,$r12
|
|
|
|
bge _wloop
|
|
|
|
move.w $r9,[$r11+]
|
|
|
|
|
|
|
|
_no_words:
|
2008-01-26 00:54:14 +08:00
|
|
|
addq 2,$r12
|
|
|
|
bne _do_byte
|
2005-07-28 02:44:44 +08:00
|
|
|
nop
|
|
|
|
ret
|
|
|
|
move.d $r13,$r10
|
|
|
|
|
|
|
|
_do_byte:
|
|
|
|
;; copy and checksum the last byte
|
|
|
|
3: ;; A failing userspace access for the read below will have this as PC.
|
|
|
|
move.b [$r10],$r9
|
|
|
|
addu.b $r9,$r13
|
|
|
|
move.b $r9,[$r11]
|
|
|
|
ret
|
|
|
|
move.d $r13,$r10
|
2010-08-03 22:13:37 +08:00
|
|
|
|
|
|
|
.size csum_partial_copy_nocheck, . - csum_partial_copy_nocheck
|