Make the CPU detection much more efficient in user code
authorThiago Macieira <thiago.macieira@intel.com>
Mon, 2 Apr 2012 23:52:28 +0000 (20:52 -0300)
committerQt by Nokia <qt-info@nokia.com>
Mon, 2 Jul 2012 08:09:31 +0000 (10:09 +0200)
commit978937ab4a44179224a3021f89555bfa988fe687
tree2dbe36298a7218566549a7fe3dc7c059a3b0ac8c
parentf58390e0f495e229d9f2f1301c3a9dec978af9c2
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>
src/corelib/tools/qsimd.cpp
src/corelib/tools/qsimd_p.h
src/gui/image/qimage.cpp
src/gui/image/qjpeghandler.cpp
src/gui/painting/qdrawhelper.cpp