Re: Does Duff Device break C compilers

jeremy@floyd.sw.oz.au (Jeremy Fitzhardinge)
10 May 1996 01:28:28 -0400

          From comp.compilers

Related articles
Does Duff Device break C compilers Lambert.Lum@eng.efi.com (Lambert Lum) (1996-05-06)
Re: Does Duff Device break C compilers preston@tera.com (1996-05-07)
Re: Does Duff Device break C compilers krste@ICSI.Berkeley.EDU (1996-05-08)
Re: Does Duff Device break C compilers jeremy@floyd.sw.oz.au (1996-05-10)
Re: Does Duff Device break C compilers rankin@eql.caltech.edu (1996-05-10)
Re: Does Duff Device break C compilers msb@sq.com (1996-05-10)
Re: Does Duff Device break C compilers preston@tera.com (1996-05-13)
Re: Does Duff Device break C compilers baynes@ukpsshp1.serigate.philips.nl (1996-05-19)
| List of all articles for this month |

From: jeremy@floyd.sw.oz.au (Jeremy Fitzhardinge)
Newsgroups: comp.compilers
Date: 10 May 1996 01:28:28 -0400
Organization: Softway Pty Ltd
References: 96-05-050 96-05-054 96-05-057
Keywords: C, optimize

"Lambert Lum" <Lambert.Lum@eng.efi.com> writes:
>item called Duff's Device.
> case 0: do { *to = *from++;
> case 7: *to = *from++;
> case 6: *to = *from++;
>[...]


preston@tera.com (Preston Briggs) writes:
> Better is to rewrite it, like this
>
> /* no assumptions made about count */
> for (n = 0; n < count; n++)
> to[n] = from[n];


krste@ICSI.Berkeley.EDU (Krste Asanovic) writes:
>Better yet, "Krste's Kopy" :-)
>
> memcpy(from, to, count*(sizeof *from));


Errm, neither of these alternatives does what the original does.
Better to write it:


/* Jeremy's Junk Jumper */
volatile thing *to;
thing *from;
for(n = 0; n < count; n++)
*to = from[n];


The original was to jump on some hardware as quickly as possible; the
Device was the only way Duff could get the CPU/compiler to do it fast
enough. It was purely an expedient hack for that case alone, and was
never proposed as a general mechanism (though people tended to use it
as such for hack value, and it may well have helped them).


Tom Duff discusses the Device in
http://www.lysator.liu.se/c/duffs-device.html. This is the definitive
reference to all points raised here about Duff's Device.


J
[Oops. -John]




--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.