diff options
author | Thiago Macieira <thiago.macieira@nokia.com> | 2010-08-24 11:52:09 (GMT) |
---|---|---|
committer | Thiago Macieira <thiago.macieira@nokia.com> | 2010-08-24 13:01:11 (GMT) |
commit | ebf9d5dd5174b7c82fec83b56d71a59d5277bd51 (patch) | |
tree | 1de900a0d5ff17e8653f0fa2f16549e569276974 | |
parent | d9b567288f301e44abedebf5b9b553c2878f2c77 (diff) | |
download | Qt-ebf9d5dd5174b7c82fec83b56d71a59d5277bd51.zip Qt-ebf9d5dd5174b7c82fec83b56d71a59d5277bd51.tar.gz Qt-ebf9d5dd5174b7c82fec83b56d71a59d5277bd51.tar.bz2 |
Properly implement the CPU feature disabling in qsimd.cpp.
Don't use ^=, since that might enable a feature that wasn't detected.
The new use is:
export QT_NO_CPU_FEATURE="<feature1> [<feature2>]"
Reviewed-by: Benjamin Poulain
-rw-r--r-- | src/corelib/tools/qsimd.cpp | 157 |
1 files changed, 60 insertions, 97 deletions
diff --git a/src/corelib/tools/qsimd.cpp b/src/corelib/tools/qsimd.cpp index 2472449..c34644c 100644 --- a/src/corelib/tools/qsimd.cpp +++ b/src/corelib/tools/qsimd.cpp @@ -112,11 +112,6 @@ static inline uint detectProcessorFeatures() } } - if (qgetenv("QT_NO_IWMMXT").toInt()) - features ^= IWMMXT; - if (qgetenv("QT_NO_NEON").toInt()) - features ^= NEON; - ::qt_safe_close(auxv); return features; } @@ -125,11 +120,9 @@ static inline uint detectProcessorFeatures() #if defined(QT_HAVE_IWMMXT) // runtime detection only available when running as a previlegied process - static const bool doIWMMXT = !qgetenv("QT_NO_IWMMXT").toInt(); - features = doIWMMXT ? IWMMXT : 0; + features = IWMMXT; #elif defined(QT_HAVE_NEON) - static const bool doNEON = !qgetenv("QT_NO_NEON").toInt(); - features = doNEON ? NEON : 0; + features = NEON; #endif return features; @@ -284,29 +277,6 @@ static inline uint detectProcessorFeatures() if (feature_result & (1u << 28)) features |= AVX; -#if defined(QT_HAVE_MMX) - if (qgetenv("QT_NO_MMX").toInt()) - features ^= MMX; -#endif - if (qgetenv("QT_NO_MMXEXT").toInt()) - features ^= MMXEXT; - -#if defined(QT_HAVE_3DNOW) - if (qgetenv("QT_NO_3DNOW").toInt()) - features ^= MMX3DNOW; -#endif - if (qgetenv("QT_NO_3DNOWEXT").toInt()) - features ^= MMX3DNOWEXT; - -#if defined(QT_HAVE_SSE) - if (qgetenv("QT_NO_SSE").toInt()) - features ^= SSE; -#endif -#if defined(QT_HAVE_SSE2) - if (qgetenv("QT_NO_SSE2").toInt()) - features ^= SSE2; -#endif - return features; } @@ -358,28 +328,7 @@ static inline uint detectProcessorFeatures() if (feature_result & (1u << 28)) features |= AVX; -#if defined(QT_HAVE_MMX) - if (qgetenv("QT_NO_MMX").toInt()) - features ^= MMX; -#endif - if (qgetenv("QT_NO_MMXEXT").toInt()) - features ^= MMXEXT; - -#if defined(QT_HAVE_3DNOW) - if (qgetenv("QT_NO_3DNOW").toInt()) - features ^= MMX3DNOW; -#endif - if (qgetenv("QT_NO_3DNOWEXT").toInt()) - features ^= MMX3DNOWEXT; - -#if defined(QT_HAVE_SSE) - if (qgetenv("QT_NO_SSE").toInt()) - features ^= SSE; -#endif -#if defined(QT_HAVE_SSE2) - if (qgetenv("QT_NO_SSE2").toInt()) - features ^= SSE2; -#endif + return features; } #elif defined(__ia64__) @@ -395,64 +344,78 @@ static inline uint detectProcessorFeatures() } #endif +/* + * Use kdesdk/scripts/generate_string_table.pl to update the table below. + * Here's the data (don't forget the ONE leading space): + mmx + mmxext + mmx3dnow + mmx3dnowext + sse + sse2 + cmov + iwmmxt + neon + sse3 + ssse3 + sse4.1 + sse4.2 + avx + */ + +// begin generated +static const char features_string[] = + " mmx\0" + " mmxext\0" + " mmx3dnow\0" + " mmx3dnowext\0" + " sse\0" + " sse2\0" + " cmov\0" + " iwmmxt\0" + " neon\0" + " sse3\0" + " ssse3\0" + " sse4.1\0" + " sse4.2\0" + " avx\0" + "\0"; + +static const int features_indices[] = { + 0, 5, 13, 23, 36, 41, 47, 53, + 61, 67, 73, 80, 88, 96, -1 +}; +// end generated + +const int features_count = (sizeof features_indices - 1) / (sizeof features_indices[0]); + uint qDetectCPUFeatures() { static QBasicAtomicInt features = Q_BASIC_ATOMIC_INITIALIZER(-1); if (features != -1) return features; - features = detectProcessorFeatures(); + uint f = detectProcessorFeatures(); + QByteArray disable = qgetenv("QT_NO_CPU_FEATURE"); + if (!disable.isEmpty()) { + disable.prepend(' '); + for (int i = 0; i < features_count; ++i) { + if (disable.contains(features_string + features_indices[i])) + f &= ~(1 << i); + } + } + + features = f; return features; } void qDumpCPUFeatures() { - /* - * Use kdesdk/scripts/generate_string_table.pl to update the table below. - * Here's the data: -mmx -mmxext -mmx3dnow -mmx3dnowext -sse -sse2 -cmov -iwmmxt -neon -sse3 -ssse3 -sse4.1 -sse4.2 -avx - */ - static const char features_string[] = - "mmx\0" - "mmxext\0" - "mmx3dnow\0" - "mmx3dnowext\0" - "sse\0" - "sse2\0" - "cmov\0" - "iwmmxt\0" - "neon\0" - "sse3\0" - "ssse3\0" - "sse4.1\0" - "sse4.2\0" - "avx\0" - "\0"; - - static const int features_indices[] = { - 0, 4, 11, 20, 32, 36, 41, 46, - 53, 58, 63, 69, 76, 83, -1 - }; - const int features_count = (sizeof features_indices - 1) / (sizeof features_indices[0]); - uint features = qDetectCPUFeatures(); printf("Processor features: "); for (int i = 0; i < features_count; ++i) { if (features & (1 << i)) - printf(" %s", features_string + features_indices[i]); + printf("%s", features_string + features_indices[i]); } puts(""); } |