| website | https://vaibhavsagar.com |
| https://twitter.com/vbhvsgr | |
| https://instagram.com/vbhvsgr |
| website | https://vaibhavsagar.com |
| https://twitter.com/vbhvsgr | |
| https://instagram.com/vbhvsgr |
Day 11 of Advent of Compiler Optimisations!
A clever loop that counts set bits using the "clear bottom bit" trick: value &= value - 1. Works great, generates tight assembly. But change one compiler flag to target a slightly newer CPU and something extraordinary happens to your loop. The compiler spots a pattern you didn't even know was there. What replaces your careful bit manipulation?
Read more: https://xania.org/202512/11-pop-goes-the-weasel-er-count
Watch: https://youtu.be/Hu0vu1tpZnc
I've written a series of blog posts, in which I write a #bytecode #compiler and a #virtualMachine for arithmetic in #Haskell. We explore the following topics in the series:
- Parsing arithmetic expressions to ASTs.
- Compiling ASTs to bytecode.
- Interpreting ASTs.
- Efficiently executing bytecode in a VM.
- Disassembling bytecode and decompiling opcodes for debugging and testing.
- Unit testing and property-based testing for our compiler and VM.
- Benchmarking our code to see how the different passes perform.
- All the while keeping an eye on performance.
The third and final post of the series that focuses on writing the virtual machine is now out: https://abhinavsarkar.net/posts/arithmetic-bytecode-vm/