Hacker’s Delight (2012)
books.google.com
books.google.com
When I was doing a lot of reverse engineering and vulnerability research work this book gave some really great insight into some of the compiler optimizations that I would come across. Highly recommended for anyone trying to take their skills to the next level.
Independent recommendation here: https://twitter.com/pervognsen/status/1253135922553425921
> The bitwise techniques book will shock you because it's basically Hacker's Delight: Knuth Edition and it is very, very good and useful.
Itanium and DEC Alpha didn't have integer divide IIRC.
Cheap RISC-V also probably won't.
Still, this is a standard textbook for little tricks. Knowing these kind of tricks used to be enough to make you a hacker in the original sense. I greatly enjoyed reading it and still recommend it even today.
It really is a delight for hackers.
E.g.: 'is x a power of two'? How to write this in a programming language? However unoptimised: how to actually code this test?
HD tells you the idiom: (x & (x-1)) == 0, for any x != 0.
I use it occasionally for things like optimizing tolower() https://news.ycombinator.com/item?id=31900872 and for popcount hacks https://dotat.at/prog/qp or for quickly updating a log-linear histogram https://dotat.at/@/2022-07-15-histogram.html
https://ptgmedia.pearsoncmg.com/images/9780321842688/Errata/...
There are numerous other bugs that were found and submitted, but for unknown reasons don't yet appear in the errata listing above.
What else do you have?
It's worth noting that some of the solutions aren't optimal for modern devices with conditional moves. In some cases you can get equal or better performance with straightforward code than some of the stuff in the book that goes out of its way to avoid branching control flow.
Now that I'm doing more application development it's sitting on my bookshelf looking neglected.
In the 1980s the term "hacker" was possibly conflated with "cracker" by stupids in the media, and came to mean a software pirate or kid who broke into the Pentagon. But the proper meaning still hasn't been lost with the graybeards among us.
I think it's not necessarily due to stupidity that media outlets eschewed the term "cracker."