summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2012-08-14 14:07:31 +0200
committerQt by Nokia <qt-info@nokia.com>2012-08-15 15:20:39 +0200
commit732fc614dab0434b0a977889f326ea0910901b94 (patch)
tree6eff535190ba37e9ab3d1629329951ab3d3d15e0 /src
parent555e4e05f4f98f524e108fba0fb236406f2e2b2f (diff)
Disable CPUID checking with GCC 4.2 or older
This is not the first time that GCC 4.2 on Mac has produced bad code surrounding the CPUID instruction (see also commit 81d1f79a7f4b0f67d71). So declare it broken beyond repair and don't run the instruction at all. Instead, initialise the set of features found to be exactly that which we detected at compile-time. For that reason, we can also disable the runtime checking of the processor (minFeatures == detected features). At the time of this commit, only the draw helpers and one QImage helper make use of the runtime detection. Since the detection now switches to compile-time, QtGui will start carrying dead code for GCC 4.2 and earlier: it will never run the SSE2/SSSE3 code on 32-bit builds. (GCC 4.2 does not support AVX, so that code won't be built) Note: all Clang versions report that they are GCC 4.2, so we need to exclude it from the test; ICC reports the same version as the system's GCC. Change-Id: I43f168a9480a2479c6444eea175782b2eadc2ab2 Reviewed-by: Gunnar Sletta <gunnar.sletta@nokia.com>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/tools/qsimd.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/corelib/tools/qsimd.cpp b/src/corelib/tools/qsimd.cpp
index df41e6bd6d..244ed2ef75 100644
--- a/src/corelib/tools/qsimd.cpp
+++ b/src/corelib/tools/qsimd.cpp
@@ -379,6 +379,28 @@ QBasicAtomicInt qt_cpu_features = Q_BASIC_ATOMIC_INITIALIZER(0);
void qDetectCpuFeatures()
{
+#if defined(Q_CC_GNU) && !defined(Q_CC_CLANG) && !defined(Q_CC_INTEL)
+# if (__GNUC__ * 100 + __GNUC_MINOR__) < 403
+ // GCC 4.2 (at least the one that comes with Apple's XCode, on Mac) is
+ // known to be broken beyond repair in dealing with the inline assembly
+ // above. It will generate bad code that could corrupt important registers
+ // like the PIC register. The behaviour of code after this function would
+ // be totally unpredictable.
+ //
+ // For that reason, simply forego the CPUID check at all and return the set
+ // of features that we found at compile time, through the #defines from the
+ // compiler. This should at least allow code to execute, even if none of
+ // the specialised code found in QtGui and elsewhere will ever be enabled
+ // (it's the user's fault for using a broken compiler).
+ //
+ // This also disables the runtime checking that the processor actually
+ // contains all the features that the code required. Qt 4 ran for years
+ // like that, so it shouldn't be a problem.
+
+ qt_cpu_features.store(minFeature | QSimdInitialized);
+ return;
+# endif
+#endif
uint f = detectProcessorFeatures();
QByteArray disable = qgetenv("QT_NO_CPU_FEATURE");
if (!disable.isEmpty()) {