Wednesday, June 07, 2006

Hacker's Delight?

It arrived! Cool book, in spite of the fact that it wastes a lot of pages on proofs. I trust the author, I don't need no stinkin' proofs. I would have preferred twice as many bit twiddling tricks! And shouldn't the title be "Hackers' Delight"?

I need the quickest way to count trailing zero's, that sort of thing. As I said before, the NSA covertly prevented the ability to do any such important things (popcount as well) quickly on desktop machines. This book gives ideas and code how to do it a hundred times slower than a dedicated instruction would have done it*, but it's still very useful. *Don't forget that a mispredicted branch incurs a penalty of at least 10 cycles.

Due to MSB issues, the usability of some code is questionable to Pascal users, but for the tactical engine, I use Pascal only to generate MASM assembly anyway, and the ultimate goal is to code directly in 64-bit assembly.

It is insane not to write it in anything else but Assembly. People argue that the language used is less important than the efficiency of pruning heuristics and eval function, but they are assuming that I will write highly sub-optimal code. Even if I would do that, using assembly would outweigh that.

So me being an Assembly hacker might very well offset my currently limited Go knowledge as it will be applied to various heuristics, because the difference between compiler-optimized optimal 32-bit C code and human-optimized 64-bit assembly code is enormous - sometimes a factor 10 or more. Because using 64-bit registers allows for a radically different, highly efficient approach of some aspects, and coding at the metal is incomparably better than being at the mercy of the optimizer.