Dictionary    Maps    Thesaurus    Translate    Advanced >   


Tip: Click Thesaurus above for synonyms. Also, follow synonym links within the dictionary to find definitions from other sources.

1. The Jargon File (version 4.4.7, 29 Dec 2003)
Duff's device
 n.

    The most dramatic use yet seen of fall through in C, invented by Tom Duff
    when he was at Lucasfilm. Trying to optimize all the instructions he could
    out of an inner loop that copied data serially onto an output port, he
    decided to unroll it. He then realized that the unrolled version could be
    implemented by interlacing the structures of a switch and a loop:

       register n = (count + 7) / 8;      /* count > 0 assumed */

       switch (count % 8)
       {
       case 0:        do   *to = *from++;
       case 7:              *to = *from++;
       case 6:              *to = *from++;
       case 5:              *to = *from++;
       case 4:              *to = *from++;
       case 3:              *to = *from++;
       case 2:              *to = *from++;
       case 1:              *to = *from++;
                           while (--n > 0);
       }

    Shocking though it appears to all who encounter it for the first time, the
    device is actually perfectly valid, legal C. C's default fall through in
    case statements has long been its most controversial single feature; Duff
    observed that ?This code forms some sort of argument in that debate, but
    I'm not sure whether it's for or against.? Duff has discussed the device in
    detail at http://www.lysator.liu.se/c/duffs-device.html. Note that the
    omission of postfix ++ from *to was intentional (though confusing). Duff's
    device can be used to implement memory copy, but the original aim was to
    copy values serially into a magic IO register.

    [For maximal obscurity, the outermost pair of braces above could actually
    be removed ? GLS]


2. The Free On-line Dictionary of Computing (30 December 2018)
Duff's device

   The most dramatic use yet seen of fall through in C,
   invented by Tom Duff when he was at Lucasfilm.  Trying to
   bum all the instructions he could out of an inner loop that
   copied data serially onto an output port, he decided to unroll
   it.  He then realised that the unrolled version could be
   implemented by *interlacing* the structures of a switch and a
   loop:

     register n = (count + 7) / 8;      /* count > 0 assumed */

     switch (count % 8)
     {
     case 0:        do   *to = *from++;
     case 7:              *to = *from++;
     case 6:              *to = *from++;
     case 5:              *to = *from++;
     case 4:              *to = *from++;
     case 3:              *to = *from++;
     case 2:              *to = *from++;
     case 1:              *to = *from++;
                         while (--n > 0);
     }

   Shocking though it appears to all who encounter it for the
   first time, the device is actually perfectly valid, legal C.
   C's default fall through in case statements has long been
   its most controversial single feature; Duff observed that
   "This code forms some sort of argument in that debate, but I'm
   not sure whether it's for or against."

   [For maximal obscurity, the outermost pair of braces above
   could be actually be removed - GLS]

   [Jargon File]

   (2001-06-22)


Common Misspellings >
Most Popular Searches: Define Misanthrope, Define Pulchritudinous, Define Happy, Define Veracity, Define Cornucopia, Define Almuerzo, Define Atresic, Define URL, Definitions Of Words, Definition Of Get Up, Definition Of Quid Pro Quo, Definition Of Irreconcilable Differences, Definition Of Word, Synonyms of Repetitive, Synonym Dictionary, Synonym Antonyms. See our main index and map index for more details.

©2011-2024 ZebraWords.com - Define Yourself - The Search for Meanings and Meaning Means I Mean. All content subject to terms and conditions as set out here. Contact Us, peruse our Privacy Policy