1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2004 by Jens Arnold
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
23 .section .icode,"ax",@progbits
27 .type memset,@function
29 /* Fills a memory region with specified byte value
30 * This version is optimized for speed
33 * (4,%sp) - start address
38 * %d0 - start address (like ANSI version)
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)
46 * %a1 - current address (runs down from end to start)
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.
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 */
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 */
64 and.l #0xFF,%d0 /* start: spread data to all 4 bytes */
67 or.l %d1,%d0 /* data now in 2 lower bytes of %d0 */
70 or.l %d1,%d0 /* data now in all 4 bytes of %d0 */
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 */
77 /* leading byte loop: sets 0..3 bytes */
79 move.b %d0,-(%a1) /* store byte */
80 cmp.l %d1,%a1 /* runs %a1 down to last long bound */
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 */
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 */
95 /* leading longword loop: sets 0..3 longwords */
97 move.l %d0,-(%a1) /* store longword */
98 cmp.l %d1,%a1 /* runs %a1 down to last line bound */
102 move.l %d2,-(%sp) /* free some registers */
105 move.l %d0,%d1 /* spread data to 4 data registers */
108 lea.l (15,%a0),%a0 /* start address += 15, acct. for trl. data */
110 /* main loop: set whole lines utilising burst mode */
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 */
117 lea.l (-15,%a0),%a0 /* correct start address */
118 move.l (%sp)+,%d3 /* restore registers */
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 */
128 move.l %a0,%d1 /* %d1 = start address ... */
129 addq.l #3,%d1 /* ... +3, account for possible trailing bytes */
131 /* trailing longword loop */
133 move.l %d0,-(%a1) /* store longword */
134 cmp.l %d1,%a1 /* runs %a1 down to first long bound */
138 cmp.l %a0,%a1 /* any bytes left? */
139 bls.b .end_b2 /* no: skip loop */
141 /* trailing byte loop */
143 move.b %d0,-(%a1) /* store byte */
144 cmp.l %a0,%a1 /* runs %a1 down to start address */
148 move.l %a0,%d0 /* return start address */
152 .size memset,.end-memset