Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxl!ihnp4!inuxc!pur-ee!uiucdcs!uiuccsb!grunwald From: grunwald@uiuccsb.UUCP Newsgroups: net.lang.c Subject: Re: Casting Pointers - (nf) Message-ID: <5342@uiucdcs.UUCP> Date: Fri, 3-Feb-84 22:43:11 EST Article-I.D.: uiucdcs.5342 Posted: Fri Feb 3 22:43:11 1984 Date-Received: Wed, 8-Feb-84 05:42:04 EST Lines: 66 #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@++,a4@++"); 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@++,a4@++ 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