xf86-video-intel: src/sna/sna_cpu.c
Chris Wilson
ickle at kemper.freedesktop.org
Tue Mar 26 09:18:06 PDT 2013
src/sna/sna_cpu.c | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
New commits:
commit 0b479504c82bd81c0b93de0e6529eae928eea3bf
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Tue Mar 26 16:12:30 2013 +0000
sna: Check for OS support of AVX/AVX2 before use
If the OS has not initialised support for the extended instructions,
then their use may result in general protection faults.
Based on code by Thiago Macieira.
Reported-by: Arjan van de Ven <arjan at linux.intel.com>
Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
diff --git a/src/sna/sna_cpu.c b/src/sna/sna_cpu.c
index ab4942b..ff83ba5 100644
--- a/src/sna/sna_cpu.c
+++ b/src/sna/sna_cpu.c
@@ -39,11 +39,17 @@
#define bit_AVX2 (1<<5)
#endif
+#define xgetbv(index,eax,edx) \
+ __asm__ ("xgetbv" : "=a"(eax), "=d"(edx) : "c" (index))
+
+#define has_YMM 0x1
+
unsigned sna_cpu_detect(void)
{
unsigned max = __get_cpuid_max(false, 0);
unsigned int eax, ebx, ecx, edx;
unsigned features = 0;
+ unsigned extra = 0;
if (max >= 1) {
__cpuid(1, eax, ebx, ecx, edx);
@@ -59,7 +65,14 @@ unsigned sna_cpu_detect(void)
if (ecx & bit_SSE4_2)
features |= SSE4_2;
- if (ecx & bit_AVX)
+ if (ecx & bit_OSXSAVE) {
+ unsigned int bv_eax, bv_ecx;
+ xgetbv(0, bv_eax, bv_ecx);
+ if ((bv_eax & 6) == 6)
+ extra |= has_YMM;
+ }
+
+ if (extra & has_YMM && ecx & bit_AVX)
features |= AVX;
if (edx & bit_MMX)
@@ -74,7 +87,7 @@ unsigned sna_cpu_detect(void)
if (max >= 7) {
__cpuid_count(7, 0, eax, ebx, ecx, edx);
- if (ebx & bit_AVX2)
+ if (extra & has_YMM && ebx & bit_AVX2)
features |= AVX2;
}
More information about the xorg-commit
mailing list