Sunday, November 12, 2006
Happiness is knowing you still have "the touch"
For a long time I considered myself a "world class" x86 assembly language programmer when it came to squeezing the crap out of code to make it as tiny as possible (a talent too often ignored these days). Others try to make things fast, I mostly focused on making them small because the vast majority of code isn't terribly speed sensitive. The bulk of code in a program or operating system usually handles oddball cases, error paths, CPU errata, etc and isn't executed all that often, yet it MUST BE THERE for the code to be "correct". The smaller that necessary baggage is, the more memory is left over for running the code that does the useful things.
It has been a few years since I did any assembler programming though. Did I still remember all the dirty tricks, arcane minutia, and nasty swindles that are the stock and trade of a premier code tweaker looking for every last byte? I really wasn't sure.
So I've got this little program (actually its an API test suite) I've been evolving ever since the early 90's. Its a modest bit of assembler code, on the order of 12,000 lines with several thousand lines of C code thrown in as well.
Today I got "in the zone" for a few hours and whipped out about 400 lines of insanely compact assembler code. About 50 new functions and the new module weighed in just under 500 bytes. I just made the minor mods to integrate the new stuff into the project and the size of the whole dropped by a few kilobytes. Add 500 bytes of magic, and the whole goes down by 6X what was added. This is the way programs should evolve!
Yes, I still have "the touch", and the 400 lines of new assembler code functioned perfectly through 4,000+ testcase variations that use it very heavily.