diff options
Diffstat (limited to 'arch/cris/arch-v32/lib/checksumcopy.S')
-rw-r--r-- | arch/cris/arch-v32/lib/checksumcopy.S | 69 |
1 files changed, 20 insertions, 49 deletions
diff --git a/arch/cris/arch-v32/lib/checksumcopy.S b/arch/cris/arch-v32/lib/checksumcopy.S index 9303ccbadc6d..21aabe91489b 100644 --- a/arch/cris/arch-v32/lib/checksumcopy.S +++ b/arch/cris/arch-v32/lib/checksumcopy.S | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | * A fast checksum+copy routine using movem | 2 | * A fast checksum+copy routine using movem |
3 | * Copyright (c) 1998, 2001, 2003 Axis Communications AB | 3 | * Copyright (c) 1998-2007 Axis Communications AB |
4 | * | 4 | * |
5 | * Authors: Bjorn Wesen | 5 | * Authors: Bjorn Wesen |
6 | * | 6 | * |
@@ -16,32 +16,23 @@ csum_partial_copy_nocheck: | |||
16 | ;; r12 - length | 16 | ;; r12 - length |
17 | ;; r13 - checksum | 17 | ;; r13 - checksum |
18 | 18 | ||
19 | ;; check for breakeven length between movem and normal word looping versions | 19 | ;; Optimized for large packets |
20 | ;; we also do _NOT_ want to compute a checksum over more than the | 20 | subq 10*4, $r12 |
21 | ;; actual length when length < 40 | 21 | blt _word_loop |
22 | 22 | move.d $r12, $acr | |
23 | cmpu.w 80,$r12 | ||
24 | blo _word_loop | ||
25 | nop | ||
26 | |||
27 | ;; need to save the registers we use below in the movem loop | ||
28 | ;; this overhead is why we have a check above for breakeven length | ||
29 | ;; only r0 - r8 have to be saved, the other ones are clobber-able | ||
30 | ;; according to the ABI | ||
31 | 23 | ||
32 | subq 9*4,$sp | 24 | subq 9*4,$sp |
33 | subq 10*4,$r12 ; update length for the first loop | 25 | clearf c |
34 | movem $r8,[$sp] | 26 | movem $r8,[$sp] |
35 | 27 | ||
36 | ;; do a movem copy and checksum | 28 | ;; do a movem copy and checksum |
37 | |||
38 | 1: ;; A failing userspace access (the read) will have this as PC. | 29 | 1: ;; A failing userspace access (the read) will have this as PC. |
39 | _mloop: movem [$r10+],$r9 ; read 10 longwords | 30 | _mloop: movem [$r10+],$r9 ; read 10 longwords |
31 | addoq -10*4, $acr, $acr ; loop counter in latency cycle | ||
40 | movem $r9,[$r11+] ; write 10 longwords | 32 | movem $r9,[$r11+] ; write 10 longwords |
41 | 33 | ||
42 | ;; perform dword checksumming on the 10 longwords | 34 | ;; perform dword checksumming on the 10 longwords |
43 | 35 | addc $r0,$r13 | |
44 | add.d $r0,$r13 | ||
45 | addc $r1,$r13 | 36 | addc $r1,$r13 |
46 | addc $r2,$r13 | 37 | addc $r2,$r13 |
47 | addc $r3,$r13 | 38 | addc $r3,$r13 |
@@ -52,47 +43,30 @@ _mloop: movem [$r10+],$r9 ; read 10 longwords | |||
52 | addc $r8,$r13 | 43 | addc $r8,$r13 |
53 | addc $r9,$r13 | 44 | addc $r9,$r13 |
54 | 45 | ||
55 | ;; fold the carry into the checksum, to avoid having to loop the carry | 46 | ;; test $acr, without trashing carry. |
56 | ;; back into the top | 47 | move.d $acr, $acr |
57 | 48 | bpl _mloop | |
58 | addc 0,$r13 | 49 | ;; r12 <= acr is needed after mloop and in the exception handlers. |
59 | addc 0,$r13 ; do it again, since we might have generated a carry | 50 | move.d $acr, $r12 |
60 | |||
61 | subq 10*4,$r12 | ||
62 | bge _mloop | ||
63 | nop | ||
64 | |||
65 | addq 10*4,$r12 ; compensate for last loop underflowing length | ||
66 | 51 | ||
52 | ;; fold the last carry into r13 | ||
53 | addc 0, $r13 | ||
67 | movem [$sp+],$r8 ; restore regs | 54 | movem [$sp+],$r8 ; restore regs |
68 | 55 | ||
69 | _word_loop: | 56 | _word_loop: |
70 | ;; only fold if there is anything to fold. | 57 | addq 10*4,$r12 ; compensate for last loop underflowing length |
71 | |||
72 | cmpq 0,$r13 | ||
73 | beq _no_fold | ||
74 | 58 | ||
75 | ;; fold 32-bit checksum into a 16-bit checksum, to avoid carries below | 59 | ;; fold 32-bit checksum into a 16-bit checksum, to avoid carries below |
76 | ;; r9 can be used as temporary. | 60 | ;; r9 can be used as temporary. |
77 | |||
78 | move.d $r13,$r9 | 61 | move.d $r13,$r9 |
79 | lsrq 16,$r9 ; r0 = checksum >> 16 | 62 | lsrq 16,$r9 ; r0 = checksum >> 16 |
80 | and.d 0xffff,$r13 ; checksum = checksum & 0xffff | 63 | and.d 0xffff,$r13 ; checksum = checksum & 0xffff |
81 | add.d $r9,$r13 ; checksum += r0 | ||
82 | move.d $r13,$r9 ; do the same again, maybe we got a carry last add | ||
83 | lsrq 16,$r9 | ||
84 | and.d 0xffff,$r13 | ||
85 | add.d $r9,$r13 | ||
86 | 64 | ||
87 | _no_fold: | 65 | subq 2, $r12 |
88 | cmpq 2,$r12 | ||
89 | blt _no_words | 66 | blt _no_words |
90 | nop | 67 | add.d $r9,$r13 ; checksum += r0 |
91 | 68 | ||
92 | ;; copy and checksum the rest of the words | 69 | ;; copy and checksum the rest of the words |
93 | |||
94 | subq 2,$r12 | ||
95 | |||
96 | 2: ;; A failing userspace access for the read below will have this as PC. | 70 | 2: ;; A failing userspace access for the read below will have this as PC. |
97 | _wloop: move.w [$r10+],$r9 | 71 | _wloop: move.w [$r10+],$r9 |
98 | addu.w $r9,$r13 | 72 | addu.w $r9,$r13 |
@@ -100,12 +74,9 @@ _wloop: move.w [$r10+],$r9 | |||
100 | bge _wloop | 74 | bge _wloop |
101 | move.w $r9,[$r11+] | 75 | move.w $r9,[$r11+] |
102 | 76 | ||
103 | addq 2,$r12 | ||
104 | |||
105 | _no_words: | 77 | _no_words: |
106 | ;; see if we have one odd byte more | 78 | addq 2,$r12 |
107 | cmpq 1,$r12 | 79 | bne _do_byte |
108 | beq _do_byte | ||
109 | nop | 80 | nop |
110 | ret | 81 | ret |
111 | move.d $r13,$r10 | 82 | move.d $r13,$r10 |