From bc394e5a2d2bc99591281b505695994a84c97607 Mon Sep 17 00:00:00 2001 From: Uros Bizjak Date: Mon, 4 Sep 2017 20:34:06 +0200 Subject: [PATCH] mpx-os-support.h: New file. * gcc.target/i386/mpx/mpx-os-support.h: New file. * gcc.target/i386/mpx/mpx-check.h: Include mpx-os-support.h. From-SVN: r251683 --- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.target/i386/mpx/mpx-check.h | 14 ++------------ .../gcc.target/i386/mpx/mpx-os-support.h | 16 ++++++++++++++++ 3 files changed, 23 insertions(+), 12 deletions(-) create mode 100644 gcc/testsuite/gcc.target/i386/mpx/mpx-os-support.h diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 940c0dbd9ac..91aa16f5d36 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-09-04 Uros Bizjak + + * gcc.target/i386/mpx/mpx-os-support.h: New file. + * gcc.target/i386/mpx/mpx-check.h: Include mpx-os-support.h. + 2017-09-04 Bernd Edlinger PR target/77308 diff --git a/gcc/testsuite/gcc.target/i386/mpx/mpx-check.h b/gcc/testsuite/gcc.target/i386/mpx/mpx-check.h index d84b8bf0efa..e622934fe32 100644 --- a/gcc/testsuite/gcc.target/i386/mpx/mpx-check.h +++ b/gcc/testsuite/gcc.target/i386/mpx/mpx-check.h @@ -1,8 +1,8 @@ #include #include #include - #include "cpuid.h" +#include "mpx-os-support.h" static int __attribute__ ((noinline)) @@ -16,16 +16,6 @@ mpx_test (int, const char **); #define DEBUG -#define XSTATE_BNDREGS (1 << 3) - -/* This should be an intrinsic, but isn't. */ -static int xgetbv (unsigned x) -{ - unsigned eax, edx; - asm ("xgetbv" : "=a" (eax), "=d" (edx) : "c" (x)); - return eax; -} - static int check_osxsave (void) { @@ -44,7 +34,7 @@ main (int argc, const char **argv) return NORUNRES; /* Run MPX test only if host has MPX support. */ - if (check_osxsave () && (ebx & bit_MPX) && (xgetbv (0) & XSTATE_BNDREGS)) + if (check_osxsave () && (ebx & bit_MPX) && mpx_os_support ()) mpx_test (argc, argv); else { diff --git a/gcc/testsuite/gcc.target/i386/mpx/mpx-os-support.h b/gcc/testsuite/gcc.target/i386/mpx/mpx-os-support.h new file mode 100644 index 00000000000..8c9294d33a5 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/mpx/mpx-os-support.h @@ -0,0 +1,16 @@ +/* Check if the OS supports executing MPX instructions. */ + +#define XCR_XFEATURE_ENABLED_MASK 0x0 + +#define XSTATE_BNDREGS 0x8 + +static int +mpx_os_support (void) +{ + unsigned int eax, edx; + unsigned int ecx = XCR_XFEATURE_ENABLED_MASK; + + __asm__ ("xgetbv" : "=a" (eax), "=d" (edx) : "c" (ecx)); + + return (eax & XSTATE_BNDREGS) != 0; +} -- 2.30.2