diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2012-04-02 20:52:28 -0300 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-07-02 10:09:31 +0200 |
commit | 978937ab4a44179224a3021f89555bfa988fe687 (patch) | |
tree | 2dbe36298a7218566549a7fe3dc7c059a3b0ac8c /src/gui/image/qimage.cpp | |
parent | f58390e0f495e229d9f2f1301c3a9dec978af9c2 (diff) |
Make the CPU detection much more efficient in user code
First, check that the option in question hasn't been already enabled
by the compiler, via compiler switches. If it has been, then we don't
need to verify anything, and we can assume that it's safe to use such
instructions. For example, on an x86-64 build, qCpuHasFeature(SSE2) is
always a constant true.
If the compile-time check fails, then we proceed to try and detect the
processor features at runtime. But instead of insisting on a call to
qDetectCPUFeatures, allow the code using the detection to read from a
variable and simply test it for values. Only if the variable isn't
initialised should it make a function call. The Q_ASSUME allows this
code to be very efficient even with multiple uses of qCpuHasFeature.
Change the uninitialised value from -1 to 0 so that simpler
instructions can be used to check for non-initialisation.
The qDetectCPUFeatures function is renamed to qDetectCpuFeatures to
match the Qt coding style and also to catch uses this code that need
to be adapted.
Change-Id: I24ca5a6ad21075e2e249e1a4f8f5057b8f68ce7c
Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/gui/image/qimage.cpp')
-rw-r--r-- | src/gui/image/qimage.cpp | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp index 8536e59440..b16ae2ffce 100644 --- a/src/gui/image/qimage.cpp +++ b/src/gui/image/qimage.cpp @@ -3270,12 +3270,8 @@ static InPlace_Image_Converter inplace_converter_map[QImage::NImageFormats][QIma void qInitImageConversions() { - const uint features = qDetectCPUFeatures(); - Q_UNUSED(features); - -#ifdef QT_COMPILER_SUPPORTS_SSE2 #ifdef QT_COMPILER_SUPPORTS_AVX - if (features & AVX) { + if (qCpuHasFeature(AVX)) { extern bool convert_ARGB_to_ARGB_PM_inplace_avx(QImageData *data, Qt::ImageConversionFlags); inplace_converter_map[QImage::Format_ARGB32][QImage::Format_ARGB32_Premultiplied] = convert_ARGB_to_ARGB_PM_inplace_avx; @@ -3283,29 +3279,33 @@ void qInitImageConversions() converter_map[QImage::Format_RGB888][QImage::Format_RGB32] = convert_RGB888_to_RGB32_avx; converter_map[QImage::Format_RGB888][QImage::Format_ARGB32] = convert_RGB888_to_RGB32_avx; converter_map[QImage::Format_RGB888][QImage::Format_ARGB32_Premultiplied] = convert_RGB888_to_RGB32_avx; - } else + return; + } #endif - if (features & SSE2) { - extern bool convert_ARGB_to_ARGB_PM_inplace_sse2(QImageData *data, Qt::ImageConversionFlags); - inplace_converter_map[QImage::Format_ARGB32][QImage::Format_ARGB32_Premultiplied] = convert_ARGB_to_ARGB_PM_inplace_sse2; +#if defined(QT_COMPILER_SUPPORTS_SSE2) && !defined(__AVX__) + if (qCpuHasFeature(SSE2)) { + extern bool convert_ARGB_to_ARGB_PM_inplace_sse2(QImageData *data, Qt::ImageConversionFlags); + inplace_converter_map[QImage::Format_ARGB32][QImage::Format_ARGB32_Premultiplied] = convert_ARGB_to_ARGB_PM_inplace_sse2; #ifdef QT_COMPILER_SUPPORTS_SSSE3 - if (features & SSSE3) { - extern void convert_RGB888_to_RGB32_ssse3(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags); - converter_map[QImage::Format_RGB888][QImage::Format_RGB32] = convert_RGB888_to_RGB32_ssse3; - converter_map[QImage::Format_RGB888][QImage::Format_ARGB32] = convert_RGB888_to_RGB32_ssse3; - converter_map[QImage::Format_RGB888][QImage::Format_ARGB32_Premultiplied] = convert_RGB888_to_RGB32_ssse3; - } -#endif + if (qCpuHasFeature(SSSE3)) { + extern void convert_RGB888_to_RGB32_ssse3(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags); + converter_map[QImage::Format_RGB888][QImage::Format_RGB32] = convert_RGB888_to_RGB32_ssse3; + converter_map[QImage::Format_RGB888][QImage::Format_ARGB32] = convert_RGB888_to_RGB32_ssse3; + converter_map[QImage::Format_RGB888][QImage::Format_ARGB32_Premultiplied] = convert_RGB888_to_RGB32_ssse3; } +#endif + return; + } #endif // SSE2 #ifdef QT_COMPILER_SUPPORTS_NEON - if (features & NEON) { + if (qCpuHasFeature(NEON)) { extern void convert_RGB888_to_RGB32_neon(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags); converter_map[QImage::Format_RGB888][QImage::Format_RGB32] = convert_RGB888_to_RGB32_neon; converter_map[QImage::Format_RGB888][QImage::Format_ARGB32] = convert_RGB888_to_RGB32_neon; converter_map[QImage::Format_RGB888][QImage::Format_ARGB32_Premultiplied] = convert_RGB888_to_RGB32_neon; + return; } #endif } |