Channels ▼

Walter Bright

Dr. Dobb's Bloggers

Porting D to the Mac: Epilog

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.

Related Reading

More Insights

Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.