Duff's Device and Coroutines (2008)
Duff's Device, a unique C code by Tom Duff in 1983, features an 8x-unrolled while loop with a switch statement for efficient data processing. Despite limited reuse, it sparked adaptations and discussions. Modern alternatives like threads and coroutines exist.
Read original articleThe article discusses Duff's Device, a unique piece of C code created by Tom Duff in 1983. It is an 8x-unrolled while loop combined with a switch statement, allowing for efficient processing of data. Despite its complexity, Duff's Device is considered a rare and specific tool, with limited reuse value. The code is valid in C due to the nature of switch statements and labels. Over the years, variations and discussions about its usage have emerged, including Bjarne Stroustrup's adaptation in The C++ Programming Language and Simon Tatham's C coroutine implementation for event-driven programming. Duff himself confirmed the use of a similar concept for specific applications in the past. The article also mentions modern alternatives like threads and coroutines with real stacks for similar functionalities. Various comments from readers provide additional insights and references to related implementations like protothreads in Contiki OS.
Related
As you learn Forth, it learns from you (1981)
The Forth programming language is highlighted for its unique features like extensibility, speed, and efficiency. Contrasted with Basic, Forth's threaded code system and data handling methods make it versatile.
Own Constant Folder in C/C++
Neil Henning discusses precision issues in clang when using the sqrtps intrinsic with -ffast-math, suggesting inline assembly for instruction selection. He introduces a workaround using __builtin_constant_p for constant folding optimization, enhancing code efficiency.
Optimizing the Roc parser/compiler with data-oriented design
The blog post explores optimizing a parser/compiler with data-oriented design (DoD), comparing Array of Structs and Struct of Arrays for improved performance through memory efficiency and cache utilization. Restructuring data in the Roc compiler showcases enhanced efficiency and performance gains.
Continuations by Example
Continuations are powerful in control-flow constructs, enabling exceptions, search, threads, generators, and coroutines. They capture remaining computation steps, aiding in non-deterministic choices and efficient iteration over data structures.
Weekend projects: getting silly with C
The C programming language's simplicity and expressiveness, despite quirks, influence other languages. Unconventional code structures showcase creativity and flexibility, promoting unique coding practices. Subscription for related content is encouraged.
Related
As you learn Forth, it learns from you (1981)
The Forth programming language is highlighted for its unique features like extensibility, speed, and efficiency. Contrasted with Basic, Forth's threaded code system and data handling methods make it versatile.
Own Constant Folder in C/C++
Neil Henning discusses precision issues in clang when using the sqrtps intrinsic with -ffast-math, suggesting inline assembly for instruction selection. He introduces a workaround using __builtin_constant_p for constant folding optimization, enhancing code efficiency.
Optimizing the Roc parser/compiler with data-oriented design
The blog post explores optimizing a parser/compiler with data-oriented design (DoD), comparing Array of Structs and Struct of Arrays for improved performance through memory efficiency and cache utilization. Restructuring data in the Roc compiler showcases enhanced efficiency and performance gains.
Continuations by Example
Continuations are powerful in control-flow constructs, enabling exceptions, search, threads, generators, and coroutines. They capture remaining computation steps, aiding in non-deterministic choices and efficient iteration over data structures.
Weekend projects: getting silly with C
The C programming language's simplicity and expressiveness, despite quirks, influence other languages. Unconventional code structures showcase creativity and flexibility, promoting unique coding practices. Subscription for related content is encouraged.