A study in code optimization in C

John Woods john at frog.UUCP
Tue Jul 31 08:26:00 AEST 1990


In article <1990Jul26.144134.16053 at ux1.cso.uiuc.edu>, mcdonald at aries.scs.uiuc.edu (Doug McDonald) writes:
> In article <133 at smds.UUCP> rh at smds.UUCP (Richard Harter) writes:
> >The macro shown below is an optimized memory to memory copy macro.
> >It is probably faster than memcopy on your machine
> Oh My!.
> Sure looks like his code loses. As I would expect, of course:  The
> library can do the whole 20 kilobytes in one instruction, assuming
> aligned operands. Unaligned, it takes a few more.

Well, it turns out that even without being able to do memory-to-memory moves
with a single SPIN_CYCLE instruction, a poor little garden variety 68020 can
do better than the supplied macro.  I checked our movebytes() subroutine,
and it did about three times better than the macro.  It, of course, uses
all of the valuable optimization tricks mentioned in Richard's article
(reason enough to stash it away), and also takes care of minor little problems
like odd-address alignment (which is a problem on the 68000 though not on
the '20).  movebytes() is, as it happens, written in C, using a compiler
(GreenHills) which translates it into really good assembly code.
-- 
John Woods, Charles River Data Systems, Framingham MA, (508) 626-1101
...!decvax!frog!john, john at frog.UUCP, ...!mit-eddie!jfw, jfw at eddie.mit.edu



More information about the Comp.lang.c mailing list