News for hackers. Stuff that matters.
Re:Tom Duff on Duff's Device (1988) by userbinator on Saturday September 05, 2015 @10:57PM (#10176700)
I wonder what programmers at the time would think of CPUs eventually being so good at handling loops that unrolling changes from an optimisation technique to be performed manually, to one that compilers might sometimes do, to an anti-optimisation:

http://www.agner.org/optimize/blog/read.php?i=142

It is so important to economize the use of the micro-op cache that I would give the advice never to unroll loops.

http://lkml.iu.edu/hypermail/linux/kernel/0008.2/0171.html

by eliminating all instances of Duff's Device from the XFree86 4.0 server, the server shrunk in size by _half_ _a_ _megabyte_ (!!!), and was faster to boot

Re:Tom Duff on Duff's Device (1988) by TheCoelacanth on Sunday September 06, 2015 @12:59AM (#10176850)
It seems from his comments that the idea of a compiler being able to do it better in some circumstances wasn't completely outlandish.

> Don't try to be smarter than an over-clever C compiler that recognizes loops that implement block move or block clear and compiles them into machine idioms.

Re:Tom Duff on Duff's Device (1988) by CyberDildonics on Saturday September 05, 2015 @11:44PM (#10176772)
Some of that can be attributed to the fact that there are multiple integer and floating point units, so the loop counter is often totally inconsequential.
Re:Tom Duff on Duff's Device (1988) by CyberDildonics on Saturday September 05, 2015 @11:39PM (#10176768)
Funny that he is more famous for this than for inventing Porter-Duff compositing algebra, one of the cornerstones of modern image manipulation.
Re:Tom Duff on Duff's Device (1988) by versteegen on Sunday September 06, 2015 @12:58AM (#10176848)
Thanks for mentioning this. I found a nice article about it and generalisation to blend modes here: http://ssp.impulsetrain.com/porterduff.html
Re:Tom Duff on Duff's Device (1988) by protomyth on Saturday September 05, 2015 @09:53PM (#10176610)
"A second poster tried the test, but botched the implementation, proving only that with diligence it is possible to make anything run slowly."

This made me laugh. "with diligence it is possible to make anything run slowly" should be one of the truths carved into an obelisk outside every CompSci department or at least on a t-shirt.

Re:Tom Duff on Duff's Device (1988) by AceJohnny2 on Saturday September 05, 2015 @08:36PM (#10176463)
> (Actually, I have another revolting way to use switches to implement interrupt driven state machines but it's too horrid to go into.)

I'm really, really curious about what that code is.

Re:Tom Duff on Duff's Device (1988) by mikeash on Saturday September 05, 2015 @08:44PM (#10176476)
This is just a guess, but perhaps something like: http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html
Re:Tom Duff on Duff's Device (1988) by nraynaud on Saturday September 05, 2015 @11:42PM (#10176771)
I just used it a few minutes ago: https://github.com/nraynaud/webgcode/blob/gh-pages/interpola...

https://github.com/nraynaud/webgcode/blob/gh-pages/interpola...

One problem is the reset of the functions, I just created a makeshift exception, but I don't know how far I want to deviate form the norm.

I still don't know if it's a good idea, but that's what personal projects are for.

Re:Tom Duff on Duff's Device (1988) by jhallenworld on Saturday September 05, 2015 @11:35PM (#10176759)
This is a very useful technique for making event driven parsers. I remember being surprised that the case statements didn't all have to be in the same scoping level, but it's true.