1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2006 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
26 .type memset16,@function
28 /* Fills a memory region with specified word value
29 * Start address must be word aligned, length is in words
30 * This version is optimized for speed
33 * (4,%sp) - start address
41 * %d0 - data (spread to both words 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 */
57 add.l %a0,%a1 /* %a1 = end address */
61 and.l #0xFFFFFFFC,%d1 /* %d1 = first long bound + 4 */
62 cmp.l %d1,%a1 /* at least one aligned longword to fill? */
63 blo.b .no_longs /* no, jump directly to word loop */
65 and.l #0xFFFF,%d0 /* start: spread data to both words */
68 or.l %d1,%d0 /* data now in both words */
71 and.l #0xFFFFFFFC,%d1 /* %d1 = last long bound */
72 cmp.l %d1,%a1 /* one extra word? */
73 bls.b .end_w1 /* no: skip */
75 move.w %d0,-(%a1) /* set leading word */
80 and.l #0xFFFFFFF0,%d1 /* %d1 = first line bound + 16 */
81 cmp.l %d1,%a1 /* at least one full line to fill? */
82 blo.b .no_lines /* no, jump to longword loop */
85 and.l #0xFFFFFFF0,%d1 /* %d1 = last line bound */
86 cmp.l %d1,%a1 /* any longwords to set? */
87 bls.b .end_l1 /* no: skip longword loop */
89 /* leading longword loop: sets 0..3 longwords */
91 move.l %d0,-(%a1) /* store longword */
92 cmp.l %d1,%a1 /* runs %a1 down to last line bound */
96 move.l %d2,-(%sp) /* free some registers */
99 move.l %d0,%d1 /* spread data to 4 data registers */
102 lea.l (14,%a0),%a0 /* start address += 14, acct. for trl. data */
104 /* main loop: set whole lines utilising burst mode */
106 lea.l (-16,%a1),%a1 /* pre-decrement */
107 movem.l %d0-%d3,(%a1) /* store line */
108 cmp.l %a0,%a1 /* runs %a1 down to first line bound */
111 lea.l (-14,%a0),%a0 /* correct start address */
112 move.l (%sp)+,%d3 /* restore registers */
115 move.l %a0,%d1 /* %d1 = start address ... */
116 addq.l #2,%d1 /* ... +2, account for possible trailing word */
117 cmp.l %d1,%a1 /* any longwords left */
118 bhi.b .loop_l2 /* yes: jump to longword loop */
119 bra.b .no_longs /* no: skip loop */
122 move.l %a0,%d1 /* %d1 = start address ... */
123 addq.l #2,%d1 /* ... +2, account for possible trailing word */
125 /* trailing longword loop */
127 move.l %d0,-(%a1) /* store longword */
128 cmp.l %d1,%a1 /* runs %a1 down to first long bound */
132 cmp.l %a0,%a1 /* any words left? */
133 bls.b .end_w2 /* no: skip loop */
135 /* trailing word loop */
137 move.w %d0,-(%a1) /* store word */
138 cmp.l %a0,%a1 /* runs %a1 down to start address */
142 move.l %a0,%d0 /* return start address */
146 .size memset16,.end-memset16