GNOME Bugzilla – Bug 308412
GCC 4.0 version in Fedora Core 4 can't handle the mmx code
Last modified: 2005-08-13 21:30:11 UTC
Distribution/Version: Fedora Core 4 This bug report is about an issue that arose tangentially in bug #303796, specifically in comment #9 there; comment #24 there describes the current state of affairs. Here is the problem: If you try to build GIMP in FC4, with default configuration, on an i386 system with mmx support, the build fails in gimp-composite-mmx.c. At the moment the workaround is to specify --disable-mmx when configuring, which is obviously not an ideal solution. Note that this problem does not arise on AMD64.
*** Bug 309199 has been marked as a duplicate of this bug. ***
Confirmed. Adding -mmmx and -msse into CFLAGS when enable MMX/SSE should fix this.
Created attachment 48618 [details] [review] configure.in patch Proposed configure.in patch to add the required flags.
Is this really correct? Does adding those CFLAGS serve only to *allow* mmx/sse assembly, or does it also cause gcc to generate mmx/sse instructions on its own? If the latter, this is not acceptible, since use of these extensions need to be selectable at runtime.
From GCC manual about -mmmx and friends: <quote> These switches enable or disable the use of built-in functions that allow direct access to the MMX, SSE, SSE2, SSE3 and 3Dnow extensions of the instruction set. See X86 Built-in Functions, for details of the functions enabled and disabled by these switches. To have SSE/SSE2 instructions generated automatically from floating-point code, see -mfpmath=sse. </quote> So I guess these options will only enable, and not generate mmx/sse instructions automatically unless we explicitly use vector extensions or -mfpmath=sse. It is strange that I do not need to specify the flags when building GIMP with mmx/sse enabled under an older version of GCC. Is this actually a fix for the flags behavior bug?
Comment #4 and #24 in bug #303796 claim otherwise. At any rate, the configure.in patch needs work, since -mmmx and -msse aren't available on all compilers, and it seems to ignore SSE2. The same technique configure figures out which altivec switch to use can be applied here.
SSE2 uses xmm* registers, so -msse should be enough to fix the clobber lists problem. From the discussion, it seems that future GCC will not compile the current code without -mmmx/-msse specified (need info from GCC folks). And simply have -mmmx/-msse is not a good idea to build binaries that will run on any x86. Should we just fix the code with #ifdef, or specify appropriate CFLAGS for *each* of processor specific files? Either cases sound ugly to me.
Removing NEEDINFO because it is not appropriate for this bug to be in "ignore" mode, even if the correct fix is not yet clear. Also confirming on the basis of comment #2.
Created attachment 48809 [details] [review] Patch to determine appropriate mmx and sse compiler flags This patch will make configure determine which compiler flags should be used to compile MMX/SSE code when appropriate. Only one set of flags are checked in this patch. Flags for other compilers can be added as needed.
Created attachment 48811 [details] [review] Correct version of patch to determine appropriate mmx and sse compiler flags This is the correct version of the patch.
This should be committed to both branches then.
This isn't just a fedora issue -- it happens on debian sid as well (on an AMD sempron 32). The patch fixes it.
Actually no, the flags should be limited to the composite dir, just like the altivec ones are. It'd be nice if the whole flag detection stuff stuff became an m4 macro too.
Re: Comment #12, adding "-mmmx -msse" to CFLAGS causes an Illegal Instruction error on gimp start on machines with MMX but no SSE, like early Athlons.
Ahh, I was up to report a similar bugreport myself and then stepped over this one. I got the same issues with "-mmmx -msse" using GCC 4.0.1 (and here it was NOT FC4 so it's a general compiler specific thing), Applying the updated patch from the attachment below solved the issues for me. Compiled went on correctly. Just in case, wanted to add my feedback to it.
Created attachment 50017 [details] [review] Patch defines MMX_EXTRA_CFLAGS with -mmmx and -msse flags as appropriate Third time lucky? This patch checks whether the compiler understands the -mmmx and -msse flags. This information is used to define MMX_EXTRA_CFLAGS. The Makefile of the composite directory uses this new define.
It didn't break my Win32 build and made my Linux build work again - so there is at least something right with it :)
I don't think this is good enough, since the CFLAGS may cause mmx/sse instruction generation in any file in the composite directory, and some of those are used unconditionally. Better to apply the specific flag needed to only the files that actually use it.
I've done a fair bit of work in HEAD to only compile files with the actual mmx/sse/etc. code using the respective CFLAGS. Let's see how it tests out there before backporting it.
OK, backported to 2.2. Closing as FIXED.