3 ms·
Maybe useless, but the article is extremely intersting and easy to read. One can definitely try to read it. Amusing anecdote : During the very beginning of the
by wiz21c 8y ago
Maybe useless, but the article is extremely intersting and easy to read. One can definitely try to read it.
Amusing anecdote : During the very beginning of the 90’s, I happened to code a lot of very optimized code (3D engines) in assembler.
I was doing assembler because, well, that was the de facto way to get speed. So at that time, I forgot about the possibility
of writing things in C (and I had not access to a C compiler) -- a bit dumb of me. So, one day, tired of writing tedious assembler,
and at the same time discovering C, I rewrote one of my assembler program in C. BIG suprise, the C code was much
faster than my assembler. So I disassembled the generated code and understood what the compiler did. First, it used
very clever bit manipulations (unknown to me) to alter some comparisons I did. Second, it understood that
because my code was just a test that didn’t produce anything, then it didn’t need to generate any code. So
a big chunk of my C code was just not compiled (and rightly so). So the resulting program, was mostly doing nothing.
It was the first time I saw what an optimizing compiler means, I was totally blown away. I was beaten
at the optimization game by a program :-)
The other thing I understood that day is that an optimizer is no magic. It just carefully applies little
knowledge about optimization on little cases here and there. It basically automates what one would have
done to optimize some assembler code by hand (except for algorithmic optimization). It also means that
one can sleep well knowing that 90% of the chores of optimization are done automatically in a reliable
way. We all take that for granted but when I was around 20 years old, it was just super exciting.
- krylon 8y agoIn a previous job, I once tried to rewrite those small - tiny, really! - functions that were called all over the place in assembly, so I kind of looked at it from the opposite direction. The experience was both frustrating and elating. In the end, the "optimized" assembly code I could come up with was pretty much identical to the code generated by the compiler. So I missed that rush of showing the compiler who's boss. This is what led me to abandon the project very quickly. On the other hand, I was very relieved that my hand-written code was at least not worse than what the compiler could come up with. So at least I could get out with my dignity intact. To be fair, those small functions were so small and simple (no more than three or four instructions) that there really was only one obvious way to implement them in x86 assembly. So maybe my problem set was a bad choice. It was fun, though.
- eesmith 8y agoNo more than three or four instructions? See also https://en.wikipedia.org/wiki/Superoptimization https://en.wikipedia.org/wiki/Superoptimization .