Re: Converting Optlink from Assembler to C - Reboot
bearophile <bearophileHUGS <at> lycos.com>
2009-12-01 00:35:16 GMT
A nice article, thank you for writing it for us for free (I used to pay to read similar texts).
>I had the job at the time of converting a huge (and very successful) electronic schematic editor, DASH,
from assembler into C. In C it could then be recompiled for 32 bits, and even ported to other platforms like
the Sun workstations. The conversion took months, but was a big success.<
Sounds like a so much bug-prone job that the probability of having a final working product seem small. I
guess you have translated it part-by-part, keeping it functional all the time, as you are doing with optlink.
>9. Optlink has no unit tests. Writing them would require understanding what the various functions do, and
I won't know precisely what they are supposed to do until most of the program is converted.<
Translating a largish program from a language to a different language is a good way to convince most
programmers that unit tests are a Good Thing. Unit tests make this work quite simpler. And many good
programs eventually need to be translated, it's not an uncommon event.
>Although I have not run any speed tests, I expect the performance of the non-I/O bound code to be about 30%
slower. Since a linker tends to be I/O bound, the actual performance loss probably will be about 10%, which
I can live with.<
We'll see. Modern C compilers, like the Intel one, LLVM or GCC 4.4 sometimes give surprises
Modern C
compilers also use CPU instructions that were not available in the past (you have to use compilation flags
for Pentium4/Core2 or similar CPUs of course).
>The difference in object code size is primarily due to the assembler having done register assignments
that cross over multiple function calls. There's just a lot less pushing and popping of parameters.<
In GCC there are annotations (that LLVM doesn't support yet) that allow to nail variables into registers.
One Haskell compiler (GHC) uses this feature a lot, it's explained here:
http://www.cse.unsw.edu.au/~pls/thesis/davidt-thesis.pdf
(Continue reading)