A small question about Duff's Device

Discussion in 'C Programming' started by Christopher Benson-Manica, Oct 21, 2004.

  1. (Fear not, I have no intention of actually using it!)

    Was there a particular reason Duff chose to unroll the loop 8 times,
    as opposed to some other number of times (besides some reason having
    to do with the original application of the device)?

    --
    Christopher Benson-Manica | I *should* know what I'm talking about - if I
    ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
    Christopher Benson-Manica, Oct 21, 2004
    #1
    1. Advertising

  2. In article <cl6urn$gtb$>,
    Christopher Benson-Manica <> wrote:
    >(Fear not, I have no intention of actually using it!)
    >
    >Was there a particular reason Duff chose to unroll the loop 8 times,
    >as opposed to some other number of times (besides some reason having
    >to do with the original application of the device)?


    A power of two would make the math that's left for the compiler to do
    simpler (it can be done entirely with bitwise operators rather than
    having to do arithmetic).

    Other than style or application-specific reasons, I don't see why 8
    would be inherently a better or worse choice than any other power of two,
    except possibly that it's a sweet spot wrt the law of diminishing returns
    (less unrolling gives less improvement, more unrolling doesn't get enough
    extra improvement to be worth the extra typing).


    dave

    --
    Dave Vandervies
    Much as we might regret it sometimes, comp.lang.c is not actually
    normative.
    --Richard Heathfield in comp.lang.c
    Dave Vandervies, Oct 21, 2004
    #2
    1. Advertising

  3. In article <cl7e0p$9k8$>, (Dave Vandervies) writes:
    > In article <cl6urn$gtb$>,
    > Christopher Benson-Manica <> wrote:
    > >(Fear not, I have no intention of actually using it!)
    > >
    > >Was there a particular reason Duff chose to unroll the loop 8 times,

    >
    > Other than style or application-specific reasons, I don't see why 8
    > would be inherently a better or worse choice than any other power of two,
    > except possibly that it's a sweet spot wrt the law of diminishing returns
    > (less unrolling gives less improvement, more unrolling doesn't get enough
    > extra improvement to be worth the extra typing).


    And more unrolling could result in making the loop too large to fit
    in an instruction cache line, severely impairing performance.

    This is just the sort of thing that makes optimization context-
    dependent and tricky.


    --
    Michael Wojcik
    Michael Wojcik, Oct 21, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jamie Risk

    Duff Device reference ...

    Jamie Risk, Oct 16, 2004, in forum: C Programming
    Replies:
    1
    Views:
    406
    Michael Wojcik
    Oct 20, 2004
  2. Jan Richter

    duff's device / loop unriolling

    Jan Richter, Aug 19, 2005, in forum: C Programming
    Replies:
    19
    Views:
    671
    Tim Rentsch
    Aug 29, 2005
  3. Hallvard B Furuseth

    Duff's Device

    Hallvard B Furuseth, Sep 28, 2006, in forum: C Programming
    Replies:
    11
    Views:
    636
    Hallvard B Furuseth
    Oct 3, 2006
  4. Replies:
    10
    Views:
    698
  5. yawnmoth

    how does duff's device work?

    yawnmoth, Nov 9, 2008, in forum: C Programming
    Replies:
    7
    Views:
    315
    Phil Carmody
    Nov 9, 2008
Loading...

Share This Page