diff options
author | Thomas Martitz <kugel@rockbox.org> | 2012-01-07 19:56:09 +0100 |
---|---|---|
committer | Thomas Martitz <kugel@rockbox.org> | 2012-01-22 18:46:45 +0100 |
commit | a035261089403de259e74ce4dd196e2715138ed2 (patch) | |
tree | 440d75109a7ebfefef2a58076b38b1bfe9db8f63 /firmware/asm/m68k/memset.S | |
parent | 8e8e978de6b6283b66a6829fa8c5e3b94674ce7d (diff) | |
download | rockbox-a035261089403de259e74ce4dd196e2715138ed2.tar.gz rockbox-a035261089403de259e74ce4dd196e2715138ed2.zip |
Move optimized memcpy and friends and strlen to firmware/asm,
using the new automatic-asm-picking infrastructure.
Diffstat (limited to 'firmware/asm/m68k/memset.S')
-rw-r--r-- | firmware/asm/m68k/memset.S | 152 |
1 files changed, 152 insertions, 0 deletions
diff --git a/firmware/asm/m68k/memset.S b/firmware/asm/m68k/memset.S new file mode 100644 index 0000000000..839b305a05 --- /dev/null +++ b/firmware/asm/m68k/memset.S | |||
@@ -0,0 +1,152 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2004 by Jens Arnold | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | #include "config.h" | ||
22 | |||
23 | .section .icode,"ax",@progbits | ||
24 | |||
25 | .align 2 | ||
26 | .global memset | ||
27 | .type memset,@function | ||
28 | |||
29 | /* Fills a memory region with specified byte value | ||
30 | * This version is optimized for speed | ||
31 | * | ||
32 | * arguments: | ||
33 | * (4,%sp) - start address | ||
34 | * (8,%sp) - data | ||
35 | * (12,%sp) - length | ||
36 | * | ||
37 | * return value: | ||
38 | * %d0 - start address (like ANSI version) | ||
39 | * | ||
40 | * register usage: | ||
41 | * %d0 - data (spread to all 4 bytes when using long stores) | ||
42 | * %d1 - temporary / data (for burst transfer) | ||
43 | * %d2 - data (for burst transfer) | ||
44 | * %d3 - data (for burst transfer) | ||
45 | * %a0 - start address | ||
46 | * %a1 - current address (runs down from end to start) | ||
47 | * | ||
48 | * For maximum speed this routine uses both long stores and burst mode, | ||
49 | * storing whole lines with movem.l. The routine fills memory from end | ||
50 | * to start in order to ease returning the start address. | ||
51 | */ | ||
52 | memset: | ||
53 | move.l (4,%sp),%a0 /* start address */ | ||
54 | move.l (8,%sp),%d0 /* data */ | ||
55 | move.l (12,%sp),%a1 /* length */ | ||
56 | add.l %a0,%a1 /* %a1 = end address */ | ||
57 | |||
58 | move.l %a0,%d1 | ||
59 | addq.l #7,%d1 | ||
60 | and.l #0xFFFFFFFC,%d1 /* %d1 = first long bound + 4 */ | ||
61 | cmp.l %d1,%a1 /* at least one aligned longword to fill? */ | ||
62 | blo.b .no_longs /* no, jump directly to byte loop */ | ||
63 | |||
64 | and.l #0xFF,%d0 /* start: spread data to all 4 bytes */ | ||
65 | move.l %d0,%d1 | ||
66 | lsl.l #8,%d1 | ||
67 | or.l %d1,%d0 /* data now in 2 lower bytes of %d0 */ | ||
68 | move.l %d0,%d1 | ||
69 | swap %d0 | ||
70 | or.l %d1,%d0 /* data now in all 4 bytes of %d0 */ | ||
71 | |||
72 | move.l %a1,%d1 | ||
73 | and.l #0xFFFFFFFC,%d1 /* %d1 = last long bound */ | ||
74 | cmp.l %d1,%a1 /* any bytes to set? */ | ||
75 | bls.b .end_b1 /* no: skip byte loop */ | ||
76 | |||
77 | /* leading byte loop: sets 0..3 bytes */ | ||
78 | .loop_b1: | ||
79 | move.b %d0,-(%a1) /* store byte */ | ||
80 | cmp.l %d1,%a1 /* runs %a1 down to last long bound */ | ||
81 | bhi.b .loop_b1 | ||
82 | |||
83 | .end_b1: | ||
84 | moveq.l #31,%d1 | ||
85 | add.l %a0,%d1 | ||
86 | and.l #0xFFFFFFF0,%d1 /* %d1 = first line bound + 16 */ | ||
87 | cmp.l %d1,%a1 /* at least one full line to fill? */ | ||
88 | blo.b .no_lines /* no, jump to longword loop */ | ||
89 | |||
90 | mov.l %a1,%d1 | ||
91 | and.l #0xFFFFFFF0,%d1 /* %d1 = last line bound */ | ||
92 | cmp.l %d1,%a1 /* any longwords to set? */ | ||
93 | bls.b .end_l1 /* no: skip longword loop */ | ||
94 | |||
95 | /* leading longword loop: sets 0..3 longwords */ | ||
96 | .loop_l1: | ||
97 | move.l %d0,-(%a1) /* store longword */ | ||
98 | cmp.l %d1,%a1 /* runs %a1 down to last line bound */ | ||
99 | bhi.b .loop_l1 | ||
100 | |||
101 | .end_l1: | ||
102 | move.l %d2,-(%sp) /* free some registers */ | ||
103 | move.l %d3,-(%sp) | ||
104 | |||
105 | move.l %d0,%d1 /* spread data to 4 data registers */ | ||
106 | move.l %d0,%d2 | ||
107 | move.l %d0,%d3 | ||
108 | lea.l (15,%a0),%a0 /* start address += 15, acct. for trl. data */ | ||
109 | |||
110 | /* main loop: set whole lines utilising burst mode */ | ||
111 | .loop_line: | ||
112 | lea.l (-16,%a1),%a1 /* pre-decrement */ | ||
113 | movem.l %d0-%d3,(%a1) /* store line */ | ||
114 | cmp.l %a0,%a1 /* runs %a1 down to first line bound */ | ||
115 | bhi.b .loop_line | ||
116 | |||
117 | lea.l (-15,%a0),%a0 /* correct start address */ | ||
118 | move.l (%sp)+,%d3 /* restore registers */ | ||
119 | move.l (%sp)+,%d2 | ||
120 | |||
121 | move.l %a0,%d1 /* %d1 = start address ... */ | ||
122 | addq.l #3,%d1 /* ... +3, account for possible trailing bytes */ | ||
123 | cmp.l %d1,%a1 /* any longwords left */ | ||
124 | bhi.b .loop_l2 /* yes: jump to longword loop */ | ||
125 | bra.b .no_longs /* no: skip loop */ | ||
126 | |||
127 | .no_lines: | ||
128 | move.l %a0,%d1 /* %d1 = start address ... */ | ||
129 | addq.l #3,%d1 /* ... +3, account for possible trailing bytes */ | ||
130 | |||
131 | /* trailing longword loop */ | ||
132 | .loop_l2: | ||
133 | move.l %d0,-(%a1) /* store longword */ | ||
134 | cmp.l %d1,%a1 /* runs %a1 down to first long bound */ | ||
135 | bhi.b .loop_l2 | ||
136 | |||
137 | .no_longs: | ||
138 | cmp.l %a0,%a1 /* any bytes left? */ | ||
139 | bls.b .end_b2 /* no: skip loop */ | ||
140 | |||
141 | /* trailing byte loop */ | ||
142 | .loop_b2: | ||
143 | move.b %d0,-(%a1) /* store byte */ | ||
144 | cmp.l %a0,%a1 /* runs %a1 down to start address */ | ||
145 | bhi.b .loop_b2 | ||
146 | |||
147 | .end_b2: | ||
148 | move.l %a0,%d0 /* return start address */ | ||
149 | rts | ||
150 | |||
151 | .end: | ||
152 | .size memset,.end-memset | ||