Newsgroups: comp.lang.c
Path: utzoo!henry
From: henry@utzoo.uucp (Henry Spencer)
Subject: Re: faster bcopy using duffs device (source)
Message-ID: <1989Sep10.005306.23467@utzoo.uucp>
Organization: U of Toronto Zoology
References: <5180@portia.Stanford.EDU> <19473@mimsy.UUCP> <5603@thor.acc.stolaf.edu>
Date: Sun, 10 Sep 89 00:53:06 GMT

In article <5603@thor.acc.stolaf.edu> mike@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@zoo.toronto.edu
