written by Walter Bright
March 10, 2009
I've learned a few more things now that the Mac OSX version of dmd is out.
The first thing that happened was dmd failed on version 10.4 of OSX with a lovely “bus error” message. dmd was developed and tested on version 10.5. On Windows I was used to things working across the line of Windows versions, so this was a bit of a surprise. Various instructions for fixing it conflicted with each other, and I didn’t have a 10.4 system to test it on, so this involved sending each build to people who did until I got it right.
That got the compiler executables working on 10.4. But a more serious problem developed when trying to get the runtime library working on 10.4. The D programming language is designed to work with multiple threads, and the pthreads implementation on 10.4 is weak. The tradeoff is spending time trying to accommodate it, versus 10.4 being officially obsoleted when Apple updates OSX in the next year. We decided it probably wasn’t worth the effort to support 10.4.
Daveed Vandevoorde emailed me that the reason long doubles are 16 bytes long on the x86 Mac is so the struct layouts are binary compatible with those for the PowerPC Mac. This makes perfect sense. I was concerned that I was missing some efficiency reason.
The accuracy of some of the standard math library functions dropped from 19 decimal digits to 16. Those functions were implemented by simply calling the corresponding ones in the C standard library. I suspect the problem is that, in the implementation of the C versions, there is a conversion to double precision at some point which would completely account for the loss in accuracy. This provided the motivation to replace those functions with our own. Don Clugston implemented them to produce the full 19 digits of accuracy, and now the math functions reliably produce the same results across x86 platforms. One nice thing about the Mac coming only recently to the x86 platform is the math functions can assume modern CPU hardware, and so they use the newer and faster hardware instructions.
One nice lesson learned is that the test suite we have for dmd works. Once it passed the test suite, few OSX specific problems have cropped up in the wild.
A further change since the initial OSX release is that the release now includes the full dmd compiler source code, so you can build it and see how it works yourself. If you’re even more interested in how compilers work, I’m teaching a Compiler Construction seminar in the fall.
Thanks to Sean Kelly and Andrei Alexandrescu for reviewing a draft of this.