From: H.J. Lu Date: Tue, 2 Oct 2012 20:31:40 +0000 (+0000) Subject: Check SSE and YMM state support for -march=native X-Git-Tag: releases/gcc-4.6.4~342 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=742b2e2c12528af24ff364bf83045b80b31ea0c1;p=thirdparty%2Fgcc.git Check SSE and YMM state support for -march=native Backported from mainline PR target/54741 * config/i386/driver-i386.c (XCR_XFEATURE_ENABLED_MASK): New. (XSTATE_FP): Likewise. (XSTATE_SSE): Likewise. (XSTATE_YMM): Likewise. (host_detect_local_cpu): Disable AVX, FMA, FMA4 and XOP if SSE and YMM states aren't supported. From-SVN: r192004 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 29065b818b1b..3bdfda68265a 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,16 @@ +2012-10-02 H.J. Lu + + Backported from mainline + 2012-10-02 H.J. Lu + + PR target/54741 + * config/i386/driver-i386.c (XCR_XFEATURE_ENABLED_MASK): New. + (XSTATE_FP): Likewise. + (XSTATE_SSE): Likewise. + (XSTATE_YMM): Likewise. + (host_detect_local_cpu): Disable AVX, FMA, FMA4 and XOP if SSE + and YMM states aren't supported. + 2012-09-21 Richard Guenther PR middle-end/54638 diff --git a/gcc/config/i386/driver-i386.c b/gcc/config/i386/driver-i386.c index 1871ae485044..3e25a72f63d5 100644 --- a/gcc/config/i386/driver-i386.c +++ b/gcc/config/i386/driver-i386.c @@ -1,5 +1,5 @@ /* Subroutines for the gcc driver. - Copyright (C) 2006, 2007, 2008, 2010 Free Software Foundation, Inc. + Copyright (C) 2006-2012 Free Software Foundation, Inc. This file is part of GCC. @@ -398,6 +398,7 @@ const char *host_detect_local_cpu (int argc, const char **argv) unsigned int has_fma = 0, has_fma4 = 0, has_xop = 0; unsigned int has_bmi = 0, has_tbm = 0; unsigned int has_rdrnd = 0, has_f16c = 0, has_fsgsbase = 0; + unsigned int has_osxsave = 0; bool arch; @@ -439,6 +440,7 @@ const char *host_detect_local_cpu (int argc, const char **argv) has_sse4_1 = ecx & bit_SSE4_1; has_sse4_2 = ecx & bit_SSE4_2; has_avx = ecx & bit_AVX; + has_osxsave = ecx & bit_OSXSAVE; has_cmpxchg16b = ecx & bit_CMPXCHG16B; has_movbe = ecx & bit_MOVBE; has_popcnt = ecx & bit_POPCNT; @@ -461,6 +463,25 @@ const char *host_detect_local_cpu (int argc, const char **argv) has_fsgsbase = ebx & bit_FSGSBASE; } + /* Get XCR_XFEATURE_ENABLED_MASK register with xgetbv. */ +#define XCR_XFEATURE_ENABLED_MASK 0x0 +#define XSTATE_FP 0x1 +#define XSTATE_SSE 0x2 +#define XSTATE_YMM 0x4 + if (has_osxsave) + asm (".byte 0x0f; .byte 0x01; .byte 0xd0" + : "=a" (eax), "=d" (edx) + : "c" (XCR_XFEATURE_ENABLED_MASK)); + + /* Check if SSE and YMM states are supported. */ + if ((eax & (XSTATE_SSE | XSTATE_YMM)) == (XSTATE_SSE | XSTATE_YMM)) + { + has_avx = 0; + has_fma = 0; + has_fma4 = 0; + has_xop = 0; + } + /* Check cpuid level of extended features. */ __cpuid (0x80000000, ext_level, ebx, ecx, edx);