This is a really great book for anyone interested in compiler development, JIT compilation of higher-level languages, reverse engineering, or anything that involves understanding or generating assembly instructions. This is not a book about hacking from the perspective of breaking into systems or finding and exploiting vulnerabilities in software. The term Hacker in the title is a reference to an early meaning of the word that referred to someone who liked to tinker and understand how things worked.
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.
You might be thinking about a different book? Hacker's Delight is mostly about bit fiddling (counting bits, finding the longest string of 1-bits, multiplication and division, Gray code, CRC, the famous approximate reciprocal square root) and such.
These are just the kinds of things that an optimizing compiler can use, so would be quite useful for reverse engineering the product of an optimizing compiler to figure out what it is doing.
yes. the book could definitively be named differently. I skimmed through the free pages and I came to the same conclusion. Probably a great book, but not for me since I am a higher level developer that benefit from the outcome of books like these.
See also Knuth's TAOCP section 7.1.3 "Bitwise Tricks & Techniques" which makes references to this book Hacker's Delight and covers some similar ground, in Knuth's unique style. (Published as part of Vol 4A in 2011, earlier as Volume 4 Fascicle 1 in 2009, and earlier draft available online as pre-fascicle 1A: https://cs.stanford.edu/~knuth/fasc1a.ps.gz ) (The first edition of Hacker's Delight is from 2002. HAKMEM is from 1972.)
The section on computing magic numbers for integer division is quite useful if you find yourself implementing a vectorized version of an algorithm that calls for integer division or integer modulus, since these instructions typically don't exist
Compilers have improved a lot, to the point where you don't need to read this book for many of the tricks. For example, if you divide by a constant in gcc, you can see the tricks from this book being applied if you look at the disassembly.
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.
I have copies of both the first and second editions of Hacker’s Delight. The second edition is mostly the same, but with a few additions and corrections. (Also printed on thicker paper with a smaller text area so it looks 2.2x thicker for 1.1x the content.)
This book has been used in quite a few coding interview circa 2012 when I started interviewing for my first job. That kind of ruined the joy of cracking hacky coding problem of the book. Sigh
Mine taunts me in plain view from my bookshelf. It's a cool book but I have little use for what it provides so I haven't been able to dig into it much.
I use mine on occasion. It's particularly useful when targeting architectures that don't have modern intrinsics for special operations.
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.
It has a pretty cool niche as a set of toy problems to verify cryptography tooling and I've found some of the recipes inside useful inspiration for constant time programming and other constrained domains. It's not as useful as it used to be for exactly the reasons you mentioned though.
Same. But sometimes I like skimming it just as a distraction. There's something so satisfying about seeing these tricks I'm far too stupid to come up with on my own. A couple of times, I've had some breakthroughs when stuck on an unrelated problem, while reading this book, because the "psychedelic hackery" sort of leads me down an alley I wouldn't otherwise have thought of, due to some superficial similarity.
It's not misleading, it's just an older meaning of the word "hacker" and one that still exists in the name of this site. Hacker's delight is a spiritual successor to the HAKMEM memo from the 70s. Guy Steele even wrote the foreword.
The term hacker has a long and storied history. A hacker is someone who makes hacks. A hack is a thing, typically a piece of code, which must be appreciated for its aesthetic beauty, regardless of whether it's particularly useful. [This term was obviously originally used sarcastically]. People strove to become hackers. It was a badge of honor.
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.
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.