Casting Pointers - (nf)
grunwald at uiuccsb.UUCP
grunwald at uiuccsb.UUCP
Sat Feb 4 13:43:11 AEST 1984
#R:houxt:-35400:uiuccsb:9000011:000:1652
uiuccsb!grunwald Feb 3 11:32:00 1984
If you want to generate a fast, non-portable copy for the 68000, include the
following lines as your copy routine:
copy(from,to,length)
register char *from, /* a5 */
*to; /* a4 */
register int length; /* d7 */
{
/*
* only handles even byte boundries
*/
if (((int)from & 1 == 0) && ((int)to & 1 == 0)) {
asm("lplbl: movl a5 at ++,a4 at ++");
asm(" dbnz d7,lplbl");
}
else do_it_yourself;
}
This generates the following using the MIT CC68. I assume that ints are 32
bits, otherwise you might need to cast the pointer to a long. If you're going
to write machine dependent code, you might as well do it so that its as fast
as possible. While I'm not one to push the use of really kludgy things like
the "asm" construct, I think that when you're doing what you are trying to
do, it's useful.
In the 68010 (e.g. as in the new Sun stations), there is a two word buffer
that was specificially designed for instruction pairs like the above. You
don't do any fetching for the opcoodes and the speed improvement is pretty
good. Check out the 68010 instruction manual for more details. However, if
you don't use the MIT CC68 compiler, you better try running the above
through cc -S whatever.c and look at the register allocations, etc.
.data
.text
.globl copy
copy:
link a6,#-_F1
moveml #_S1,a6@(-_F1)
movl a6@(8),a5
movl a6@(12),a4
movl a6@(16),d7
| A1 = 20
movl a5,d0
andl #1,d0
bne .L13
movl a4,d0
andl #0,d0
beq .L13
lplbl: movl a5 at ++,a4 at ++
dbnz d7,lplbl
.L13:
bra .L12
.L12: moveml a6@(-_F1),#12416
unlk a6
rts
_F1 = 12
_S1 = 12416
| M1 = 0
.data
Dirk Grunwald
University of Illinois
... ! ihnp4 ! uiucdcs ! grunwald
More information about the Comp.lang.c
mailing list