Re: XCode/MMX: no automatic EMMS instruction
Re: XCode/MMX: no automatic EMMS instruction
- Subject: Re: XCode/MMX: no automatic EMMS instruction
- From: Eric Albert <email@hidden>
- Date: Wed, 16 Aug 2006 22:00:53 -0700
On Aug 16, 2006, at 8:37 AM, Mark Coniglio wrote:
I discovered today that XCode/GCC doesn't automatically produce the
emms instruction at the end of an MMX routine. The emms instruction
is required to restore proper floating point operation after using
MMX instructions.
See http://www.tommesani.com/MMXPrimer.html and http://
www.tacc.utexas.edu/services/userguides/intel/c_ug/linux336.htm
CodeWarrior automatically produces an emms at the end of the
routine, so all my MMX routines for Windows worked fine when
compiled under CW.
But, upon compiling the Universal Binary under XCode, things broke
in very unpredictable ways. I witnessed several weird bugs, some of
which had to do with floating point, and some of which appeared as
wacky behavior in QuickTime calls.
It's an easy fix -- just add the emms call at the end of your
assembly routine, e.g.
pop eax
pop ebx
#if TARGET_OS_MAC
emms
#endif
Note that I wrapped the emms with an #if/#endif since it costs 50
cycles to execute it -- and I don't want it twice when I compile
for Windows.
The cost of that single emms instruction is why GCC doesn't emit it
automatically for you. If GCC's own codegen results in MMX
instructions (which is very rare), it'll emit an emms. But if you
use MMX instructions in your assembly code, there's a reasonable
chance you might be trying to use MMX in the function you're
returning to too, and if we were to emit an emms at the end of your
current function you'd burn 50 cycles for something you didn't want.
On the other hand, if Visual Studio also automatically emits an emms
in this case I'd suggest filing a bug at bugreport.apple.com to
request that GCC do this.
I should also mention that on Mac OS X we tend to use SSE registers
and instructions far more heavily than MMX. We turn on SSE2 and SSE
floating point math by default, and we guarantee that Intel-based
Macs will always have at least SSE2. SSE code is often (though
admittedly not always) faster than the equivalent MMX code and
doesn't have the emms problem, so you might want to think about using
SSE.
Hope this helps,
Eric
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden