faster bcopy using duffs device (source)

Henry Spencer henry at utzoo.uucp
Sun Sep 10 10:53:06 AEST 1989


In article <5603 at thor.acc.stolaf.edu> mike at thor.stolaf.edu () writes:
>I just tried the obvious bcopy "while (n--) *s++ = *d++;"
>on a 68010 using gcc.  It produced a dbra loop that beat
>the sh*t out of the supposedly carefully handcoded one
>in the C library.  (Which is a Duffish sort of thing...

The odds are pretty good that the library one was built for a 68020 or 68000.
The various 68XXXs are more or less the same architecture, but performance
tradeoffs are *very* different.  The simple tight loop with autoincrement
and decrement usually wins on the 010 because of the "loop mode" feature
of the hardware.  On a 68000 or 68020, not so.

>If you have a halfway decent compiler, I bet a lot of
>the string routines will compile to excellent code using
>just the obvious C implementations.

This depends *a lot* on exactly what hardware you've got.  And cleverness
is a win regardless, if it's the right cleverness.  Copying a word at a
time rather than a byte at a time, size and alignment permitting, in a
"while (n--) *s++ = *d++;" loop will be a big win even on a 68010.
-- 
V7 /bin/mail source: 554 lines.|     Henry Spencer at U of Toronto Zoology
1989 X.400 specs: 2200+ pages. | uunet!attcan!utzoo!henry henry at zoo.toronto.edu



More information about the Comp.lang.c mailing list