5 ms·
Hacker’s Delight (2012)
- KingOfCoders 4y agoBioshock!
- cbisnett 4y agoThis 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.
- FabHK 4y agoYou 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.
- EdwardCoffin 4y agoThese 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.
- makach 4y agoyes. 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.
- smrtinsert 4y agoI have my physical copy of this around somewhere
- 2OEH8eoCRo0 4y agoMine 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.
- davegauer 4y agoHa ha, this falls firmly into the "I wish I needed to reference this more" category for me as well.
- kevin_thibedeau 4y agoI 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.
- AlotOfReading 4y agoIt 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.
- mtlmtlmtlmtl 4y agoSame. 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.
- huqedato 4y agoA fine book with a very misleading name. The book is about basic computer science and algorithms.
- AlotOfReading 4y agoIt'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.
- night-rider 4y agoReminded me of Smokers Delight by Nightmares on Wax: https://www.last.fm/music/Nightmares%20on%20Wax/Smokers%20Delight https://www.last.fm/music/Nightmares%20on%20Wax/Smokers%20De...
- fknorangesite 4y agoAnd Rapper's Delight before that.
- sjamaan 4y agoAnd Turkish Delight before that
- SeanLuke 4y agoThe 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.
- xhevahir 4y ago
- tintedfireglass 4y agoNice book but I feel the title should be something like principles of computer science or something of that sort.
- O__________O 4y agoTDLR: Author systematically collected little programming tricks, thematically organized them, and clearly explains them.
- deleted 4y ago[deleted]
- anonymoushn 4y agoThe 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
- mhh__ 4y agoNote that some fairly big hardware didn't have them either. Itanium and DEC Alpha didn't have integer divide IIRC. Cheap RISC-V also probably won't.
- fanf2 4y agoI 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.) I use it occasionally for things like optimizing tolower() https://news.ycombinator.com/item?id=31900872 https://news.ycombinator.com/item?id=31900872 and for popcount hacks https://dotat.at/prog/qp https://dotat.at/prog/qp or for quickly updating a log-linear histogram https://dotat.at/@/2022-07-15-histogram.html https://dotat.at/@/2022-07-15-histogram.html
- djmips 4y agoPeople on a site called Hacker News complaining about the name of a book called Hacker's Delight.
- throwaway787544 4y agoKids today and their "analysis of history from the present perspective". Sheesh!
- fefe23 4y agoCompilers 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. It really is a delight for hackers.
- anonymoushn 4y agoIn gcc 9.3, it seems like it stops applying this optimization after maybe 30 constants. Pretty weird.
- beeforpork 4y agoThis is not only about optimisation, but often it provides you the idiom for coding something. 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.
- svat 4y agoSee 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 https://cs.stanford.edu/~knuth/fasc1a.ps.gz ) (The first edition of Hacker's Delight is from 2002. HAKMEM is from 1972.) Independent recommendation here: https://twitter.com/pervognsen/status/1253135922553425921 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.
- harry8 4y agoIf you haven't already seen it check this out along similar lines: http://aggregate.org/MAGIC/ http://aggregate.org/MAGIC/ What else do you have?
- bigcat12345678 4y agoThis 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
- rol32 4y agoBeautiful book. But it's full of little mistakes. See the errata: https://ptgmedia.pearsoncmg.com/images/9780321842688/Errata/9780321842688errata031417.pdf 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.