Chris Quenelle's Weblog
Thoughts on developer tools.

All | Dbx | Development Tools | Life in General | OpenSolaris | plus | Software Philosophy | Sun Studio

fav comics

« Previous day (Jul 16, 2006) | Main | Next day (Jul 18, 2006) »
20060717 Monday July 17, 2006

Instruction set selection in Sun Studio and gcc (Grudge match: -xarch versus -fast)

The right way to control compiler code generation has proven to be a bit a little tricky. Every compiler needs a way for the user say what kind of machines the program should run on. Different machines have different chips, different chips support different instructions. Closely related to this is a way to say which machines the program should run best on.

  1. SPARC spoiled us. We were used to a list of instructions sets that was almost linear in its availability. Version N of SPARC always included all the instructions from version N-1. (Apart from a 10 year old anecdote which I omitted. You can thank me later. ;-))

  2. Solaris spoiled us. When 64-bit Solaris came out, the transition was so compatible that the compiler group just treated it as another set of instructions they could use. So -xarch=v8 means 32-bit code and -xarch=v9 mean 64-bit code. Nobody thought 64-bits was a whole different universe.

  3. Something we invented called “macro options” messed us up a little bit.

The Sun compilers in Sun Studio 11 have a general option called -xtarget which we call a “macro option”. This option “expands” into settings for -xarch, -xchip and -xcache. In theory this helps the user because they don't have to remember the details of every Sun box. In practice I'm not sure how many people use it, but we feel compelled never to remove anything. To see all the expansions of -xtarget in Sun Studio 11 check the docs. I think we smartened up after a while and stopped building the marketing name of every Sun system into the compiler, it got to be a maintenance nightmare.

The group of related options I'm talking about goes like this:

Compared to gcc which uses these options:

Introducing -m64

It turns out that having one option (-xarch) control both instruction set selection and the 32/64 ABIness of your program wasn't a good long-term solution. When people used -xarch=v9 to select a 64-bit program, we ran into glitches. Because most of our options will silently override a previous instance of the option, our macros options caused us grief. Users were saying “cc -xarch=v9 -xtarget=foo” and getting a 32-bit program. More common was to use “-xarch=v9 -fast” and get a 32-bit program. Which of course gives different results than “-fast -xarch=v9”. The next release of the Sun Studio compilers will have -m32 and -m64 options to control the data model of the program, and with luck we'll have something like a -xisa option to select groups of instructions.

Another related quirk is the need for an option to select hybrid data models. As long as there are 32-bit and 64-bit programs, each with their own strengths, someone will want to get the best of both worlds. If you want to use SPARC 64-bit registers, but want to follow the 32-bit ABI, you can use what we called the “v8plus” architecture. Seongbae wrote about it in his blog, with a link to the specification. I couldn't find a better description of it, so maybe I'll summarize it one day. To support this kind of hybrid, we ended up turning our -xarch option into a bit of a cross-product. We now have -xarch=v8a/v8b/v8plusa/v8plusb etc, etc. The proper place to control this would have been to define an option like -m32plus. I remember hearing hallway gossip about something like this on intel, so don't think sparc is the only architecture with this kind of mess. ;-)

You can also read the list of -xarch values in the -xarch documentation in the Sun Studio 11 compiler docs.

Posted by Chris Quenelle ( Jul 17 2006, 03:08:16 PM PDT ) - Permalink - -

Older blog entries:

mug shot Chris Quenelle is a tools developer at Sun Microsystems. He's worked on performance and debugging tools at Sun for more than 10 years. He reads comic books and science fiction, and has more tivos than he can keep track of.

Calendar

RSS Feeds

Search

Links

Navigation

Referers