A small question about Duff's Device

  • Thread starter Christopher Benson-Manica
  • Start date
C

Christopher Benson-Manica

(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)?
 
D

Dave Vandervies

(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
 
M

Michael Wojcik

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top