Cleanups and simplifications in x86 CPU feature detection
authorSøren Sandmann Pedersen <ssp@redhat.com>
Thu, 28 Jun 2012 19:53:14 +0000 (15:53 -0400)
committerSøren Sandmann Pedersen <ssp@redhat.com>
Wed, 20 Jun 2012 06:51:04 +0000 (02:51 -0400)
commit0c81957e9b4f83944075167ae27a955bb253e267
tree90510e08e9eabafc0eefdc33a2a98f3c6de00fa5
parent4d641c3803d508ba1eb40e61257949422ae2b90d
Cleanups and simplifications in x86 CPU feature detection

A new function pixman_cpuid() is added that runs the cpuid instruction
and returns the results. On GCC this function uses inline assembly; on
MSVC, the function calls the __cpuid intrinsic.

There is also a new function called have_cpuid() which detects whether
cpuid is available. On x86-64 and MSVC, it simply returns TRUE; on
x86-32 bit, it checks whether the 22nd bit of eflags can be
modified. On MSVC this does have the consequence that pixman will no
longer work CPUS without cpuid (ie., older than 486 and some 486
models).

These two functions together makes it possible to write a generic
detect_cpu_features() in plain C. This function is then used in a new
have_feature() function that checks whether a specific set of feature
bits is available.

Aside from the cleanups and simplifications, the main benefit from
this patch is that pixman now can do feature detection on x86-64, so
that newer instruction sets such as SSSE3 and SSE4.1 can be used. (And
apparently the assumption that x86-64 CPUs always have MMX and SSE2 is
no longer correct: Knight's Corner is x86-64, but doesn't have them).

V2: Rename the constants in the getisax() code, as pointed out by Alan
Coopersmith. Also reinstate the result variable and initialize
features to 0.

V3: Fixes for the fact that the upper 32 bits of a 64 bit register are
zeroed whenever the corresponding 32 bit register is written to.

V4: Fixes for the fact that in 32 bit mode, when gcc is not optimizing
there were not enough registers available. The new code uses the "a",
"b", "c", and "d" constraints instead, and has two separate versions
for 32 and 64 bit modes.
pixman/pixman-x86.c