diff mbox series

Reconstruct i386 testsuite with __builtin_cpu_supports

Message ID 20220506075708.84250-1-haochen.jiang@intel.com
State New
Headers show
Series Reconstruct i386 testsuite with __builtin_cpu_supports | expand

Commit Message

Jiang, Haochen May 6, 2022, 7:57 a.m. UTC
Hi all,

There are some check files in i386 testsuite are written before the function __builtin_cpu_supports is introduced. All of them are using __get_cpuid_count. This patch aims to reconstruct the i386 testsuite with __builtin_cpu_supports so that we can have a much clearer code.

Regtested on x86_64-pc-linux-gnu. Ok for trunk?

Also when writting this patch, I also find some files in testsuite that might be useless currently. For example, in the file gcc/testsuite/gcc.target/i386/sse-os-support.h, it always return 1. And there are also some files will no longer be included at all with this patch. Should we remove those files when we have time?

BRs,
Haochen

gcc/testsuite/ChangeLog:

	* gcc.target/i386/adx-check.h: Change bit check to
	__builtin_cpu_supports.
	* gcc.target/i386/aes-avx-check.h: Ditto.
	* gcc.target/i386/aes-check.h: Ditto.
	* gcc.target/i386/avx-check.h: Ditto.
	* gcc.target/i386/avx2-check.h: Ditto.
	* gcc.target/i386/avx512-check.h: Ditto.
	* gcc.target/i386/bmi-check.h: Ditto.
	* gcc.target/i386/bmi2-check.h: Ditto.
	* gcc.target/i386/f16c-check.h: Ditto.
	* gcc.target/i386/fma-check.h: Ditto.
	* gcc.target/i386/fma4-check.h: Ditto.
	* gcc.target/i386/lzcnt-check.h: Ditto.
	* gcc.target/i386/mmx-3dnow-check.h: Ditto.
	* gcc.target/i386/mmx-check.h: Ditto.
	* gcc.target/i386/pclmul-avx-check.h: Ditto.
	* gcc.target/i386/pclmul-check.h: Ditto.
	* gcc.target/i386/rtm-check.h: Ditto.
	* gcc.target/i386/sha-check.h: Ditto.
	* gcc.target/i386/sse-check.h: Ditto.
	* gcc.target/i386/sse2-check.h: Ditto.
	* gcc.target/i386/sse3-check.h: Ditto.
	* gcc.target/i386/sse4_1-check.h: Ditto.
	* gcc.target/i386/sse4_2-check.h: Ditto.
	* gcc.target/i386/sse4a-check.h: Ditto.
	* gcc.target/i386/ssse3-check.h: Ditto.
	* gcc.target/i386/xop-check.h: Ditto.
---
 gcc/testsuite/gcc.target/i386/adx-check.h     | 10 +---
 gcc/testsuite/gcc.target/i386/aes-avx-check.h | 14 +----
 gcc/testsuite/gcc.target/i386/aes-check.h     | 11 +---
 gcc/testsuite/gcc.target/i386/avx-check.h     | 12 +---
 gcc/testsuite/gcc.target/i386/avx2-check.h    | 20 +------
 gcc/testsuite/gcc.target/i386/avx512-check.h  | 59 +++++++------------
 gcc/testsuite/gcc.target/i386/bmi-check.h     | 11 +---
 gcc/testsuite/gcc.target/i386/bmi2-check.h    | 10 +---
 gcc/testsuite/gcc.target/i386/f16c-check.h    | 10 +---
 gcc/testsuite/gcc.target/i386/fma-check.h     | 11 +---
 gcc/testsuite/gcc.target/i386/fma4-check.h    | 11 +---
 gcc/testsuite/gcc.target/i386/lzcnt-check.h   | 11 +---
 .../gcc.target/i386/mmx-3dnow-check.h         | 11 +---
 gcc/testsuite/gcc.target/i386/mmx-check.h     | 11 +---
 .../gcc.target/i386/pclmul-avx-check.h        | 14 +----
 gcc/testsuite/gcc.target/i386/pclmul-check.h  | 11 +---
 gcc/testsuite/gcc.target/i386/rtm-check.h     | 10 +---
 gcc/testsuite/gcc.target/i386/sha-check.h     | 10 +---
 gcc/testsuite/gcc.target/i386/sse-check.h     | 11 +---
 gcc/testsuite/gcc.target/i386/sse2-check.h    | 11 +---
 gcc/testsuite/gcc.target/i386/sse3-check.h    | 11 +---
 gcc/testsuite/gcc.target/i386/sse4_1-check.h  | 11 +---
 gcc/testsuite/gcc.target/i386/sse4_2-check.h  | 11 +---
 gcc/testsuite/gcc.target/i386/sse4a-check.h   | 11 +---
 gcc/testsuite/gcc.target/i386/ssse3-check.h   | 11 +---
 gcc/testsuite/gcc.target/i386/xop-check.h     | 11 +---
 26 files changed, 73 insertions(+), 272 deletions(-)

Comments

Uros Bizjak May 6, 2022, 8:26 a.m. UTC | #1
On Fri, May 6, 2022 at 9:57 AM Haochen Jiang <haochen.jiang@intel.com> wrote:
>
> Hi all,
>
> There are some check files in i386 testsuite are written before the function __builtin_cpu_supports is introduced. All of them are using __get_cpuid_count. This patch aims to reconstruct the i386 testsuite with __builtin_cpu_supports so that we can have a much clearer code.
>
> Regtested on x86_64-pc-linux-gnu. Ok for trunk?

I don't think *_os_support calls should be removed. IIRC,
__builtin_cpu_supports function checks if the feature is supported by
CPU, whereas *_os_supports calls check via xgetbv if OS supports
handling of new registers.

Uros.

>
> Also when writting this patch, I also find some files in testsuite that might be useless currently. For example, in the file gcc/testsuite/gcc.target/i386/sse-os-support.h, it always return 1. And there are also some files will no longer be included at all with this patch. Should we remove those files when we have time?
>
> BRs,
> Haochen
>
> gcc/testsuite/ChangeLog:
>
>         * gcc.target/i386/adx-check.h: Change bit check to
>         __builtin_cpu_supports.
>         * gcc.target/i386/aes-avx-check.h: Ditto.
>         * gcc.target/i386/aes-check.h: Ditto.
>         * gcc.target/i386/avx-check.h: Ditto.
>         * gcc.target/i386/avx2-check.h: Ditto.
>         * gcc.target/i386/avx512-check.h: Ditto.
>         * gcc.target/i386/bmi-check.h: Ditto.
>         * gcc.target/i386/bmi2-check.h: Ditto.
>         * gcc.target/i386/f16c-check.h: Ditto.
>         * gcc.target/i386/fma-check.h: Ditto.
>         * gcc.target/i386/fma4-check.h: Ditto.
>         * gcc.target/i386/lzcnt-check.h: Ditto.
>         * gcc.target/i386/mmx-3dnow-check.h: Ditto.
>         * gcc.target/i386/mmx-check.h: Ditto.
>         * gcc.target/i386/pclmul-avx-check.h: Ditto.
>         * gcc.target/i386/pclmul-check.h: Ditto.
>         * gcc.target/i386/rtm-check.h: Ditto.
>         * gcc.target/i386/sha-check.h: Ditto.
>         * gcc.target/i386/sse-check.h: Ditto.
>         * gcc.target/i386/sse2-check.h: Ditto.
>         * gcc.target/i386/sse3-check.h: Ditto.
>         * gcc.target/i386/sse4_1-check.h: Ditto.
>         * gcc.target/i386/sse4_2-check.h: Ditto.
>         * gcc.target/i386/sse4a-check.h: Ditto.
>         * gcc.target/i386/ssse3-check.h: Ditto.
>         * gcc.target/i386/xop-check.h: Ditto.
> ---
>  gcc/testsuite/gcc.target/i386/adx-check.h     | 10 +---
>  gcc/testsuite/gcc.target/i386/aes-avx-check.h | 14 +----
>  gcc/testsuite/gcc.target/i386/aes-check.h     | 11 +---
>  gcc/testsuite/gcc.target/i386/avx-check.h     | 12 +---
>  gcc/testsuite/gcc.target/i386/avx2-check.h    | 20 +------
>  gcc/testsuite/gcc.target/i386/avx512-check.h  | 59 +++++++------------
>  gcc/testsuite/gcc.target/i386/bmi-check.h     | 11 +---
>  gcc/testsuite/gcc.target/i386/bmi2-check.h    | 10 +---
>  gcc/testsuite/gcc.target/i386/f16c-check.h    | 10 +---
>  gcc/testsuite/gcc.target/i386/fma-check.h     | 11 +---
>  gcc/testsuite/gcc.target/i386/fma4-check.h    | 11 +---
>  gcc/testsuite/gcc.target/i386/lzcnt-check.h   | 11 +---
>  .../gcc.target/i386/mmx-3dnow-check.h         | 11 +---
>  gcc/testsuite/gcc.target/i386/mmx-check.h     | 11 +---
>  .../gcc.target/i386/pclmul-avx-check.h        | 14 +----
>  gcc/testsuite/gcc.target/i386/pclmul-check.h  | 11 +---
>  gcc/testsuite/gcc.target/i386/rtm-check.h     | 10 +---
>  gcc/testsuite/gcc.target/i386/sha-check.h     | 10 +---
>  gcc/testsuite/gcc.target/i386/sse-check.h     | 11 +---
>  gcc/testsuite/gcc.target/i386/sse2-check.h    | 11 +---
>  gcc/testsuite/gcc.target/i386/sse3-check.h    | 11 +---
>  gcc/testsuite/gcc.target/i386/sse4_1-check.h  | 11 +---
>  gcc/testsuite/gcc.target/i386/sse4_2-check.h  | 11 +---
>  gcc/testsuite/gcc.target/i386/sse4a-check.h   | 11 +---
>  gcc/testsuite/gcc.target/i386/ssse3-check.h   | 11 +---
>  gcc/testsuite/gcc.target/i386/xop-check.h     | 11 +---
>  26 files changed, 73 insertions(+), 272 deletions(-)
>
> diff --git a/gcc/testsuite/gcc.target/i386/adx-check.h b/gcc/testsuite/gcc.target/i386/adx-check.h
> index cfed1a38483..bed5dcca385 100644
> --- a/gcc/testsuite/gcc.target/i386/adx-check.h
> +++ b/gcc/testsuite/gcc.target/i386/adx-check.h
> @@ -1,5 +1,4 @@
>  #include <stdlib.h>
> -#include "cpuid.h"
>
>  static void adx_test (void);
>
> @@ -11,13 +10,8 @@ static void __attribute__ ((noinline)) do_test (void)
>  int
>  main ()
>  {
> -  unsigned int eax, ebx, ecx, edx;
> -
> -  if (!__get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx))
> -    return 0;
> -
> -  /* Run ADX test only if host has ADX support.  */
> -  if (ebx & bit_ADX)
> +  /* Check cpu support for ADX.  */
> +  if (__builtin_cpu_supports ("adx"))
>      {
>        do_test ();
>  #ifdef DEBUG
> diff --git a/gcc/testsuite/gcc.target/i386/aes-avx-check.h b/gcc/testsuite/gcc.target/i386/aes-avx-check.h
> index f2a4ead4014..74bf597ead4 100644
> --- a/gcc/testsuite/gcc.target/i386/aes-avx-check.h
> +++ b/gcc/testsuite/gcc.target/i386/aes-avx-check.h
> @@ -2,8 +2,6 @@
>  #include <stdio.h>
>  #endif
>  #include <stdlib.h>
> -#include "cpuid.h"
> -#include "avx-os-support.h"
>
>  static void aes_avx_test (void);
>
> @@ -17,15 +15,9 @@ do_test (void)
>  int
>  main ()
>  {
> -  unsigned int eax, ebx, ecx, edx;
> -
> -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> -    return 0;
> -
> -  /* Run AES + AVX test only if host has AES + AVX support.  */
> -  if (((ecx & (bit_AVX | bit_OSXSAVE | bit_AES))
> -       == (bit_AVX | bit_OSXSAVE | bit_AES))
> -      && avx_os_support ())
> +  /* Check cpu support for AES and AVX.  */
> +  if (__builtin_cpu_supports ("avx")
> +      && __builtin_cpu_supports ("aes"))
>      {
>        do_test ();
>  #ifdef DEBUG
> diff --git a/gcc/testsuite/gcc.target/i386/aes-check.h b/gcc/testsuite/gcc.target/i386/aes-check.h
> index 7e794423e47..7c3a3b324a7 100644
> --- a/gcc/testsuite/gcc.target/i386/aes-check.h
> +++ b/gcc/testsuite/gcc.target/i386/aes-check.h
> @@ -1,8 +1,6 @@
>  #include <stdio.h>
>  #include <stdlib.h>
>
> -#include "cpuid.h"
> -
>  static void aes_test (void);
>
>  static void
> @@ -15,13 +13,8 @@ do_test (void)
>  int
>  main ()
>  {
> -  unsigned int eax, ebx, ecx, edx;
> -
> -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> -    return 0;
> -
> -  /* Run AES test only if host has AES support.  */
> -  if (ecx & bit_AES)
> +  /* Check cpu support for AES.  */
> +  if (__builtin_cpu_supports ("aes"))
>      {
>        do_test ();
>  #ifdef DEBUG
> diff --git a/gcc/testsuite/gcc.target/i386/avx-check.h b/gcc/testsuite/gcc.target/i386/avx-check.h
> index 7ddca9d7b80..4a3dbc257bc 100644
> --- a/gcc/testsuite/gcc.target/i386/avx-check.h
> +++ b/gcc/testsuite/gcc.target/i386/avx-check.h
> @@ -1,7 +1,5 @@
>  #include <stdlib.h>
> -#include "cpuid.h"
>  #include "m256-check.h"
> -#include "avx-os-support.h"
>
>  static void avx_test (void);
>
> @@ -15,14 +13,8 @@ do_test (void)
>  int
>  main ()
>  {
> -  unsigned int eax, ebx, ecx, edx;
> -
> -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> -    return 0;
> -
> -  /* Run AVX test only if host has AVX support.  */
> -  if (((ecx & (bit_AVX | bit_OSXSAVE)) == (bit_AVX | bit_OSXSAVE))
> -      && avx_os_support ())
> +  /* Check cpu support for AVX.  */
> +  if (__builtin_cpu_supports ("avx"))
>      {
>        do_test ();
>  #ifdef DEBUG
> diff --git a/gcc/testsuite/gcc.target/i386/avx2-check.h b/gcc/testsuite/gcc.target/i386/avx2-check.h
> index 25bed5e0da6..2bc3c4425bb 100644
> --- a/gcc/testsuite/gcc.target/i386/avx2-check.h
> +++ b/gcc/testsuite/gcc.target/i386/avx2-check.h
> @@ -1,7 +1,5 @@
>  #include <stdlib.h>
> -#include "cpuid.h"
>  #include "m256-check.h"
> -#include "avx-os-support.h"
>
>  static void avx2_test (void);
>
> @@ -10,25 +8,11 @@ static void __attribute__ ((noinline)) do_test (void)
>    avx2_test ();
>  }
>
> -static int
> -check_osxsave (void)
> -{
> -  unsigned int eax, ebx, ecx, edx;
> -
> -  __cpuid (1, eax, ebx, ecx, edx);
> -  return (ecx & bit_OSXSAVE) != 0;
> -}
> -
>  int
>  main ()
>  {
> -  unsigned int eax, ebx, ecx, edx;
> -
> -  if (!__get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx))
> -    return 0;
> -
> -  /* Run AVX2 test only if host has AVX2 support.  */
> -  if (check_osxsave () && (ebx & bit_AVX2) && avx_os_support ())
> +  /* Check cpu support for AVX2.  */
> +  if (__builtin_cpu_supports ("avx2"))
>      {
>        do_test ();
>  #ifdef DEBUG
> diff --git a/gcc/testsuite/gcc.target/i386/avx512-check.h b/gcc/testsuite/gcc.target/i386/avx512-check.h
> index 0ad9064f637..339c79070c9 100644
> --- a/gcc/testsuite/gcc.target/i386/avx512-check.h
> +++ b/gcc/testsuite/gcc.target/i386/avx512-check.h
> @@ -1,7 +1,5 @@
>  #include <stdlib.h>
> -#include "cpuid.h"
>  #include "m512-check.h"
> -#include "avx512f-os-support.h"
>
>  #ifndef DO_TEST
>  #define DO_TEST do_test
> @@ -25,81 +23,66 @@ do_test (void)
>  }
>  #endif
>
> -static int
> -check_osxsave (void)
> -{
> -  unsigned int eax, ebx, ecx, edx;
> -
> -  __cpuid (1, eax, ebx, ecx, edx);
> -  return (ecx & bit_OSXSAVE) != 0;
> -}
> -
>  int
>  main ()
>  {
> -  unsigned int eax, ebx, ecx, edx;
> -
> -  if (!__get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx))
> -    return 0;
> -
> -  /* Run AVX512 test only if host has ISA support.  */
> -  if (check_osxsave ()
> -      && (ebx & bit_AVX512F)
> +  /* Check cpu support for AVX512.  */
> +  if (__builtin_cpu_supports ("avx512f")
>  #ifdef AVX512VL
> -      && (ebx & bit_AVX512VL)
> +      && __builtin_cpu_supports ("avx512vl")
>  #endif
>  #ifdef AVX512ER
> -      && (ebx & bit_AVX512ER)
> +      && __builtin_cpu_supports ("avx512er")
>  #endif
>  #ifdef AVX512CD
> -      && (ebx & bit_AVX512CD)
> +      && __builtin_cpu_supports ("avx512cd")
>  #endif
>  #ifdef AVX512DQ
> -      && (ebx & bit_AVX512DQ)
> +      && __builtin_cpu_supports ("avx512dq")
>  #endif
>  #ifdef AVX512BW
> -      && (ebx & bit_AVX512BW)
> +      && __builtin_cpu_supports ("avx512bw")
>  #endif
>  #ifdef AVX512IFMA
> -      && (ebx & bit_AVX512IFMA)
> +      && __builtin_cpu_supports ("avx512ifma")
>  #endif
>  #ifdef AVX512VBMI
> -      && (ecx & bit_AVX512VBMI)
> +      && __builtin_cpu_supports ("avx512vbmi")
>  #endif
>  #ifdef AVX5124FMAPS
> -      && (edx & bit_AVX5124FMAPS)
> +      && __builtin_cpu_supports ("avx5124fmaps")
>  #endif
>  #ifdef AVX5124VNNIW
> -      && (edx & bit_AVX5124VNNIW)
> +      && __builtin_cpu_supports ("avx5124vnniw")
>  #endif
>  #ifdef AVX512VPOPCNTDQ
> -      && (ecx & bit_AVX512VPOPCNTDQ)
> +      && __builtin_cpu_supports ("avx512vpopcntdq")
>  #endif
>  #ifdef AVX512BITALG
> -      && (ecx & bit_AVX512BITALG)
> +      && __builtin_cpu_supports ("avx512bitalg")
>  #endif
>  #ifdef GFNI
> -      && (ecx & bit_GFNI)
> +      && __builtin_cpu_supports ("gfni")
>  #endif
>  #ifdef AVX512VBMI2
> -      && (ecx & bit_AVX512VBMI2)
> +      && __builtin_cpu_supports ("avx512vbmi2")
>  #endif
>  #ifdef AVX512VNNI
> -      && (ecx & bit_AVX512VNNI)
> +      && __builtin_cpu_supports ("avx512vnni")
>  #endif
>  #ifdef AVX512FP16
> -      && (edx & bit_AVX512FP16)
> +      && __builtin_cpu_supports ("avx512fp16")
>  #endif
>  #ifdef VAES
> -      && (ecx & bit_VAES)
> +      && __builtin_cpu_supports ("vaes")
>  #endif
>  #ifdef VPCLMULQDQ
> -      && (ecx & bit_VPCLMULQDQ)
> +      && __builtin_cpu_supports ("vpclmulqdq")
>  #endif
>  #ifdef AVX512VP2INTERSECT
> -      && (edx & bit_AVX512VP2INTERSECT)
> +      && __builtin_cpu_supports ("avx512vp2intersect")
>  #endif
> -      && avx512f_os_support ())
> +      )
>      {
>        DO_TEST ();
>  #ifdef DEBUG
> diff --git a/gcc/testsuite/gcc.target/i386/bmi-check.h b/gcc/testsuite/gcc.target/i386/bmi-check.h
> index 1973f3b6468..6af0291a947 100644
> --- a/gcc/testsuite/gcc.target/i386/bmi-check.h
> +++ b/gcc/testsuite/gcc.target/i386/bmi-check.h
> @@ -1,8 +1,6 @@
>  #include <stdio.h>
>  #include <stdlib.h>
>
> -#include "cpuid.h"
> -
>  static void bmi_test (void);
>
>  static void
> @@ -15,13 +13,8 @@ do_test (void)
>  int
>  main ()
>  {
> -  unsigned int eax, ebx, ecx, edx;
> -
> -  if (!__get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx))
> -    return 0;
> -
> -  /* Run BMI test only if host has BMI support.  */
> -  if (ebx & bit_BMI)
> +  /* Check cpu support for BMI.  */
> +  if (__builtin_cpu_supports ("bmi"))
>      {
>        do_test ();
>  #ifdef DEBUG
> diff --git a/gcc/testsuite/gcc.target/i386/bmi2-check.h b/gcc/testsuite/gcc.target/i386/bmi2-check.h
> index ba91ef9b780..75c4d8d9616 100644
> --- a/gcc/testsuite/gcc.target/i386/bmi2-check.h
> +++ b/gcc/testsuite/gcc.target/i386/bmi2-check.h
> @@ -1,6 +1,5 @@
>  #include <stdio.h>
>  #include <stdlib.h>
> -#include "cpuid.h"
>
>  static void bmi2_test (void);
>
> @@ -14,13 +13,8 @@ do_test (void)
>  int
>  main ()
>  {
> -  unsigned int eax, ebx, ecx, edx;
> -
> -  if (!__get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx))
> -    return 0;
> -
> -  /* Run BMI2 test only if host has BMI2 support.  */
> -  if (ebx & bit_BMI2)
> +  /* Check cpu support for BMI2.  */
> +  if (__builtin_cpu_supports ("bmi2"))
>      {
>        do_test ();
>  #ifdef DEBUG
> diff --git a/gcc/testsuite/gcc.target/i386/f16c-check.h b/gcc/testsuite/gcc.target/i386/f16c-check.h
> index af7f32c5f4f..2cbf34ab516 100644
> --- a/gcc/testsuite/gcc.target/i386/f16c-check.h
> +++ b/gcc/testsuite/gcc.target/i386/f16c-check.h
> @@ -1,6 +1,5 @@
>  #include <stdlib.h>
>  #include <stdio.h>
> -#include "cpuid.h"
>  #include "m256-check.h"
>
>  static void f16c_test (void);
> @@ -8,13 +7,8 @@ static void f16c_test (void);
>  int
>  main ()
>  {
> -  unsigned int eax, ebx, ecx, edx;
> -
> -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> -    return 0;
> -
> -  /* Run F16C test only if host has F16C support.  */
> -  if (ecx & bit_F16C)
> +  /* Check cpu support for F16C.  */
> +  if (__builtin_cpu_supports ("f16c"))
>      {
>        f16c_test ();
>  #ifdef DEBUG
> diff --git a/gcc/testsuite/gcc.target/i386/fma-check.h b/gcc/testsuite/gcc.target/i386/fma-check.h
> index 8390f5088bd..6c1d3372218 100644
> --- a/gcc/testsuite/gcc.target/i386/fma-check.h
> +++ b/gcc/testsuite/gcc.target/i386/fma-check.h
> @@ -1,7 +1,5 @@
>  #include <stdlib.h>
>
> -#include "cpuid.h"
> -
>  static void fma_test (void);
>
>  static void __attribute__ ((noinline)) do_test (void)
> @@ -12,13 +10,8 @@ static void __attribute__ ((noinline)) do_test (void)
>  int
>  main ()
>  {
> -  unsigned int eax, ebx, ecx, edx;
> -
> -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> -    return 0;
> -
> -  /* Run FMA test only if host has FMA support.  */
> -  if (ecx & bit_FMA)
> +  /* Check cpu support for FMA.  */
> +  if (__builtin_cpu_supports ("fma"))
>      do_test ();
>
>    return 0;
> diff --git a/gcc/testsuite/gcc.target/i386/fma4-check.h b/gcc/testsuite/gcc.target/i386/fma4-check.h
> index 33cd9628c04..2d2c2718029 100644
> --- a/gcc/testsuite/gcc.target/i386/fma4-check.h
> +++ b/gcc/testsuite/gcc.target/i386/fma4-check.h
> @@ -1,7 +1,5 @@
>  #include <stdlib.h>
>
> -#include "cpuid.h"
> -
>  static void fma4_test (void);
>
>  static void
> @@ -14,13 +12,8 @@ do_test (void)
>  int
>  main ()
>  {
> -  unsigned int eax, ebx, ecx, edx;
> -
> -  if (!__get_cpuid (0x80000001, &eax, &ebx, &ecx, &edx))
> -    return 0;
> -
> -  /* Run FMA4 test only if host has FMA4 support.  */
> -  if (ecx & bit_FMA4)
> +  /* Check cpu support foe FMA4.  */
> +  if (__builtin_cpu_supports ("fma4"))
>      do_test ();
>
>    return 0;
> diff --git a/gcc/testsuite/gcc.target/i386/lzcnt-check.h b/gcc/testsuite/gcc.target/i386/lzcnt-check.h
> index 8aad834d6af..824f1a3b513 100644
> --- a/gcc/testsuite/gcc.target/i386/lzcnt-check.h
> +++ b/gcc/testsuite/gcc.target/i386/lzcnt-check.h
> @@ -1,8 +1,6 @@
>  #include <stdio.h>
>  #include <stdlib.h>
>
> -#include "cpuid.h"
> -
>  static void lzcnt_test (void);
>
>  static void
> @@ -15,13 +13,8 @@ do_test (void)
>  int
>  main ()
>  {
> -  unsigned int eax, ebx, ecx, edx;
> -
> -  if (!__get_cpuid (0x80000001, &eax, &ebx, &ecx, &edx))
> -    return 0;
> -
> -  /* Run LZCNT test only if host has LZCNT support.  */
> -  if (ecx & bit_LZCNT)
> +  /* Check cpu support for LZCNT.  */
> +  if (__builtin_cpu_supports ("lzcnt"))
>      {
>        do_test ();
>  #ifdef DEBUG
> diff --git a/gcc/testsuite/gcc.target/i386/mmx-3dnow-check.h b/gcc/testsuite/gcc.target/i386/mmx-3dnow-check.h
> index 4f2f7f3ac40..0ec2dca2e19 100644
> --- a/gcc/testsuite/gcc.target/i386/mmx-3dnow-check.h
> +++ b/gcc/testsuite/gcc.target/i386/mmx-3dnow-check.h
> @@ -1,8 +1,6 @@
>  #include <stdio.h>
>  #include <stdlib.h>
>
> -#include "cpuid.h"
> -
>  static void mmx_3dnow_test (void);
>
>  static void
> @@ -15,13 +13,8 @@ do_test (void)
>  int
>  main ()
>  {
> -  unsigned int eax, ebx, ecx, edx;
> -
> -  if (!__get_cpuid (0x80000001, &eax, &ebx, &ecx, &edx))
> -    return 0;
> -
> -  /* Run 3DNow! test only if host has 3DNow! support.  */
> -  if (edx & bit_3DNOW)
> +  /* Check cpu support for 3DNow!.  */
> +  if (__builtin_cpu_supports ("3dnow"))
>      do_test ();
>
>    return 0;
> diff --git a/gcc/testsuite/gcc.target/i386/mmx-check.h b/gcc/testsuite/gcc.target/i386/mmx-check.h
> index faf9b876f38..2afe5183ba2 100644
> --- a/gcc/testsuite/gcc.target/i386/mmx-check.h
> +++ b/gcc/testsuite/gcc.target/i386/mmx-check.h
> @@ -1,8 +1,6 @@
>  #include <stdio.h>
>  #include <stdlib.h>
>
> -#include "cpuid.h"
> -
>  static void mmx_test (void);
>
>  static void
> @@ -15,13 +13,8 @@ do_test (void)
>  int
>  main ()
>  {
> -  unsigned int eax, ebx, ecx, edx;
> -
> -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> -    return 0;
> -
> -  /* Run MMX test only if host has MMX support.  */
> -  if (edx & bit_MMX)
> +  /* Check cpu support for MMX.  */
> +  if (__builtin_cpu_supports ("mmx"))
>      do_test ();
>
>    return 0;
> diff --git a/gcc/testsuite/gcc.target/i386/pclmul-avx-check.h b/gcc/testsuite/gcc.target/i386/pclmul-avx-check.h
> index 5eed2e2203c..b506b3306e6 100644
> --- a/gcc/testsuite/gcc.target/i386/pclmul-avx-check.h
> +++ b/gcc/testsuite/gcc.target/i386/pclmul-avx-check.h
> @@ -2,8 +2,6 @@
>  #include <stdio.h>
>  #endif
>  #include <stdlib.h>
> -#include "cpuid.h"
> -#include "avx-os-support.h"
>
>  static void pclmul_avx_test (void);
>
> @@ -17,15 +15,9 @@ do_test (void)
>  int
>  main ()
>  {
> -  unsigned int eax, ebx, ecx, edx;
> -
> -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> -    return 0;
> -
> -  /* Run PCLMUL + AVX test only if host has PCLMUL + AVX support.  */
> -  if (((ecx & (bit_AVX | bit_OSXSAVE | bit_PCLMUL))
> -       == (bit_AVX | bit_OSXSAVE | bit_PCLMUL))
> -      && avx_os_support ())
> +  /* Check cpu support for PCLMUL and AVX.  */
> +  if (__builtin_cpu_supports ("pclmul")
> +      && __builtin_cpu_supports ("avx"))
>      {
>        do_test ();
>  #ifdef DEBUG
> diff --git a/gcc/testsuite/gcc.target/i386/pclmul-check.h b/gcc/testsuite/gcc.target/i386/pclmul-check.h
> index 7526cbe2ddf..3ed1a044627 100644
> --- a/gcc/testsuite/gcc.target/i386/pclmul-check.h
> +++ b/gcc/testsuite/gcc.target/i386/pclmul-check.h
> @@ -1,8 +1,6 @@
>  #include <stdio.h>
>  #include <stdlib.h>
>
> -#include "cpuid.h"
> -
>  static void pclmul_test (void);
>
>  static void
> @@ -15,13 +13,8 @@ do_test (void)
>  int
>  main ()
>  {
> -  unsigned int eax, ebx, ecx, edx;
> -
> -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> -    return 0;
> -
> -  /* Run PCLMULQDQ test only if host has PCLMULQDQ support.  */
> -  if (ecx & bit_PCLMUL)
> +  /* Check cpu support for PCLMUL.  */
> +  if (__builtin_cpu_supports ("pclmul"))
>      {
>        do_test ();
>  #ifdef DEBUG
> diff --git a/gcc/testsuite/gcc.target/i386/rtm-check.h b/gcc/testsuite/gcc.target/i386/rtm-check.h
> index bdb5a6dc0bf..4121e602a7f 100644
> --- a/gcc/testsuite/gcc.target/i386/rtm-check.h
> +++ b/gcc/testsuite/gcc.target/i386/rtm-check.h
> @@ -1,5 +1,4 @@
>  #include <stdlib.h>
> -#include "cpuid.h"
>
>  static void rtm_test (void);
>
> @@ -11,13 +10,8 @@ static void __attribute__ ((noinline)) do_test (void)
>  int
>  main ()
>  {
> -  unsigned int eax, ebx, ecx, edx;
> -
> -  if (!__get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx))
> -    return 0;
> -
> -  /* Run RTM test only if host has RTM support.  */
> -  if (ebx & bit_RTM)
> +  /* Check cpu support for RTM.  */
> +  if (__builtin_cpu_supports ("rtm"))
>      {
>        do_test ();
>  #ifdef DEBUG
> diff --git a/gcc/testsuite/gcc.target/i386/sha-check.h b/gcc/testsuite/gcc.target/i386/sha-check.h
> index 5bc5a59ab80..61ce43053f9 100644
> --- a/gcc/testsuite/gcc.target/i386/sha-check.h
> +++ b/gcc/testsuite/gcc.target/i386/sha-check.h
> @@ -1,5 +1,4 @@
>  #include <stdlib.h>
> -#include "cpuid.h"
>
>  static void sha_test (void);
>
> @@ -13,13 +12,8 @@ do_test (void)
>  int
>  main ()
>  {
> -  unsigned int eax, ebx, ecx, edx;
> -
> -  if (!__get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx))
> -    return 0;
> -
> -  /* Run SHA test only if host has SHA support.  */
> -  if (ebx & bit_SHA)
> +  /* Check cpu support for SHA.  */
> +  if (__builtin_cpu_supports ("sha"))
>      {
>        do_test ();
>  #ifdef DEBUG
> diff --git a/gcc/testsuite/gcc.target/i386/sse-check.h b/gcc/testsuite/gcc.target/i386/sse-check.h
> index 11b71bc3e97..58bc88c5598 100644
> --- a/gcc/testsuite/gcc.target/i386/sse-check.h
> +++ b/gcc/testsuite/gcc.target/i386/sse-check.h
> @@ -1,7 +1,5 @@
>  #include <stdlib.h>
>  #include "m128-check.h"
> -#include "cpuid.h"
> -#include "sse-os-support.h"
>
>  static void sse_test (void);
>
> @@ -15,13 +13,8 @@ do_test (void)
>  int
>  main ()
>  {
> -  unsigned int eax, ebx, ecx, edx;
> -
> -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> -    return 0;
> -
> -  /* Run SSE test only if host has SSE support.  */
> -  if ((edx & bit_SSE) && sse_os_support ())
> +  /* Check cpu support for SSE.  */
> +  if (__builtin_cpu_supports ("sse"))
>      do_test ();
>
>    return 0;
> diff --git a/gcc/testsuite/gcc.target/i386/sse2-check.h b/gcc/testsuite/gcc.target/i386/sse2-check.h
> index fd4a6ce1dbf..4976a27022d 100644
> --- a/gcc/testsuite/gcc.target/i386/sse2-check.h
> +++ b/gcc/testsuite/gcc.target/i386/sse2-check.h
> @@ -1,7 +1,5 @@
>  #include <stdlib.h>
> -#include "cpuid.h"
>  #include "m128-check.h"
> -#include "sse-os-support.h"
>
>  static void sse2_test (void);
>
> @@ -15,13 +13,8 @@ do_test (void)
>  int
>  main ()
>  {
> -  unsigned int eax, ebx, ecx, edx;
> -
> -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> -    return 0;
> -
> -  /* Run SSE2 test only if host has SSE2 support.  */
> -  if ((edx & bit_SSE2) && sse_os_support ())
> +  /* Check cpu support for SSE2.  */
> +  if (__builtin_cpu_supports ("sse2"))
>      do_test ();
>
>    return 0;
> diff --git a/gcc/testsuite/gcc.target/i386/sse3-check.h b/gcc/testsuite/gcc.target/i386/sse3-check.h
> index 5a0a0b1a02e..3c58361e925 100644
> --- a/gcc/testsuite/gcc.target/i386/sse3-check.h
> +++ b/gcc/testsuite/gcc.target/i386/sse3-check.h
> @@ -1,7 +1,5 @@
>  #include <stdio.h>
>  #include <stdlib.h>
> -#include "cpuid.h"
> -#include "sse-os-support.h"
>
>  static void sse3_test (void);
>
> @@ -15,13 +13,8 @@ do_test (void)
>  int
>  main ()
>  {
> -  unsigned int eax, ebx, ecx, edx;
> -
> -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> -    return 0;
> -
> -  /* Run SSE3 test only if host has SSE3 support.  */
> -  if ((ecx & bit_SSE3) && sse_os_support ())
> +  /* Check cpu support for SSE3.  */
> +  if (__builtin_cpu_supports ("sse3"))
>      do_test ();
>
>    return 0;
> diff --git a/gcc/testsuite/gcc.target/i386/sse4_1-check.h b/gcc/testsuite/gcc.target/i386/sse4_1-check.h
> index 788f65d61cb..61d0d0284a8 100644
> --- a/gcc/testsuite/gcc.target/i386/sse4_1-check.h
> +++ b/gcc/testsuite/gcc.target/i386/sse4_1-check.h
> @@ -1,6 +1,4 @@
>  #include <stdlib.h>
> -
> -#include "cpuid.h"
>  #include "m128-check.h"
>
>  static void sse4_1_test (void);
> @@ -17,13 +15,8 @@ do_test (void)
>  int
>  main ()
>  {
> -  unsigned int eax, ebx, ecx, edx;
> -
> -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> -    return 0;
> -
> -  /* Run SSE4.1 test only if host has SSE4.1 support.  */
> -  if (ecx & bit_SSE4_1)
> +  /* Check cpu support for SSE4.1.  */
> +  if (__builtin_cpu_supports ("sse4.1"))
>      do_test ();
>
>    return 0;
> diff --git a/gcc/testsuite/gcc.target/i386/sse4_2-check.h b/gcc/testsuite/gcc.target/i386/sse4_2-check.h
> index c33cd1b4986..6c921ac52c7 100644
> --- a/gcc/testsuite/gcc.target/i386/sse4_2-check.h
> +++ b/gcc/testsuite/gcc.target/i386/sse4_2-check.h
> @@ -1,8 +1,6 @@
>  #include <stdio.h>
>  #include <stdlib.h>
> -
>  #include "m128-check.h"
> -#include "cpuid.h"
>
>  static void sse4_2_test (void);
>
> @@ -16,13 +14,8 @@ do_test (void)
>  int
>  main ()
>  {
> -  unsigned int eax, ebx, ecx, edx;
> -
> -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> -    return 0;
> -
> -  /* Run SSE4.2 test only if host has SSE4.2 support.  */
> -  if (ecx & bit_SSE4_2)
> +  /* Check cpu support for SSE4.2.  */
> +  if (__builtin_cpu_supports ("sse4.2"))
>      do_test ();
>
>    return 0;
> diff --git a/gcc/testsuite/gcc.target/i386/sse4a-check.h b/gcc/testsuite/gcc.target/i386/sse4a-check.h
> index d43b4b222b1..ae70ff0a268 100644
> --- a/gcc/testsuite/gcc.target/i386/sse4a-check.h
> +++ b/gcc/testsuite/gcc.target/i386/sse4a-check.h
> @@ -1,8 +1,6 @@
>  #include <stdio.h>
>  #include <stdlib.h>
>
> -#include "cpuid.h"
> -
>  static void sse4a_test (void);
>
>  static void
> @@ -15,13 +13,8 @@ do_test (void)
>  int
>  main ()
>  {
> -  unsigned int eax, ebx, ecx, edx;
> -
> -  if (!__get_cpuid (0x80000001, &eax, &ebx, &ecx, &edx))
> -    return 0;
> -
> -  /* Run SSE4a test only if host has SSE4a support.  */
> -  if (ecx & bit_SSE4a)
> +  /* Check cpu support for SSE4a.  */
> +  if (__builtin_cpu_supports ("sse4a"))
>      do_test ();
>
>    return 0;
> diff --git a/gcc/testsuite/gcc.target/i386/ssse3-check.h b/gcc/testsuite/gcc.target/i386/ssse3-check.h
> index 3ca79333c7f..3e834811f2d 100644
> --- a/gcc/testsuite/gcc.target/i386/ssse3-check.h
> +++ b/gcc/testsuite/gcc.target/i386/ssse3-check.h
> @@ -1,8 +1,6 @@
>  #include <stdio.h>
>  #include <stdlib.h>
>
> -#include "cpuid.h"
> -
>  static void ssse3_test (void);
>
>  static void
> @@ -15,13 +13,8 @@ do_test (void)
>  int
>  main ()
>  {
> -  unsigned int eax, ebx, ecx, edx;
> -
> -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> -    return 0;
> -
> -  /* Run SSSE3 test only if host has SSSE3 support.  */
> -  if (ecx & bit_SSSE3)
> +  /* Check cpu support for SSSE3.  */
> +  if (__builtin_cpu_supports ("ssse3"))
>      do_test ();
>
>    return 0;
> diff --git a/gcc/testsuite/gcc.target/i386/xop-check.h b/gcc/testsuite/gcc.target/i386/xop-check.h
> index 395abe8766d..e1ef1273111 100644
> --- a/gcc/testsuite/gcc.target/i386/xop-check.h
> +++ b/gcc/testsuite/gcc.target/i386/xop-check.h
> @@ -1,6 +1,4 @@
>  #include <stdlib.h>
> -
> -#include "cpuid.h"
>  #include "m256-check.h"
>
>  static void xop_test (void);
> @@ -15,13 +13,8 @@ do_test (void)
>  int
>  main ()
>  {
> -  unsigned int eax, ebx, ecx, edx;
> -
> -  if (!__get_cpuid (0x80000001, &eax, &ebx, &ecx, &edx))
> -    return 0;
> -
> -  /* Run XOP test only if host has XOP support.  */
> -  if (ecx & bit_XOP)
> +  /* Check cpu support for XOP.  */
> +  if (__builtin_cpu_supports ("xop"))
>      do_test ();
>
>    return 0;
> --
> 2.18.1
>
Hongyu Wang May 6, 2022, 9 a.m. UTC | #2
> I don't think *_os_support calls should be removed. IIRC,
> __builtin_cpu_supports function checks if the feature is supported by
> CPU, whereas *_os_supports calls check via xgetbv if OS supports
> handling of new registers.

avx_os_support is like

avx_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_SSE | XSTATE_YMM)) == (XSTATE_SSE | XSTATE_YMM);
}

While in get_avaliable_features we have

#define XCR_AVX_ENABLED_MASK \
  (XSTATE_SSE | XSTATE_YMM)
  if ((ecx & bit_OSXSAVE))
    {
      /* Check if XMM, YMM, OPMASK, upper 256 bits of ZMM0-ZMM15 and
ZMM16-ZMM31 states are supported by OSXSAVE.  */
      unsigned int xcrlow;
      unsigned int xcrhigh;
      __asm__ (".byte 0x0f, 0x01, 0xd0" /* xgetbv  */
       : "=a" (xcrlow), "=d" (xcrhigh)
       : "c" (XCR_XFEATURE_ENABLED_MASK));
      if ((xcrlow & XCR_AVX_ENABLED_MASK) == XCR_AVX_ENABLED_MASK)
{
  avx_usable = 1;

So __builtin_cpu_supports already inherits same check

Uros Bizjak via Gcc-patches <gcc-patches@gcc.gnu.org> 于2022年5月6日周五 16:27写道:
>
> On Fri, May 6, 2022 at 9:57 AM Haochen Jiang <haochen.jiang@intel.com> wrote:
> >
> > Hi all,
> >
> > There are some check files in i386 testsuite are written before the function __builtin_cpu_supports is introduced. All of them are using __get_cpuid_count. This patch aims to reconstruct the i386 testsuite with __builtin_cpu_supports so that we can have a much clearer code.
> >
> > Regtested on x86_64-pc-linux-gnu. Ok for trunk?
>
> I don't think *_os_support calls should be removed. IIRC,
> __builtin_cpu_supports function checks if the feature is supported by
> CPU, whereas *_os_supports calls check via xgetbv if OS supports
> handling of new registers.
>
> Uros.
>
> >
> > Also when writting this patch, I also find some files in testsuite that might be useless currently. For example, in the file gcc/testsuite/gcc.target/i386/sse-os-support.h, it always return 1. And there are also some files will no longer be included at all with this patch. Should we remove those files when we have time?
> >
> > BRs,
> > Haochen
> >
> > gcc/testsuite/ChangeLog:
> >
> >         * gcc.target/i386/adx-check.h: Change bit check to
> >         __builtin_cpu_supports.
> >         * gcc.target/i386/aes-avx-check.h: Ditto.
> >         * gcc.target/i386/aes-check.h: Ditto.
> >         * gcc.target/i386/avx-check.h: Ditto.
> >         * gcc.target/i386/avx2-check.h: Ditto.
> >         * gcc.target/i386/avx512-check.h: Ditto.
> >         * gcc.target/i386/bmi-check.h: Ditto.
> >         * gcc.target/i386/bmi2-check.h: Ditto.
> >         * gcc.target/i386/f16c-check.h: Ditto.
> >         * gcc.target/i386/fma-check.h: Ditto.
> >         * gcc.target/i386/fma4-check.h: Ditto.
> >         * gcc.target/i386/lzcnt-check.h: Ditto.
> >         * gcc.target/i386/mmx-3dnow-check.h: Ditto.
> >         * gcc.target/i386/mmx-check.h: Ditto.
> >         * gcc.target/i386/pclmul-avx-check.h: Ditto.
> >         * gcc.target/i386/pclmul-check.h: Ditto.
> >         * gcc.target/i386/rtm-check.h: Ditto.
> >         * gcc.target/i386/sha-check.h: Ditto.
> >         * gcc.target/i386/sse-check.h: Ditto.
> >         * gcc.target/i386/sse2-check.h: Ditto.
> >         * gcc.target/i386/sse3-check.h: Ditto.
> >         * gcc.target/i386/sse4_1-check.h: Ditto.
> >         * gcc.target/i386/sse4_2-check.h: Ditto.
> >         * gcc.target/i386/sse4a-check.h: Ditto.
> >         * gcc.target/i386/ssse3-check.h: Ditto.
> >         * gcc.target/i386/xop-check.h: Ditto.
> > ---
> >  gcc/testsuite/gcc.target/i386/adx-check.h     | 10 +---
> >  gcc/testsuite/gcc.target/i386/aes-avx-check.h | 14 +----
> >  gcc/testsuite/gcc.target/i386/aes-check.h     | 11 +---
> >  gcc/testsuite/gcc.target/i386/avx-check.h     | 12 +---
> >  gcc/testsuite/gcc.target/i386/avx2-check.h    | 20 +------
> >  gcc/testsuite/gcc.target/i386/avx512-check.h  | 59 +++++++------------
> >  gcc/testsuite/gcc.target/i386/bmi-check.h     | 11 +---
> >  gcc/testsuite/gcc.target/i386/bmi2-check.h    | 10 +---
> >  gcc/testsuite/gcc.target/i386/f16c-check.h    | 10 +---
> >  gcc/testsuite/gcc.target/i386/fma-check.h     | 11 +---
> >  gcc/testsuite/gcc.target/i386/fma4-check.h    | 11 +---
> >  gcc/testsuite/gcc.target/i386/lzcnt-check.h   | 11 +---
> >  .../gcc.target/i386/mmx-3dnow-check.h         | 11 +---
> >  gcc/testsuite/gcc.target/i386/mmx-check.h     | 11 +---
> >  .../gcc.target/i386/pclmul-avx-check.h        | 14 +----
> >  gcc/testsuite/gcc.target/i386/pclmul-check.h  | 11 +---
> >  gcc/testsuite/gcc.target/i386/rtm-check.h     | 10 +---
> >  gcc/testsuite/gcc.target/i386/sha-check.h     | 10 +---
> >  gcc/testsuite/gcc.target/i386/sse-check.h     | 11 +---
> >  gcc/testsuite/gcc.target/i386/sse2-check.h    | 11 +---
> >  gcc/testsuite/gcc.target/i386/sse3-check.h    | 11 +---
> >  gcc/testsuite/gcc.target/i386/sse4_1-check.h  | 11 +---
> >  gcc/testsuite/gcc.target/i386/sse4_2-check.h  | 11 +---
> >  gcc/testsuite/gcc.target/i386/sse4a-check.h   | 11 +---
> >  gcc/testsuite/gcc.target/i386/ssse3-check.h   | 11 +---
> >  gcc/testsuite/gcc.target/i386/xop-check.h     | 11 +---
> >  26 files changed, 73 insertions(+), 272 deletions(-)
> >
> > diff --git a/gcc/testsuite/gcc.target/i386/adx-check.h b/gcc/testsuite/gcc.target/i386/adx-check.h
> > index cfed1a38483..bed5dcca385 100644
> > --- a/gcc/testsuite/gcc.target/i386/adx-check.h
> > +++ b/gcc/testsuite/gcc.target/i386/adx-check.h
> > @@ -1,5 +1,4 @@
> >  #include <stdlib.h>
> > -#include "cpuid.h"
> >
> >  static void adx_test (void);
> >
> > @@ -11,13 +10,8 @@ static void __attribute__ ((noinline)) do_test (void)
> >  int
> >  main ()
> >  {
> > -  unsigned int eax, ebx, ecx, edx;
> > -
> > -  if (!__get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx))
> > -    return 0;
> > -
> > -  /* Run ADX test only if host has ADX support.  */
> > -  if (ebx & bit_ADX)
> > +  /* Check cpu support for ADX.  */
> > +  if (__builtin_cpu_supports ("adx"))
> >      {
> >        do_test ();
> >  #ifdef DEBUG
> > diff --git a/gcc/testsuite/gcc.target/i386/aes-avx-check.h b/gcc/testsuite/gcc.target/i386/aes-avx-check.h
> > index f2a4ead4014..74bf597ead4 100644
> > --- a/gcc/testsuite/gcc.target/i386/aes-avx-check.h
> > +++ b/gcc/testsuite/gcc.target/i386/aes-avx-check.h
> > @@ -2,8 +2,6 @@
> >  #include <stdio.h>
> >  #endif
> >  #include <stdlib.h>
> > -#include "cpuid.h"
> > -#include "avx-os-support.h"
> >
> >  static void aes_avx_test (void);
> >
> > @@ -17,15 +15,9 @@ do_test (void)
> >  int
> >  main ()
> >  {
> > -  unsigned int eax, ebx, ecx, edx;
> > -
> > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > -    return 0;
> > -
> > -  /* Run AES + AVX test only if host has AES + AVX support.  */
> > -  if (((ecx & (bit_AVX | bit_OSXSAVE | bit_AES))
> > -       == (bit_AVX | bit_OSXSAVE | bit_AES))
> > -      && avx_os_support ())
> > +  /* Check cpu support for AES and AVX.  */
> > +  if (__builtin_cpu_supports ("avx")
> > +      && __builtin_cpu_supports ("aes"))
> >      {
> >        do_test ();
> >  #ifdef DEBUG
> > diff --git a/gcc/testsuite/gcc.target/i386/aes-check.h b/gcc/testsuite/gcc.target/i386/aes-check.h
> > index 7e794423e47..7c3a3b324a7 100644
> > --- a/gcc/testsuite/gcc.target/i386/aes-check.h
> > +++ b/gcc/testsuite/gcc.target/i386/aes-check.h
> > @@ -1,8 +1,6 @@
> >  #include <stdio.h>
> >  #include <stdlib.h>
> >
> > -#include "cpuid.h"
> > -
> >  static void aes_test (void);
> >
> >  static void
> > @@ -15,13 +13,8 @@ do_test (void)
> >  int
> >  main ()
> >  {
> > -  unsigned int eax, ebx, ecx, edx;
> > -
> > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > -    return 0;
> > -
> > -  /* Run AES test only if host has AES support.  */
> > -  if (ecx & bit_AES)
> > +  /* Check cpu support for AES.  */
> > +  if (__builtin_cpu_supports ("aes"))
> >      {
> >        do_test ();
> >  #ifdef DEBUG
> > diff --git a/gcc/testsuite/gcc.target/i386/avx-check.h b/gcc/testsuite/gcc.target/i386/avx-check.h
> > index 7ddca9d7b80..4a3dbc257bc 100644
> > --- a/gcc/testsuite/gcc.target/i386/avx-check.h
> > +++ b/gcc/testsuite/gcc.target/i386/avx-check.h
> > @@ -1,7 +1,5 @@
> >  #include <stdlib.h>
> > -#include "cpuid.h"
> >  #include "m256-check.h"
> > -#include "avx-os-support.h"
> >
> >  static void avx_test (void);
> >
> > @@ -15,14 +13,8 @@ do_test (void)
> >  int
> >  main ()
> >  {
> > -  unsigned int eax, ebx, ecx, edx;
> > -
> > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > -    return 0;
> > -
> > -  /* Run AVX test only if host has AVX support.  */
> > -  if (((ecx & (bit_AVX | bit_OSXSAVE)) == (bit_AVX | bit_OSXSAVE))
> > -      && avx_os_support ())
> > +  /* Check cpu support for AVX.  */
> > +  if (__builtin_cpu_supports ("avx"))
> >      {
> >        do_test ();
> >  #ifdef DEBUG
> > diff --git a/gcc/testsuite/gcc.target/i386/avx2-check.h b/gcc/testsuite/gcc.target/i386/avx2-check.h
> > index 25bed5e0da6..2bc3c4425bb 100644
> > --- a/gcc/testsuite/gcc.target/i386/avx2-check.h
> > +++ b/gcc/testsuite/gcc.target/i386/avx2-check.h
> > @@ -1,7 +1,5 @@
> >  #include <stdlib.h>
> > -#include "cpuid.h"
> >  #include "m256-check.h"
> > -#include "avx-os-support.h"
> >
> >  static void avx2_test (void);
> >
> > @@ -10,25 +8,11 @@ static void __attribute__ ((noinline)) do_test (void)
> >    avx2_test ();
> >  }
> >
> > -static int
> > -check_osxsave (void)
> > -{
> > -  unsigned int eax, ebx, ecx, edx;
> > -
> > -  __cpuid (1, eax, ebx, ecx, edx);
> > -  return (ecx & bit_OSXSAVE) != 0;
> > -}
> > -
> >  int
> >  main ()
> >  {
> > -  unsigned int eax, ebx, ecx, edx;
> > -
> > -  if (!__get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx))
> > -    return 0;
> > -
> > -  /* Run AVX2 test only if host has AVX2 support.  */
> > -  if (check_osxsave () && (ebx & bit_AVX2) && avx_os_support ())
> > +  /* Check cpu support for AVX2.  */
> > +  if (__builtin_cpu_supports ("avx2"))
> >      {
> >        do_test ();
> >  #ifdef DEBUG
> > diff --git a/gcc/testsuite/gcc.target/i386/avx512-check.h b/gcc/testsuite/gcc.target/i386/avx512-check.h
> > index 0ad9064f637..339c79070c9 100644
> > --- a/gcc/testsuite/gcc.target/i386/avx512-check.h
> > +++ b/gcc/testsuite/gcc.target/i386/avx512-check.h
> > @@ -1,7 +1,5 @@
> >  #include <stdlib.h>
> > -#include "cpuid.h"
> >  #include "m512-check.h"
> > -#include "avx512f-os-support.h"
> >
> >  #ifndef DO_TEST
> >  #define DO_TEST do_test
> > @@ -25,81 +23,66 @@ do_test (void)
> >  }
> >  #endif
> >
> > -static int
> > -check_osxsave (void)
> > -{
> > -  unsigned int eax, ebx, ecx, edx;
> > -
> > -  __cpuid (1, eax, ebx, ecx, edx);
> > -  return (ecx & bit_OSXSAVE) != 0;
> > -}
> > -
> >  int
> >  main ()
> >  {
> > -  unsigned int eax, ebx, ecx, edx;
> > -
> > -  if (!__get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx))
> > -    return 0;
> > -
> > -  /* Run AVX512 test only if host has ISA support.  */
> > -  if (check_osxsave ()
> > -      && (ebx & bit_AVX512F)
> > +  /* Check cpu support for AVX512.  */
> > +  if (__builtin_cpu_supports ("avx512f")
> >  #ifdef AVX512VL
> > -      && (ebx & bit_AVX512VL)
> > +      && __builtin_cpu_supports ("avx512vl")
> >  #endif
> >  #ifdef AVX512ER
> > -      && (ebx & bit_AVX512ER)
> > +      && __builtin_cpu_supports ("avx512er")
> >  #endif
> >  #ifdef AVX512CD
> > -      && (ebx & bit_AVX512CD)
> > +      && __builtin_cpu_supports ("avx512cd")
> >  #endif
> >  #ifdef AVX512DQ
> > -      && (ebx & bit_AVX512DQ)
> > +      && __builtin_cpu_supports ("avx512dq")
> >  #endif
> >  #ifdef AVX512BW
> > -      && (ebx & bit_AVX512BW)
> > +      && __builtin_cpu_supports ("avx512bw")
> >  #endif
> >  #ifdef AVX512IFMA
> > -      && (ebx & bit_AVX512IFMA)
> > +      && __builtin_cpu_supports ("avx512ifma")
> >  #endif
> >  #ifdef AVX512VBMI
> > -      && (ecx & bit_AVX512VBMI)
> > +      && __builtin_cpu_supports ("avx512vbmi")
> >  #endif
> >  #ifdef AVX5124FMAPS
> > -      && (edx & bit_AVX5124FMAPS)
> > +      && __builtin_cpu_supports ("avx5124fmaps")
> >  #endif
> >  #ifdef AVX5124VNNIW
> > -      && (edx & bit_AVX5124VNNIW)
> > +      && __builtin_cpu_supports ("avx5124vnniw")
> >  #endif
> >  #ifdef AVX512VPOPCNTDQ
> > -      && (ecx & bit_AVX512VPOPCNTDQ)
> > +      && __builtin_cpu_supports ("avx512vpopcntdq")
> >  #endif
> >  #ifdef AVX512BITALG
> > -      && (ecx & bit_AVX512BITALG)
> > +      && __builtin_cpu_supports ("avx512bitalg")
> >  #endif
> >  #ifdef GFNI
> > -      && (ecx & bit_GFNI)
> > +      && __builtin_cpu_supports ("gfni")
> >  #endif
> >  #ifdef AVX512VBMI2
> > -      && (ecx & bit_AVX512VBMI2)
> > +      && __builtin_cpu_supports ("avx512vbmi2")
> >  #endif
> >  #ifdef AVX512VNNI
> > -      && (ecx & bit_AVX512VNNI)
> > +      && __builtin_cpu_supports ("avx512vnni")
> >  #endif
> >  #ifdef AVX512FP16
> > -      && (edx & bit_AVX512FP16)
> > +      && __builtin_cpu_supports ("avx512fp16")
> >  #endif
> >  #ifdef VAES
> > -      && (ecx & bit_VAES)
> > +      && __builtin_cpu_supports ("vaes")
> >  #endif
> >  #ifdef VPCLMULQDQ
> > -      && (ecx & bit_VPCLMULQDQ)
> > +      && __builtin_cpu_supports ("vpclmulqdq")
> >  #endif
> >  #ifdef AVX512VP2INTERSECT
> > -      && (edx & bit_AVX512VP2INTERSECT)
> > +      && __builtin_cpu_supports ("avx512vp2intersect")
> >  #endif
> > -      && avx512f_os_support ())
> > +      )
> >      {
> >        DO_TEST ();
> >  #ifdef DEBUG
> > diff --git a/gcc/testsuite/gcc.target/i386/bmi-check.h b/gcc/testsuite/gcc.target/i386/bmi-check.h
> > index 1973f3b6468..6af0291a947 100644
> > --- a/gcc/testsuite/gcc.target/i386/bmi-check.h
> > +++ b/gcc/testsuite/gcc.target/i386/bmi-check.h
> > @@ -1,8 +1,6 @@
> >  #include <stdio.h>
> >  #include <stdlib.h>
> >
> > -#include "cpuid.h"
> > -
> >  static void bmi_test (void);
> >
> >  static void
> > @@ -15,13 +13,8 @@ do_test (void)
> >  int
> >  main ()
> >  {
> > -  unsigned int eax, ebx, ecx, edx;
> > -
> > -  if (!__get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx))
> > -    return 0;
> > -
> > -  /* Run BMI test only if host has BMI support.  */
> > -  if (ebx & bit_BMI)
> > +  /* Check cpu support for BMI.  */
> > +  if (__builtin_cpu_supports ("bmi"))
> >      {
> >        do_test ();
> >  #ifdef DEBUG
> > diff --git a/gcc/testsuite/gcc.target/i386/bmi2-check.h b/gcc/testsuite/gcc.target/i386/bmi2-check.h
> > index ba91ef9b780..75c4d8d9616 100644
> > --- a/gcc/testsuite/gcc.target/i386/bmi2-check.h
> > +++ b/gcc/testsuite/gcc.target/i386/bmi2-check.h
> > @@ -1,6 +1,5 @@
> >  #include <stdio.h>
> >  #include <stdlib.h>
> > -#include "cpuid.h"
> >
> >  static void bmi2_test (void);
> >
> > @@ -14,13 +13,8 @@ do_test (void)
> >  int
> >  main ()
> >  {
> > -  unsigned int eax, ebx, ecx, edx;
> > -
> > -  if (!__get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx))
> > -    return 0;
> > -
> > -  /* Run BMI2 test only if host has BMI2 support.  */
> > -  if (ebx & bit_BMI2)
> > +  /* Check cpu support for BMI2.  */
> > +  if (__builtin_cpu_supports ("bmi2"))
> >      {
> >        do_test ();
> >  #ifdef DEBUG
> > diff --git a/gcc/testsuite/gcc.target/i386/f16c-check.h b/gcc/testsuite/gcc.target/i386/f16c-check.h
> > index af7f32c5f4f..2cbf34ab516 100644
> > --- a/gcc/testsuite/gcc.target/i386/f16c-check.h
> > +++ b/gcc/testsuite/gcc.target/i386/f16c-check.h
> > @@ -1,6 +1,5 @@
> >  #include <stdlib.h>
> >  #include <stdio.h>
> > -#include "cpuid.h"
> >  #include "m256-check.h"
> >
> >  static void f16c_test (void);
> > @@ -8,13 +7,8 @@ static void f16c_test (void);
> >  int
> >  main ()
> >  {
> > -  unsigned int eax, ebx, ecx, edx;
> > -
> > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > -    return 0;
> > -
> > -  /* Run F16C test only if host has F16C support.  */
> > -  if (ecx & bit_F16C)
> > +  /* Check cpu support for F16C.  */
> > +  if (__builtin_cpu_supports ("f16c"))
> >      {
> >        f16c_test ();
> >  #ifdef DEBUG
> > diff --git a/gcc/testsuite/gcc.target/i386/fma-check.h b/gcc/testsuite/gcc.target/i386/fma-check.h
> > index 8390f5088bd..6c1d3372218 100644
> > --- a/gcc/testsuite/gcc.target/i386/fma-check.h
> > +++ b/gcc/testsuite/gcc.target/i386/fma-check.h
> > @@ -1,7 +1,5 @@
> >  #include <stdlib.h>
> >
> > -#include "cpuid.h"
> > -
> >  static void fma_test (void);
> >
> >  static void __attribute__ ((noinline)) do_test (void)
> > @@ -12,13 +10,8 @@ static void __attribute__ ((noinline)) do_test (void)
> >  int
> >  main ()
> >  {
> > -  unsigned int eax, ebx, ecx, edx;
> > -
> > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > -    return 0;
> > -
> > -  /* Run FMA test only if host has FMA support.  */
> > -  if (ecx & bit_FMA)
> > +  /* Check cpu support for FMA.  */
> > +  if (__builtin_cpu_supports ("fma"))
> >      do_test ();
> >
> >    return 0;
> > diff --git a/gcc/testsuite/gcc.target/i386/fma4-check.h b/gcc/testsuite/gcc.target/i386/fma4-check.h
> > index 33cd9628c04..2d2c2718029 100644
> > --- a/gcc/testsuite/gcc.target/i386/fma4-check.h
> > +++ b/gcc/testsuite/gcc.target/i386/fma4-check.h
> > @@ -1,7 +1,5 @@
> >  #include <stdlib.h>
> >
> > -#include "cpuid.h"
> > -
> >  static void fma4_test (void);
> >
> >  static void
> > @@ -14,13 +12,8 @@ do_test (void)
> >  int
> >  main ()
> >  {
> > -  unsigned int eax, ebx, ecx, edx;
> > -
> > -  if (!__get_cpuid (0x80000001, &eax, &ebx, &ecx, &edx))
> > -    return 0;
> > -
> > -  /* Run FMA4 test only if host has FMA4 support.  */
> > -  if (ecx & bit_FMA4)
> > +  /* Check cpu support foe FMA4.  */
> > +  if (__builtin_cpu_supports ("fma4"))
> >      do_test ();
> >
> >    return 0;
> > diff --git a/gcc/testsuite/gcc.target/i386/lzcnt-check.h b/gcc/testsuite/gcc.target/i386/lzcnt-check.h
> > index 8aad834d6af..824f1a3b513 100644
> > --- a/gcc/testsuite/gcc.target/i386/lzcnt-check.h
> > +++ b/gcc/testsuite/gcc.target/i386/lzcnt-check.h
> > @@ -1,8 +1,6 @@
> >  #include <stdio.h>
> >  #include <stdlib.h>
> >
> > -#include "cpuid.h"
> > -
> >  static void lzcnt_test (void);
> >
> >  static void
> > @@ -15,13 +13,8 @@ do_test (void)
> >  int
> >  main ()
> >  {
> > -  unsigned int eax, ebx, ecx, edx;
> > -
> > -  if (!__get_cpuid (0x80000001, &eax, &ebx, &ecx, &edx))
> > -    return 0;
> > -
> > -  /* Run LZCNT test only if host has LZCNT support.  */
> > -  if (ecx & bit_LZCNT)
> > +  /* Check cpu support for LZCNT.  */
> > +  if (__builtin_cpu_supports ("lzcnt"))
> >      {
> >        do_test ();
> >  #ifdef DEBUG
> > diff --git a/gcc/testsuite/gcc.target/i386/mmx-3dnow-check.h b/gcc/testsuite/gcc.target/i386/mmx-3dnow-check.h
> > index 4f2f7f3ac40..0ec2dca2e19 100644
> > --- a/gcc/testsuite/gcc.target/i386/mmx-3dnow-check.h
> > +++ b/gcc/testsuite/gcc.target/i386/mmx-3dnow-check.h
> > @@ -1,8 +1,6 @@
> >  #include <stdio.h>
> >  #include <stdlib.h>
> >
> > -#include "cpuid.h"
> > -
> >  static void mmx_3dnow_test (void);
> >
> >  static void
> > @@ -15,13 +13,8 @@ do_test (void)
> >  int
> >  main ()
> >  {
> > -  unsigned int eax, ebx, ecx, edx;
> > -
> > -  if (!__get_cpuid (0x80000001, &eax, &ebx, &ecx, &edx))
> > -    return 0;
> > -
> > -  /* Run 3DNow! test only if host has 3DNow! support.  */
> > -  if (edx & bit_3DNOW)
> > +  /* Check cpu support for 3DNow!.  */
> > +  if (__builtin_cpu_supports ("3dnow"))
> >      do_test ();
> >
> >    return 0;
> > diff --git a/gcc/testsuite/gcc.target/i386/mmx-check.h b/gcc/testsuite/gcc.target/i386/mmx-check.h
> > index faf9b876f38..2afe5183ba2 100644
> > --- a/gcc/testsuite/gcc.target/i386/mmx-check.h
> > +++ b/gcc/testsuite/gcc.target/i386/mmx-check.h
> > @@ -1,8 +1,6 @@
> >  #include <stdio.h>
> >  #include <stdlib.h>
> >
> > -#include "cpuid.h"
> > -
> >  static void mmx_test (void);
> >
> >  static void
> > @@ -15,13 +13,8 @@ do_test (void)
> >  int
> >  main ()
> >  {
> > -  unsigned int eax, ebx, ecx, edx;
> > -
> > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > -    return 0;
> > -
> > -  /* Run MMX test only if host has MMX support.  */
> > -  if (edx & bit_MMX)
> > +  /* Check cpu support for MMX.  */
> > +  if (__builtin_cpu_supports ("mmx"))
> >      do_test ();
> >
> >    return 0;
> > diff --git a/gcc/testsuite/gcc.target/i386/pclmul-avx-check.h b/gcc/testsuite/gcc.target/i386/pclmul-avx-check.h
> > index 5eed2e2203c..b506b3306e6 100644
> > --- a/gcc/testsuite/gcc.target/i386/pclmul-avx-check.h
> > +++ b/gcc/testsuite/gcc.target/i386/pclmul-avx-check.h
> > @@ -2,8 +2,6 @@
> >  #include <stdio.h>
> >  #endif
> >  #include <stdlib.h>
> > -#include "cpuid.h"
> > -#include "avx-os-support.h"
> >
> >  static void pclmul_avx_test (void);
> >
> > @@ -17,15 +15,9 @@ do_test (void)
> >  int
> >  main ()
> >  {
> > -  unsigned int eax, ebx, ecx, edx;
> > -
> > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > -    return 0;
> > -
> > -  /* Run PCLMUL + AVX test only if host has PCLMUL + AVX support.  */
> > -  if (((ecx & (bit_AVX | bit_OSXSAVE | bit_PCLMUL))
> > -       == (bit_AVX | bit_OSXSAVE | bit_PCLMUL))
> > -      && avx_os_support ())
> > +  /* Check cpu support for PCLMUL and AVX.  */
> > +  if (__builtin_cpu_supports ("pclmul")
> > +      && __builtin_cpu_supports ("avx"))
> >      {
> >        do_test ();
> >  #ifdef DEBUG
> > diff --git a/gcc/testsuite/gcc.target/i386/pclmul-check.h b/gcc/testsuite/gcc.target/i386/pclmul-check.h
> > index 7526cbe2ddf..3ed1a044627 100644
> > --- a/gcc/testsuite/gcc.target/i386/pclmul-check.h
> > +++ b/gcc/testsuite/gcc.target/i386/pclmul-check.h
> > @@ -1,8 +1,6 @@
> >  #include <stdio.h>
> >  #include <stdlib.h>
> >
> > -#include "cpuid.h"
> > -
> >  static void pclmul_test (void);
> >
> >  static void
> > @@ -15,13 +13,8 @@ do_test (void)
> >  int
> >  main ()
> >  {
> > -  unsigned int eax, ebx, ecx, edx;
> > -
> > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > -    return 0;
> > -
> > -  /* Run PCLMULQDQ test only if host has PCLMULQDQ support.  */
> > -  if (ecx & bit_PCLMUL)
> > +  /* Check cpu support for PCLMUL.  */
> > +  if (__builtin_cpu_supports ("pclmul"))
> >      {
> >        do_test ();
> >  #ifdef DEBUG
> > diff --git a/gcc/testsuite/gcc.target/i386/rtm-check.h b/gcc/testsuite/gcc.target/i386/rtm-check.h
> > index bdb5a6dc0bf..4121e602a7f 100644
> > --- a/gcc/testsuite/gcc.target/i386/rtm-check.h
> > +++ b/gcc/testsuite/gcc.target/i386/rtm-check.h
> > @@ -1,5 +1,4 @@
> >  #include <stdlib.h>
> > -#include "cpuid.h"
> >
> >  static void rtm_test (void);
> >
> > @@ -11,13 +10,8 @@ static void __attribute__ ((noinline)) do_test (void)
> >  int
> >  main ()
> >  {
> > -  unsigned int eax, ebx, ecx, edx;
> > -
> > -  if (!__get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx))
> > -    return 0;
> > -
> > -  /* Run RTM test only if host has RTM support.  */
> > -  if (ebx & bit_RTM)
> > +  /* Check cpu support for RTM.  */
> > +  if (__builtin_cpu_supports ("rtm"))
> >      {
> >        do_test ();
> >  #ifdef DEBUG
> > diff --git a/gcc/testsuite/gcc.target/i386/sha-check.h b/gcc/testsuite/gcc.target/i386/sha-check.h
> > index 5bc5a59ab80..61ce43053f9 100644
> > --- a/gcc/testsuite/gcc.target/i386/sha-check.h
> > +++ b/gcc/testsuite/gcc.target/i386/sha-check.h
> > @@ -1,5 +1,4 @@
> >  #include <stdlib.h>
> > -#include "cpuid.h"
> >
> >  static void sha_test (void);
> >
> > @@ -13,13 +12,8 @@ do_test (void)
> >  int
> >  main ()
> >  {
> > -  unsigned int eax, ebx, ecx, edx;
> > -
> > -  if (!__get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx))
> > -    return 0;
> > -
> > -  /* Run SHA test only if host has SHA support.  */
> > -  if (ebx & bit_SHA)
> > +  /* Check cpu support for SHA.  */
> > +  if (__builtin_cpu_supports ("sha"))
> >      {
> >        do_test ();
> >  #ifdef DEBUG
> > diff --git a/gcc/testsuite/gcc.target/i386/sse-check.h b/gcc/testsuite/gcc.target/i386/sse-check.h
> > index 11b71bc3e97..58bc88c5598 100644
> > --- a/gcc/testsuite/gcc.target/i386/sse-check.h
> > +++ b/gcc/testsuite/gcc.target/i386/sse-check.h
> > @@ -1,7 +1,5 @@
> >  #include <stdlib.h>
> >  #include "m128-check.h"
> > -#include "cpuid.h"
> > -#include "sse-os-support.h"
> >
> >  static void sse_test (void);
> >
> > @@ -15,13 +13,8 @@ do_test (void)
> >  int
> >  main ()
> >  {
> > -  unsigned int eax, ebx, ecx, edx;
> > -
> > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > -    return 0;
> > -
> > -  /* Run SSE test only if host has SSE support.  */
> > -  if ((edx & bit_SSE) && sse_os_support ())
> > +  /* Check cpu support for SSE.  */
> > +  if (__builtin_cpu_supports ("sse"))
> >      do_test ();
> >
> >    return 0;
> > diff --git a/gcc/testsuite/gcc.target/i386/sse2-check.h b/gcc/testsuite/gcc.target/i386/sse2-check.h
> > index fd4a6ce1dbf..4976a27022d 100644
> > --- a/gcc/testsuite/gcc.target/i386/sse2-check.h
> > +++ b/gcc/testsuite/gcc.target/i386/sse2-check.h
> > @@ -1,7 +1,5 @@
> >  #include <stdlib.h>
> > -#include "cpuid.h"
> >  #include "m128-check.h"
> > -#include "sse-os-support.h"
> >
> >  static void sse2_test (void);
> >
> > @@ -15,13 +13,8 @@ do_test (void)
> >  int
> >  main ()
> >  {
> > -  unsigned int eax, ebx, ecx, edx;
> > -
> > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > -    return 0;
> > -
> > -  /* Run SSE2 test only if host has SSE2 support.  */
> > -  if ((edx & bit_SSE2) && sse_os_support ())
> > +  /* Check cpu support for SSE2.  */
> > +  if (__builtin_cpu_supports ("sse2"))
> >      do_test ();
> >
> >    return 0;
> > diff --git a/gcc/testsuite/gcc.target/i386/sse3-check.h b/gcc/testsuite/gcc.target/i386/sse3-check.h
> > index 5a0a0b1a02e..3c58361e925 100644
> > --- a/gcc/testsuite/gcc.target/i386/sse3-check.h
> > +++ b/gcc/testsuite/gcc.target/i386/sse3-check.h
> > @@ -1,7 +1,5 @@
> >  #include <stdio.h>
> >  #include <stdlib.h>
> > -#include "cpuid.h"
> > -#include "sse-os-support.h"
> >
> >  static void sse3_test (void);
> >
> > @@ -15,13 +13,8 @@ do_test (void)
> >  int
> >  main ()
> >  {
> > -  unsigned int eax, ebx, ecx, edx;
> > -
> > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > -    return 0;
> > -
> > -  /* Run SSE3 test only if host has SSE3 support.  */
> > -  if ((ecx & bit_SSE3) && sse_os_support ())
> > +  /* Check cpu support for SSE3.  */
> > +  if (__builtin_cpu_supports ("sse3"))
> >      do_test ();
> >
> >    return 0;
> > diff --git a/gcc/testsuite/gcc.target/i386/sse4_1-check.h b/gcc/testsuite/gcc.target/i386/sse4_1-check.h
> > index 788f65d61cb..61d0d0284a8 100644
> > --- a/gcc/testsuite/gcc.target/i386/sse4_1-check.h
> > +++ b/gcc/testsuite/gcc.target/i386/sse4_1-check.h
> > @@ -1,6 +1,4 @@
> >  #include <stdlib.h>
> > -
> > -#include "cpuid.h"
> >  #include "m128-check.h"
> >
> >  static void sse4_1_test (void);
> > @@ -17,13 +15,8 @@ do_test (void)
> >  int
> >  main ()
> >  {
> > -  unsigned int eax, ebx, ecx, edx;
> > -
> > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > -    return 0;
> > -
> > -  /* Run SSE4.1 test only if host has SSE4.1 support.  */
> > -  if (ecx & bit_SSE4_1)
> > +  /* Check cpu support for SSE4.1.  */
> > +  if (__builtin_cpu_supports ("sse4.1"))
> >      do_test ();
> >
> >    return 0;
> > diff --git a/gcc/testsuite/gcc.target/i386/sse4_2-check.h b/gcc/testsuite/gcc.target/i386/sse4_2-check.h
> > index c33cd1b4986..6c921ac52c7 100644
> > --- a/gcc/testsuite/gcc.target/i386/sse4_2-check.h
> > +++ b/gcc/testsuite/gcc.target/i386/sse4_2-check.h
> > @@ -1,8 +1,6 @@
> >  #include <stdio.h>
> >  #include <stdlib.h>
> > -
> >  #include "m128-check.h"
> > -#include "cpuid.h"
> >
> >  static void sse4_2_test (void);
> >
> > @@ -16,13 +14,8 @@ do_test (void)
> >  int
> >  main ()
> >  {
> > -  unsigned int eax, ebx, ecx, edx;
> > -
> > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > -    return 0;
> > -
> > -  /* Run SSE4.2 test only if host has SSE4.2 support.  */
> > -  if (ecx & bit_SSE4_2)
> > +  /* Check cpu support for SSE4.2.  */
> > +  if (__builtin_cpu_supports ("sse4.2"))
> >      do_test ();
> >
> >    return 0;
> > diff --git a/gcc/testsuite/gcc.target/i386/sse4a-check.h b/gcc/testsuite/gcc.target/i386/sse4a-check.h
> > index d43b4b222b1..ae70ff0a268 100644
> > --- a/gcc/testsuite/gcc.target/i386/sse4a-check.h
> > +++ b/gcc/testsuite/gcc.target/i386/sse4a-check.h
> > @@ -1,8 +1,6 @@
> >  #include <stdio.h>
> >  #include <stdlib.h>
> >
> > -#include "cpuid.h"
> > -
> >  static void sse4a_test (void);
> >
> >  static void
> > @@ -15,13 +13,8 @@ do_test (void)
> >  int
> >  main ()
> >  {
> > -  unsigned int eax, ebx, ecx, edx;
> > -
> > -  if (!__get_cpuid (0x80000001, &eax, &ebx, &ecx, &edx))
> > -    return 0;
> > -
> > -  /* Run SSE4a test only if host has SSE4a support.  */
> > -  if (ecx & bit_SSE4a)
> > +  /* Check cpu support for SSE4a.  */
> > +  if (__builtin_cpu_supports ("sse4a"))
> >      do_test ();
> >
> >    return 0;
> > diff --git a/gcc/testsuite/gcc.target/i386/ssse3-check.h b/gcc/testsuite/gcc.target/i386/ssse3-check.h
> > index 3ca79333c7f..3e834811f2d 100644
> > --- a/gcc/testsuite/gcc.target/i386/ssse3-check.h
> > +++ b/gcc/testsuite/gcc.target/i386/ssse3-check.h
> > @@ -1,8 +1,6 @@
> >  #include <stdio.h>
> >  #include <stdlib.h>
> >
> > -#include "cpuid.h"
> > -
> >  static void ssse3_test (void);
> >
> >  static void
> > @@ -15,13 +13,8 @@ do_test (void)
> >  int
> >  main ()
> >  {
> > -  unsigned int eax, ebx, ecx, edx;
> > -
> > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > -    return 0;
> > -
> > -  /* Run SSSE3 test only if host has SSSE3 support.  */
> > -  if (ecx & bit_SSSE3)
> > +  /* Check cpu support for SSSE3.  */
> > +  if (__builtin_cpu_supports ("ssse3"))
> >      do_test ();
> >
> >    return 0;
> > diff --git a/gcc/testsuite/gcc.target/i386/xop-check.h b/gcc/testsuite/gcc.target/i386/xop-check.h
> > index 395abe8766d..e1ef1273111 100644
> > --- a/gcc/testsuite/gcc.target/i386/xop-check.h
> > +++ b/gcc/testsuite/gcc.target/i386/xop-check.h
> > @@ -1,6 +1,4 @@
> >  #include <stdlib.h>
> > -
> > -#include "cpuid.h"
> >  #include "m256-check.h"
> >
> >  static void xop_test (void);
> > @@ -15,13 +13,8 @@ do_test (void)
> >  int
> >  main ()
> >  {
> > -  unsigned int eax, ebx, ecx, edx;
> > -
> > -  if (!__get_cpuid (0x80000001, &eax, &ebx, &ecx, &edx))
> > -    return 0;
> > -
> > -  /* Run XOP test only if host has XOP support.  */
> > -  if (ecx & bit_XOP)
> > +  /* Check cpu support for XOP.  */
> > +  if (__builtin_cpu_supports ("xop"))
> >      do_test ();
> >
> >    return 0;
> > --
> > 2.18.1
> >
Uros Bizjak May 6, 2022, 9:17 a.m. UTC | #3
On Fri, May 6, 2022 at 11:00 AM Hongyu Wang <wwwhhhyyy333@gmail.com> wrote:
>
> > I don't think *_os_support calls should be removed. IIRC,
> > __builtin_cpu_supports function checks if the feature is supported by
> > CPU, whereas *_os_supports calls check via xgetbv if OS supports
> > handling of new registers.
>
> avx_os_support is like
>
> avx_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_SSE | XSTATE_YMM)) == (XSTATE_SSE | XSTATE_YMM);
> }
>
> While in get_avaliable_features we have
>
> #define XCR_AVX_ENABLED_MASK \
>   (XSTATE_SSE | XSTATE_YMM)
>   if ((ecx & bit_OSXSAVE))
>     {
>       /* Check if XMM, YMM, OPMASK, upper 256 bits of ZMM0-ZMM15 and
> ZMM16-ZMM31 states are supported by OSXSAVE.  */
>       unsigned int xcrlow;
>       unsigned int xcrhigh;
>       __asm__ (".byte 0x0f, 0x01, 0xd0" /* xgetbv  */
>        : "=a" (xcrlow), "=d" (xcrhigh)
>        : "c" (XCR_XFEATURE_ENABLED_MASK));
>       if ((xcrlow & XCR_AVX_ENABLED_MASK) == XCR_AVX_ENABLED_MASK)
> {
>   avx_usable = 1;
>
> So __builtin_cpu_supports already inherits same check

Indeed, thanks for the explanation.

OTOH, we don't change the existing tests (perhaps only dg- directives
when infrastructure improves), so I would leave the existing testcases
as they are. In future, new helper functions should be implemented
with __builtin_cpu_supports, but let's leave existing ones as they
are.

Uros.

> Uros Bizjak via Gcc-patches <gcc-patches@gcc.gnu.org> 于2022年5月6日周五 16:27写道:
> >
> > On Fri, May 6, 2022 at 9:57 AM Haochen Jiang <haochen.jiang@intel.com> wrote:
> > >
> > > Hi all,
> > >
> > > There are some check files in i386 testsuite are written before the function __builtin_cpu_supports is introduced. All of them are using __get_cpuid_count. This patch aims to reconstruct the i386 testsuite with __builtin_cpu_supports so that we can have a much clearer code.
> > >
> > > Regtested on x86_64-pc-linux-gnu. Ok for trunk?
> >
> > I don't think *_os_support calls should be removed. IIRC,
> > __builtin_cpu_supports function checks if the feature is supported by
> > CPU, whereas *_os_supports calls check via xgetbv if OS supports
> > handling of new registers.
> >
> > Uros.
> >
> > >
> > > Also when writting this patch, I also find some files in testsuite that might be useless currently. For example, in the file gcc/testsuite/gcc.target/i386/sse-os-support.h, it always return 1. And there are also some files will no longer be included at all with this patch. Should we remove those files when we have time?
> > >
> > > BRs,
> > > Haochen
> > >
> > > gcc/testsuite/ChangeLog:
> > >
> > >         * gcc.target/i386/adx-check.h: Change bit check to
> > >         __builtin_cpu_supports.
> > >         * gcc.target/i386/aes-avx-check.h: Ditto.
> > >         * gcc.target/i386/aes-check.h: Ditto.
> > >         * gcc.target/i386/avx-check.h: Ditto.
> > >         * gcc.target/i386/avx2-check.h: Ditto.
> > >         * gcc.target/i386/avx512-check.h: Ditto.
> > >         * gcc.target/i386/bmi-check.h: Ditto.
> > >         * gcc.target/i386/bmi2-check.h: Ditto.
> > >         * gcc.target/i386/f16c-check.h: Ditto.
> > >         * gcc.target/i386/fma-check.h: Ditto.
> > >         * gcc.target/i386/fma4-check.h: Ditto.
> > >         * gcc.target/i386/lzcnt-check.h: Ditto.
> > >         * gcc.target/i386/mmx-3dnow-check.h: Ditto.
> > >         * gcc.target/i386/mmx-check.h: Ditto.
> > >         * gcc.target/i386/pclmul-avx-check.h: Ditto.
> > >         * gcc.target/i386/pclmul-check.h: Ditto.
> > >         * gcc.target/i386/rtm-check.h: Ditto.
> > >         * gcc.target/i386/sha-check.h: Ditto.
> > >         * gcc.target/i386/sse-check.h: Ditto.
> > >         * gcc.target/i386/sse2-check.h: Ditto.
> > >         * gcc.target/i386/sse3-check.h: Ditto.
> > >         * gcc.target/i386/sse4_1-check.h: Ditto.
> > >         * gcc.target/i386/sse4_2-check.h: Ditto.
> > >         * gcc.target/i386/sse4a-check.h: Ditto.
> > >         * gcc.target/i386/ssse3-check.h: Ditto.
> > >         * gcc.target/i386/xop-check.h: Ditto.
> > > ---
> > >  gcc/testsuite/gcc.target/i386/adx-check.h     | 10 +---
> > >  gcc/testsuite/gcc.target/i386/aes-avx-check.h | 14 +----
> > >  gcc/testsuite/gcc.target/i386/aes-check.h     | 11 +---
> > >  gcc/testsuite/gcc.target/i386/avx-check.h     | 12 +---
> > >  gcc/testsuite/gcc.target/i386/avx2-check.h    | 20 +------
> > >  gcc/testsuite/gcc.target/i386/avx512-check.h  | 59 +++++++------------
> > >  gcc/testsuite/gcc.target/i386/bmi-check.h     | 11 +---
> > >  gcc/testsuite/gcc.target/i386/bmi2-check.h    | 10 +---
> > >  gcc/testsuite/gcc.target/i386/f16c-check.h    | 10 +---
> > >  gcc/testsuite/gcc.target/i386/fma-check.h     | 11 +---
> > >  gcc/testsuite/gcc.target/i386/fma4-check.h    | 11 +---
> > >  gcc/testsuite/gcc.target/i386/lzcnt-check.h   | 11 +---
> > >  .../gcc.target/i386/mmx-3dnow-check.h         | 11 +---
> > >  gcc/testsuite/gcc.target/i386/mmx-check.h     | 11 +---
> > >  .../gcc.target/i386/pclmul-avx-check.h        | 14 +----
> > >  gcc/testsuite/gcc.target/i386/pclmul-check.h  | 11 +---
> > >  gcc/testsuite/gcc.target/i386/rtm-check.h     | 10 +---
> > >  gcc/testsuite/gcc.target/i386/sha-check.h     | 10 +---
> > >  gcc/testsuite/gcc.target/i386/sse-check.h     | 11 +---
> > >  gcc/testsuite/gcc.target/i386/sse2-check.h    | 11 +---
> > >  gcc/testsuite/gcc.target/i386/sse3-check.h    | 11 +---
> > >  gcc/testsuite/gcc.target/i386/sse4_1-check.h  | 11 +---
> > >  gcc/testsuite/gcc.target/i386/sse4_2-check.h  | 11 +---
> > >  gcc/testsuite/gcc.target/i386/sse4a-check.h   | 11 +---
> > >  gcc/testsuite/gcc.target/i386/ssse3-check.h   | 11 +---
> > >  gcc/testsuite/gcc.target/i386/xop-check.h     | 11 +---
> > >  26 files changed, 73 insertions(+), 272 deletions(-)
> > >
> > > diff --git a/gcc/testsuite/gcc.target/i386/adx-check.h b/gcc/testsuite/gcc.target/i386/adx-check.h
> > > index cfed1a38483..bed5dcca385 100644
> > > --- a/gcc/testsuite/gcc.target/i386/adx-check.h
> > > +++ b/gcc/testsuite/gcc.target/i386/adx-check.h
> > > @@ -1,5 +1,4 @@
> > >  #include <stdlib.h>
> > > -#include "cpuid.h"
> > >
> > >  static void adx_test (void);
> > >
> > > @@ -11,13 +10,8 @@ static void __attribute__ ((noinline)) do_test (void)
> > >  int
> > >  main ()
> > >  {
> > > -  unsigned int eax, ebx, ecx, edx;
> > > -
> > > -  if (!__get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx))
> > > -    return 0;
> > > -
> > > -  /* Run ADX test only if host has ADX support.  */
> > > -  if (ebx & bit_ADX)
> > > +  /* Check cpu support for ADX.  */
> > > +  if (__builtin_cpu_supports ("adx"))
> > >      {
> > >        do_test ();
> > >  #ifdef DEBUG
> > > diff --git a/gcc/testsuite/gcc.target/i386/aes-avx-check.h b/gcc/testsuite/gcc.target/i386/aes-avx-check.h
> > > index f2a4ead4014..74bf597ead4 100644
> > > --- a/gcc/testsuite/gcc.target/i386/aes-avx-check.h
> > > +++ b/gcc/testsuite/gcc.target/i386/aes-avx-check.h
> > > @@ -2,8 +2,6 @@
> > >  #include <stdio.h>
> > >  #endif
> > >  #include <stdlib.h>
> > > -#include "cpuid.h"
> > > -#include "avx-os-support.h"
> > >
> > >  static void aes_avx_test (void);
> > >
> > > @@ -17,15 +15,9 @@ do_test (void)
> > >  int
> > >  main ()
> > >  {
> > > -  unsigned int eax, ebx, ecx, edx;
> > > -
> > > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > > -    return 0;
> > > -
> > > -  /* Run AES + AVX test only if host has AES + AVX support.  */
> > > -  if (((ecx & (bit_AVX | bit_OSXSAVE | bit_AES))
> > > -       == (bit_AVX | bit_OSXSAVE | bit_AES))
> > > -      && avx_os_support ())
> > > +  /* Check cpu support for AES and AVX.  */
> > > +  if (__builtin_cpu_supports ("avx")
> > > +      && __builtin_cpu_supports ("aes"))
> > >      {
> > >        do_test ();
> > >  #ifdef DEBUG
> > > diff --git a/gcc/testsuite/gcc.target/i386/aes-check.h b/gcc/testsuite/gcc.target/i386/aes-check.h
> > > index 7e794423e47..7c3a3b324a7 100644
> > > --- a/gcc/testsuite/gcc.target/i386/aes-check.h
> > > +++ b/gcc/testsuite/gcc.target/i386/aes-check.h
> > > @@ -1,8 +1,6 @@
> > >  #include <stdio.h>
> > >  #include <stdlib.h>
> > >
> > > -#include "cpuid.h"
> > > -
> > >  static void aes_test (void);
> > >
> > >  static void
> > > @@ -15,13 +13,8 @@ do_test (void)
> > >  int
> > >  main ()
> > >  {
> > > -  unsigned int eax, ebx, ecx, edx;
> > > -
> > > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > > -    return 0;
> > > -
> > > -  /* Run AES test only if host has AES support.  */
> > > -  if (ecx & bit_AES)
> > > +  /* Check cpu support for AES.  */
> > > +  if (__builtin_cpu_supports ("aes"))
> > >      {
> > >        do_test ();
> > >  #ifdef DEBUG
> > > diff --git a/gcc/testsuite/gcc.target/i386/avx-check.h b/gcc/testsuite/gcc.target/i386/avx-check.h
> > > index 7ddca9d7b80..4a3dbc257bc 100644
> > > --- a/gcc/testsuite/gcc.target/i386/avx-check.h
> > > +++ b/gcc/testsuite/gcc.target/i386/avx-check.h
> > > @@ -1,7 +1,5 @@
> > >  #include <stdlib.h>
> > > -#include "cpuid.h"
> > >  #include "m256-check.h"
> > > -#include "avx-os-support.h"
> > >
> > >  static void avx_test (void);
> > >
> > > @@ -15,14 +13,8 @@ do_test (void)
> > >  int
> > >  main ()
> > >  {
> > > -  unsigned int eax, ebx, ecx, edx;
> > > -
> > > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > > -    return 0;
> > > -
> > > -  /* Run AVX test only if host has AVX support.  */
> > > -  if (((ecx & (bit_AVX | bit_OSXSAVE)) == (bit_AVX | bit_OSXSAVE))
> > > -      && avx_os_support ())
> > > +  /* Check cpu support for AVX.  */
> > > +  if (__builtin_cpu_supports ("avx"))
> > >      {
> > >        do_test ();
> > >  #ifdef DEBUG
> > > diff --git a/gcc/testsuite/gcc.target/i386/avx2-check.h b/gcc/testsuite/gcc.target/i386/avx2-check.h
> > > index 25bed5e0da6..2bc3c4425bb 100644
> > > --- a/gcc/testsuite/gcc.target/i386/avx2-check.h
> > > +++ b/gcc/testsuite/gcc.target/i386/avx2-check.h
> > > @@ -1,7 +1,5 @@
> > >  #include <stdlib.h>
> > > -#include "cpuid.h"
> > >  #include "m256-check.h"
> > > -#include "avx-os-support.h"
> > >
> > >  static void avx2_test (void);
> > >
> > > @@ -10,25 +8,11 @@ static void __attribute__ ((noinline)) do_test (void)
> > >    avx2_test ();
> > >  }
> > >
> > > -static int
> > > -check_osxsave (void)
> > > -{
> > > -  unsigned int eax, ebx, ecx, edx;
> > > -
> > > -  __cpuid (1, eax, ebx, ecx, edx);
> > > -  return (ecx & bit_OSXSAVE) != 0;
> > > -}
> > > -
> > >  int
> > >  main ()
> > >  {
> > > -  unsigned int eax, ebx, ecx, edx;
> > > -
> > > -  if (!__get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx))
> > > -    return 0;
> > > -
> > > -  /* Run AVX2 test only if host has AVX2 support.  */
> > > -  if (check_osxsave () && (ebx & bit_AVX2) && avx_os_support ())
> > > +  /* Check cpu support for AVX2.  */
> > > +  if (__builtin_cpu_supports ("avx2"))
> > >      {
> > >        do_test ();
> > >  #ifdef DEBUG
> > > diff --git a/gcc/testsuite/gcc.target/i386/avx512-check.h b/gcc/testsuite/gcc.target/i386/avx512-check.h
> > > index 0ad9064f637..339c79070c9 100644
> > > --- a/gcc/testsuite/gcc.target/i386/avx512-check.h
> > > +++ b/gcc/testsuite/gcc.target/i386/avx512-check.h
> > > @@ -1,7 +1,5 @@
> > >  #include <stdlib.h>
> > > -#include "cpuid.h"
> > >  #include "m512-check.h"
> > > -#include "avx512f-os-support.h"
> > >
> > >  #ifndef DO_TEST
> > >  #define DO_TEST do_test
> > > @@ -25,81 +23,66 @@ do_test (void)
> > >  }
> > >  #endif
> > >
> > > -static int
> > > -check_osxsave (void)
> > > -{
> > > -  unsigned int eax, ebx, ecx, edx;
> > > -
> > > -  __cpuid (1, eax, ebx, ecx, edx);
> > > -  return (ecx & bit_OSXSAVE) != 0;
> > > -}
> > > -
> > >  int
> > >  main ()
> > >  {
> > > -  unsigned int eax, ebx, ecx, edx;
> > > -
> > > -  if (!__get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx))
> > > -    return 0;
> > > -
> > > -  /* Run AVX512 test only if host has ISA support.  */
> > > -  if (check_osxsave ()
> > > -      && (ebx & bit_AVX512F)
> > > +  /* Check cpu support for AVX512.  */
> > > +  if (__builtin_cpu_supports ("avx512f")
> > >  #ifdef AVX512VL
> > > -      && (ebx & bit_AVX512VL)
> > > +      && __builtin_cpu_supports ("avx512vl")
> > >  #endif
> > >  #ifdef AVX512ER
> > > -      && (ebx & bit_AVX512ER)
> > > +      && __builtin_cpu_supports ("avx512er")
> > >  #endif
> > >  #ifdef AVX512CD
> > > -      && (ebx & bit_AVX512CD)
> > > +      && __builtin_cpu_supports ("avx512cd")
> > >  #endif
> > >  #ifdef AVX512DQ
> > > -      && (ebx & bit_AVX512DQ)
> > > +      && __builtin_cpu_supports ("avx512dq")
> > >  #endif
> > >  #ifdef AVX512BW
> > > -      && (ebx & bit_AVX512BW)
> > > +      && __builtin_cpu_supports ("avx512bw")
> > >  #endif
> > >  #ifdef AVX512IFMA
> > > -      && (ebx & bit_AVX512IFMA)
> > > +      && __builtin_cpu_supports ("avx512ifma")
> > >  #endif
> > >  #ifdef AVX512VBMI
> > > -      && (ecx & bit_AVX512VBMI)
> > > +      && __builtin_cpu_supports ("avx512vbmi")
> > >  #endif
> > >  #ifdef AVX5124FMAPS
> > > -      && (edx & bit_AVX5124FMAPS)
> > > +      && __builtin_cpu_supports ("avx5124fmaps")
> > >  #endif
> > >  #ifdef AVX5124VNNIW
> > > -      && (edx & bit_AVX5124VNNIW)
> > > +      && __builtin_cpu_supports ("avx5124vnniw")
> > >  #endif
> > >  #ifdef AVX512VPOPCNTDQ
> > > -      && (ecx & bit_AVX512VPOPCNTDQ)
> > > +      && __builtin_cpu_supports ("avx512vpopcntdq")
> > >  #endif
> > >  #ifdef AVX512BITALG
> > > -      && (ecx & bit_AVX512BITALG)
> > > +      && __builtin_cpu_supports ("avx512bitalg")
> > >  #endif
> > >  #ifdef GFNI
> > > -      && (ecx & bit_GFNI)
> > > +      && __builtin_cpu_supports ("gfni")
> > >  #endif
> > >  #ifdef AVX512VBMI2
> > > -      && (ecx & bit_AVX512VBMI2)
> > > +      && __builtin_cpu_supports ("avx512vbmi2")
> > >  #endif
> > >  #ifdef AVX512VNNI
> > > -      && (ecx & bit_AVX512VNNI)
> > > +      && __builtin_cpu_supports ("avx512vnni")
> > >  #endif
> > >  #ifdef AVX512FP16
> > > -      && (edx & bit_AVX512FP16)
> > > +      && __builtin_cpu_supports ("avx512fp16")
> > >  #endif
> > >  #ifdef VAES
> > > -      && (ecx & bit_VAES)
> > > +      && __builtin_cpu_supports ("vaes")
> > >  #endif
> > >  #ifdef VPCLMULQDQ
> > > -      && (ecx & bit_VPCLMULQDQ)
> > > +      && __builtin_cpu_supports ("vpclmulqdq")
> > >  #endif
> > >  #ifdef AVX512VP2INTERSECT
> > > -      && (edx & bit_AVX512VP2INTERSECT)
> > > +      && __builtin_cpu_supports ("avx512vp2intersect")
> > >  #endif
> > > -      && avx512f_os_support ())
> > > +      )
> > >      {
> > >        DO_TEST ();
> > >  #ifdef DEBUG
> > > diff --git a/gcc/testsuite/gcc.target/i386/bmi-check.h b/gcc/testsuite/gcc.target/i386/bmi-check.h
> > > index 1973f3b6468..6af0291a947 100644
> > > --- a/gcc/testsuite/gcc.target/i386/bmi-check.h
> > > +++ b/gcc/testsuite/gcc.target/i386/bmi-check.h
> > > @@ -1,8 +1,6 @@
> > >  #include <stdio.h>
> > >  #include <stdlib.h>
> > >
> > > -#include "cpuid.h"
> > > -
> > >  static void bmi_test (void);
> > >
> > >  static void
> > > @@ -15,13 +13,8 @@ do_test (void)
> > >  int
> > >  main ()
> > >  {
> > > -  unsigned int eax, ebx, ecx, edx;
> > > -
> > > -  if (!__get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx))
> > > -    return 0;
> > > -
> > > -  /* Run BMI test only if host has BMI support.  */
> > > -  if (ebx & bit_BMI)
> > > +  /* Check cpu support for BMI.  */
> > > +  if (__builtin_cpu_supports ("bmi"))
> > >      {
> > >        do_test ();
> > >  #ifdef DEBUG
> > > diff --git a/gcc/testsuite/gcc.target/i386/bmi2-check.h b/gcc/testsuite/gcc.target/i386/bmi2-check.h
> > > index ba91ef9b780..75c4d8d9616 100644
> > > --- a/gcc/testsuite/gcc.target/i386/bmi2-check.h
> > > +++ b/gcc/testsuite/gcc.target/i386/bmi2-check.h
> > > @@ -1,6 +1,5 @@
> > >  #include <stdio.h>
> > >  #include <stdlib.h>
> > > -#include "cpuid.h"
> > >
> > >  static void bmi2_test (void);
> > >
> > > @@ -14,13 +13,8 @@ do_test (void)
> > >  int
> > >  main ()
> > >  {
> > > -  unsigned int eax, ebx, ecx, edx;
> > > -
> > > -  if (!__get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx))
> > > -    return 0;
> > > -
> > > -  /* Run BMI2 test only if host has BMI2 support.  */
> > > -  if (ebx & bit_BMI2)
> > > +  /* Check cpu support for BMI2.  */
> > > +  if (__builtin_cpu_supports ("bmi2"))
> > >      {
> > >        do_test ();
> > >  #ifdef DEBUG
> > > diff --git a/gcc/testsuite/gcc.target/i386/f16c-check.h b/gcc/testsuite/gcc.target/i386/f16c-check.h
> > > index af7f32c5f4f..2cbf34ab516 100644
> > > --- a/gcc/testsuite/gcc.target/i386/f16c-check.h
> > > +++ b/gcc/testsuite/gcc.target/i386/f16c-check.h
> > > @@ -1,6 +1,5 @@
> > >  #include <stdlib.h>
> > >  #include <stdio.h>
> > > -#include "cpuid.h"
> > >  #include "m256-check.h"
> > >
> > >  static void f16c_test (void);
> > > @@ -8,13 +7,8 @@ static void f16c_test (void);
> > >  int
> > >  main ()
> > >  {
> > > -  unsigned int eax, ebx, ecx, edx;
> > > -
> > > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > > -    return 0;
> > > -
> > > -  /* Run F16C test only if host has F16C support.  */
> > > -  if (ecx & bit_F16C)
> > > +  /* Check cpu support for F16C.  */
> > > +  if (__builtin_cpu_supports ("f16c"))
> > >      {
> > >        f16c_test ();
> > >  #ifdef DEBUG
> > > diff --git a/gcc/testsuite/gcc.target/i386/fma-check.h b/gcc/testsuite/gcc.target/i386/fma-check.h
> > > index 8390f5088bd..6c1d3372218 100644
> > > --- a/gcc/testsuite/gcc.target/i386/fma-check.h
> > > +++ b/gcc/testsuite/gcc.target/i386/fma-check.h
> > > @@ -1,7 +1,5 @@
> > >  #include <stdlib.h>
> > >
> > > -#include "cpuid.h"
> > > -
> > >  static void fma_test (void);
> > >
> > >  static void __attribute__ ((noinline)) do_test (void)
> > > @@ -12,13 +10,8 @@ static void __attribute__ ((noinline)) do_test (void)
> > >  int
> > >  main ()
> > >  {
> > > -  unsigned int eax, ebx, ecx, edx;
> > > -
> > > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > > -    return 0;
> > > -
> > > -  /* Run FMA test only if host has FMA support.  */
> > > -  if (ecx & bit_FMA)
> > > +  /* Check cpu support for FMA.  */
> > > +  if (__builtin_cpu_supports ("fma"))
> > >      do_test ();
> > >
> > >    return 0;
> > > diff --git a/gcc/testsuite/gcc.target/i386/fma4-check.h b/gcc/testsuite/gcc.target/i386/fma4-check.h
> > > index 33cd9628c04..2d2c2718029 100644
> > > --- a/gcc/testsuite/gcc.target/i386/fma4-check.h
> > > +++ b/gcc/testsuite/gcc.target/i386/fma4-check.h
> > > @@ -1,7 +1,5 @@
> > >  #include <stdlib.h>
> > >
> > > -#include "cpuid.h"
> > > -
> > >  static void fma4_test (void);
> > >
> > >  static void
> > > @@ -14,13 +12,8 @@ do_test (void)
> > >  int
> > >  main ()
> > >  {
> > > -  unsigned int eax, ebx, ecx, edx;
> > > -
> > > -  if (!__get_cpuid (0x80000001, &eax, &ebx, &ecx, &edx))
> > > -    return 0;
> > > -
> > > -  /* Run FMA4 test only if host has FMA4 support.  */
> > > -  if (ecx & bit_FMA4)
> > > +  /* Check cpu support foe FMA4.  */
> > > +  if (__builtin_cpu_supports ("fma4"))
> > >      do_test ();
> > >
> > >    return 0;
> > > diff --git a/gcc/testsuite/gcc.target/i386/lzcnt-check.h b/gcc/testsuite/gcc.target/i386/lzcnt-check.h
> > > index 8aad834d6af..824f1a3b513 100644
> > > --- a/gcc/testsuite/gcc.target/i386/lzcnt-check.h
> > > +++ b/gcc/testsuite/gcc.target/i386/lzcnt-check.h
> > > @@ -1,8 +1,6 @@
> > >  #include <stdio.h>
> > >  #include <stdlib.h>
> > >
> > > -#include "cpuid.h"
> > > -
> > >  static void lzcnt_test (void);
> > >
> > >  static void
> > > @@ -15,13 +13,8 @@ do_test (void)
> > >  int
> > >  main ()
> > >  {
> > > -  unsigned int eax, ebx, ecx, edx;
> > > -
> > > -  if (!__get_cpuid (0x80000001, &eax, &ebx, &ecx, &edx))
> > > -    return 0;
> > > -
> > > -  /* Run LZCNT test only if host has LZCNT support.  */
> > > -  if (ecx & bit_LZCNT)
> > > +  /* Check cpu support for LZCNT.  */
> > > +  if (__builtin_cpu_supports ("lzcnt"))
> > >      {
> > >        do_test ();
> > >  #ifdef DEBUG
> > > diff --git a/gcc/testsuite/gcc.target/i386/mmx-3dnow-check.h b/gcc/testsuite/gcc.target/i386/mmx-3dnow-check.h
> > > index 4f2f7f3ac40..0ec2dca2e19 100644
> > > --- a/gcc/testsuite/gcc.target/i386/mmx-3dnow-check.h
> > > +++ b/gcc/testsuite/gcc.target/i386/mmx-3dnow-check.h
> > > @@ -1,8 +1,6 @@
> > >  #include <stdio.h>
> > >  #include <stdlib.h>
> > >
> > > -#include "cpuid.h"
> > > -
> > >  static void mmx_3dnow_test (void);
> > >
> > >  static void
> > > @@ -15,13 +13,8 @@ do_test (void)
> > >  int
> > >  main ()
> > >  {
> > > -  unsigned int eax, ebx, ecx, edx;
> > > -
> > > -  if (!__get_cpuid (0x80000001, &eax, &ebx, &ecx, &edx))
> > > -    return 0;
> > > -
> > > -  /* Run 3DNow! test only if host has 3DNow! support.  */
> > > -  if (edx & bit_3DNOW)
> > > +  /* Check cpu support for 3DNow!.  */
> > > +  if (__builtin_cpu_supports ("3dnow"))
> > >      do_test ();
> > >
> > >    return 0;
> > > diff --git a/gcc/testsuite/gcc.target/i386/mmx-check.h b/gcc/testsuite/gcc.target/i386/mmx-check.h
> > > index faf9b876f38..2afe5183ba2 100644
> > > --- a/gcc/testsuite/gcc.target/i386/mmx-check.h
> > > +++ b/gcc/testsuite/gcc.target/i386/mmx-check.h
> > > @@ -1,8 +1,6 @@
> > >  #include <stdio.h>
> > >  #include <stdlib.h>
> > >
> > > -#include "cpuid.h"
> > > -
> > >  static void mmx_test (void);
> > >
> > >  static void
> > > @@ -15,13 +13,8 @@ do_test (void)
> > >  int
> > >  main ()
> > >  {
> > > -  unsigned int eax, ebx, ecx, edx;
> > > -
> > > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > > -    return 0;
> > > -
> > > -  /* Run MMX test only if host has MMX support.  */
> > > -  if (edx & bit_MMX)
> > > +  /* Check cpu support for MMX.  */
> > > +  if (__builtin_cpu_supports ("mmx"))
> > >      do_test ();
> > >
> > >    return 0;
> > > diff --git a/gcc/testsuite/gcc.target/i386/pclmul-avx-check.h b/gcc/testsuite/gcc.target/i386/pclmul-avx-check.h
> > > index 5eed2e2203c..b506b3306e6 100644
> > > --- a/gcc/testsuite/gcc.target/i386/pclmul-avx-check.h
> > > +++ b/gcc/testsuite/gcc.target/i386/pclmul-avx-check.h
> > > @@ -2,8 +2,6 @@
> > >  #include <stdio.h>
> > >  #endif
> > >  #include <stdlib.h>
> > > -#include "cpuid.h"
> > > -#include "avx-os-support.h"
> > >
> > >  static void pclmul_avx_test (void);
> > >
> > > @@ -17,15 +15,9 @@ do_test (void)
> > >  int
> > >  main ()
> > >  {
> > > -  unsigned int eax, ebx, ecx, edx;
> > > -
> > > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > > -    return 0;
> > > -
> > > -  /* Run PCLMUL + AVX test only if host has PCLMUL + AVX support.  */
> > > -  if (((ecx & (bit_AVX | bit_OSXSAVE | bit_PCLMUL))
> > > -       == (bit_AVX | bit_OSXSAVE | bit_PCLMUL))
> > > -      && avx_os_support ())
> > > +  /* Check cpu support for PCLMUL and AVX.  */
> > > +  if (__builtin_cpu_supports ("pclmul")
> > > +      && __builtin_cpu_supports ("avx"))
> > >      {
> > >        do_test ();
> > >  #ifdef DEBUG
> > > diff --git a/gcc/testsuite/gcc.target/i386/pclmul-check.h b/gcc/testsuite/gcc.target/i386/pclmul-check.h
> > > index 7526cbe2ddf..3ed1a044627 100644
> > > --- a/gcc/testsuite/gcc.target/i386/pclmul-check.h
> > > +++ b/gcc/testsuite/gcc.target/i386/pclmul-check.h
> > > @@ -1,8 +1,6 @@
> > >  #include <stdio.h>
> > >  #include <stdlib.h>
> > >
> > > -#include "cpuid.h"
> > > -
> > >  static void pclmul_test (void);
> > >
> > >  static void
> > > @@ -15,13 +13,8 @@ do_test (void)
> > >  int
> > >  main ()
> > >  {
> > > -  unsigned int eax, ebx, ecx, edx;
> > > -
> > > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > > -    return 0;
> > > -
> > > -  /* Run PCLMULQDQ test only if host has PCLMULQDQ support.  */
> > > -  if (ecx & bit_PCLMUL)
> > > +  /* Check cpu support for PCLMUL.  */
> > > +  if (__builtin_cpu_supports ("pclmul"))
> > >      {
> > >        do_test ();
> > >  #ifdef DEBUG
> > > diff --git a/gcc/testsuite/gcc.target/i386/rtm-check.h b/gcc/testsuite/gcc.target/i386/rtm-check.h
> > > index bdb5a6dc0bf..4121e602a7f 100644
> > > --- a/gcc/testsuite/gcc.target/i386/rtm-check.h
> > > +++ b/gcc/testsuite/gcc.target/i386/rtm-check.h
> > > @@ -1,5 +1,4 @@
> > >  #include <stdlib.h>
> > > -#include "cpuid.h"
> > >
> > >  static void rtm_test (void);
> > >
> > > @@ -11,13 +10,8 @@ static void __attribute__ ((noinline)) do_test (void)
> > >  int
> > >  main ()
> > >  {
> > > -  unsigned int eax, ebx, ecx, edx;
> > > -
> > > -  if (!__get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx))
> > > -    return 0;
> > > -
> > > -  /* Run RTM test only if host has RTM support.  */
> > > -  if (ebx & bit_RTM)
> > > +  /* Check cpu support for RTM.  */
> > > +  if (__builtin_cpu_supports ("rtm"))
> > >      {
> > >        do_test ();
> > >  #ifdef DEBUG
> > > diff --git a/gcc/testsuite/gcc.target/i386/sha-check.h b/gcc/testsuite/gcc.target/i386/sha-check.h
> > > index 5bc5a59ab80..61ce43053f9 100644
> > > --- a/gcc/testsuite/gcc.target/i386/sha-check.h
> > > +++ b/gcc/testsuite/gcc.target/i386/sha-check.h
> > > @@ -1,5 +1,4 @@
> > >  #include <stdlib.h>
> > > -#include "cpuid.h"
> > >
> > >  static void sha_test (void);
> > >
> > > @@ -13,13 +12,8 @@ do_test (void)
> > >  int
> > >  main ()
> > >  {
> > > -  unsigned int eax, ebx, ecx, edx;
> > > -
> > > -  if (!__get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx))
> > > -    return 0;
> > > -
> > > -  /* Run SHA test only if host has SHA support.  */
> > > -  if (ebx & bit_SHA)
> > > +  /* Check cpu support for SHA.  */
> > > +  if (__builtin_cpu_supports ("sha"))
> > >      {
> > >        do_test ();
> > >  #ifdef DEBUG
> > > diff --git a/gcc/testsuite/gcc.target/i386/sse-check.h b/gcc/testsuite/gcc.target/i386/sse-check.h
> > > index 11b71bc3e97..58bc88c5598 100644
> > > --- a/gcc/testsuite/gcc.target/i386/sse-check.h
> > > +++ b/gcc/testsuite/gcc.target/i386/sse-check.h
> > > @@ -1,7 +1,5 @@
> > >  #include <stdlib.h>
> > >  #include "m128-check.h"
> > > -#include "cpuid.h"
> > > -#include "sse-os-support.h"
> > >
> > >  static void sse_test (void);
> > >
> > > @@ -15,13 +13,8 @@ do_test (void)
> > >  int
> > >  main ()
> > >  {
> > > -  unsigned int eax, ebx, ecx, edx;
> > > -
> > > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > > -    return 0;
> > > -
> > > -  /* Run SSE test only if host has SSE support.  */
> > > -  if ((edx & bit_SSE) && sse_os_support ())
> > > +  /* Check cpu support for SSE.  */
> > > +  if (__builtin_cpu_supports ("sse"))
> > >      do_test ();
> > >
> > >    return 0;
> > > diff --git a/gcc/testsuite/gcc.target/i386/sse2-check.h b/gcc/testsuite/gcc.target/i386/sse2-check.h
> > > index fd4a6ce1dbf..4976a27022d 100644
> > > --- a/gcc/testsuite/gcc.target/i386/sse2-check.h
> > > +++ b/gcc/testsuite/gcc.target/i386/sse2-check.h
> > > @@ -1,7 +1,5 @@
> > >  #include <stdlib.h>
> > > -#include "cpuid.h"
> > >  #include "m128-check.h"
> > > -#include "sse-os-support.h"
> > >
> > >  static void sse2_test (void);
> > >
> > > @@ -15,13 +13,8 @@ do_test (void)
> > >  int
> > >  main ()
> > >  {
> > > -  unsigned int eax, ebx, ecx, edx;
> > > -
> > > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > > -    return 0;
> > > -
> > > -  /* Run SSE2 test only if host has SSE2 support.  */
> > > -  if ((edx & bit_SSE2) && sse_os_support ())
> > > +  /* Check cpu support for SSE2.  */
> > > +  if (__builtin_cpu_supports ("sse2"))
> > >      do_test ();
> > >
> > >    return 0;
> > > diff --git a/gcc/testsuite/gcc.target/i386/sse3-check.h b/gcc/testsuite/gcc.target/i386/sse3-check.h
> > > index 5a0a0b1a02e..3c58361e925 100644
> > > --- a/gcc/testsuite/gcc.target/i386/sse3-check.h
> > > +++ b/gcc/testsuite/gcc.target/i386/sse3-check.h
> > > @@ -1,7 +1,5 @@
> > >  #include <stdio.h>
> > >  #include <stdlib.h>
> > > -#include "cpuid.h"
> > > -#include "sse-os-support.h"
> > >
> > >  static void sse3_test (void);
> > >
> > > @@ -15,13 +13,8 @@ do_test (void)
> > >  int
> > >  main ()
> > >  {
> > > -  unsigned int eax, ebx, ecx, edx;
> > > -
> > > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > > -    return 0;
> > > -
> > > -  /* Run SSE3 test only if host has SSE3 support.  */
> > > -  if ((ecx & bit_SSE3) && sse_os_support ())
> > > +  /* Check cpu support for SSE3.  */
> > > +  if (__builtin_cpu_supports ("sse3"))
> > >      do_test ();
> > >
> > >    return 0;
> > > diff --git a/gcc/testsuite/gcc.target/i386/sse4_1-check.h b/gcc/testsuite/gcc.target/i386/sse4_1-check.h
> > > index 788f65d61cb..61d0d0284a8 100644
> > > --- a/gcc/testsuite/gcc.target/i386/sse4_1-check.h
> > > +++ b/gcc/testsuite/gcc.target/i386/sse4_1-check.h
> > > @@ -1,6 +1,4 @@
> > >  #include <stdlib.h>
> > > -
> > > -#include "cpuid.h"
> > >  #include "m128-check.h"
> > >
> > >  static void sse4_1_test (void);
> > > @@ -17,13 +15,8 @@ do_test (void)
> > >  int
> > >  main ()
> > >  {
> > > -  unsigned int eax, ebx, ecx, edx;
> > > -
> > > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > > -    return 0;
> > > -
> > > -  /* Run SSE4.1 test only if host has SSE4.1 support.  */
> > > -  if (ecx & bit_SSE4_1)
> > > +  /* Check cpu support for SSE4.1.  */
> > > +  if (__builtin_cpu_supports ("sse4.1"))
> > >      do_test ();
> > >
> > >    return 0;
> > > diff --git a/gcc/testsuite/gcc.target/i386/sse4_2-check.h b/gcc/testsuite/gcc.target/i386/sse4_2-check.h
> > > index c33cd1b4986..6c921ac52c7 100644
> > > --- a/gcc/testsuite/gcc.target/i386/sse4_2-check.h
> > > +++ b/gcc/testsuite/gcc.target/i386/sse4_2-check.h
> > > @@ -1,8 +1,6 @@
> > >  #include <stdio.h>
> > >  #include <stdlib.h>
> > > -
> > >  #include "m128-check.h"
> > > -#include "cpuid.h"
> > >
> > >  static void sse4_2_test (void);
> > >
> > > @@ -16,13 +14,8 @@ do_test (void)
> > >  int
> > >  main ()
> > >  {
> > > -  unsigned int eax, ebx, ecx, edx;
> > > -
> > > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > > -    return 0;
> > > -
> > > -  /* Run SSE4.2 test only if host has SSE4.2 support.  */
> > > -  if (ecx & bit_SSE4_2)
> > > +  /* Check cpu support for SSE4.2.  */
> > > +  if (__builtin_cpu_supports ("sse4.2"))
> > >      do_test ();
> > >
> > >    return 0;
> > > diff --git a/gcc/testsuite/gcc.target/i386/sse4a-check.h b/gcc/testsuite/gcc.target/i386/sse4a-check.h
> > > index d43b4b222b1..ae70ff0a268 100644
> > > --- a/gcc/testsuite/gcc.target/i386/sse4a-check.h
> > > +++ b/gcc/testsuite/gcc.target/i386/sse4a-check.h
> > > @@ -1,8 +1,6 @@
> > >  #include <stdio.h>
> > >  #include <stdlib.h>
> > >
> > > -#include "cpuid.h"
> > > -
> > >  static void sse4a_test (void);
> > >
> > >  static void
> > > @@ -15,13 +13,8 @@ do_test (void)
> > >  int
> > >  main ()
> > >  {
> > > -  unsigned int eax, ebx, ecx, edx;
> > > -
> > > -  if (!__get_cpuid (0x80000001, &eax, &ebx, &ecx, &edx))
> > > -    return 0;
> > > -
> > > -  /* Run SSE4a test only if host has SSE4a support.  */
> > > -  if (ecx & bit_SSE4a)
> > > +  /* Check cpu support for SSE4a.  */
> > > +  if (__builtin_cpu_supports ("sse4a"))
> > >      do_test ();
> > >
> > >    return 0;
> > > diff --git a/gcc/testsuite/gcc.target/i386/ssse3-check.h b/gcc/testsuite/gcc.target/i386/ssse3-check.h
> > > index 3ca79333c7f..3e834811f2d 100644
> > > --- a/gcc/testsuite/gcc.target/i386/ssse3-check.h
> > > +++ b/gcc/testsuite/gcc.target/i386/ssse3-check.h
> > > @@ -1,8 +1,6 @@
> > >  #include <stdio.h>
> > >  #include <stdlib.h>
> > >
> > > -#include "cpuid.h"
> > > -
> > >  static void ssse3_test (void);
> > >
> > >  static void
> > > @@ -15,13 +13,8 @@ do_test (void)
> > >  int
> > >  main ()
> > >  {
> > > -  unsigned int eax, ebx, ecx, edx;
> > > -
> > > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > > -    return 0;
> > > -
> > > -  /* Run SSSE3 test only if host has SSSE3 support.  */
> > > -  if (ecx & bit_SSSE3)
> > > +  /* Check cpu support for SSSE3.  */
> > > +  if (__builtin_cpu_supports ("ssse3"))
> > >      do_test ();
> > >
> > >    return 0;
> > > diff --git a/gcc/testsuite/gcc.target/i386/xop-check.h b/gcc/testsuite/gcc.target/i386/xop-check.h
> > > index 395abe8766d..e1ef1273111 100644
> > > --- a/gcc/testsuite/gcc.target/i386/xop-check.h
> > > +++ b/gcc/testsuite/gcc.target/i386/xop-check.h
> > > @@ -1,6 +1,4 @@
> > >  #include <stdlib.h>
> > > -
> > > -#include "cpuid.h"
> > >  #include "m256-check.h"
> > >
> > >  static void xop_test (void);
> > > @@ -15,13 +13,8 @@ do_test (void)
> > >  int
> > >  main ()
> > >  {
> > > -  unsigned int eax, ebx, ecx, edx;
> > > -
> > > -  if (!__get_cpuid (0x80000001, &eax, &ebx, &ecx, &edx))
> > > -    return 0;
> > > -
> > > -  /* Run XOP test only if host has XOP support.  */
> > > -  if (ecx & bit_XOP)
> > > +  /* Check cpu support for XOP.  */
> > > +  if (__builtin_cpu_supports ("xop"))
> > >      do_test ();
> > >
> > >    return 0;
> > > --
> > > 2.18.1
> > >
Li, Pan2 via Gcc-patches May 7, 2022, 1:20 a.m. UTC | #4
Hi Uros,

I understand that we always keep the old testcases there. It is always safe to do that.

But I have another question, if we add something new in one of the existing files in the future,
should we use __builtin_cpu_supports to keep the code clearer or stick to cpuids?

I believe __builtin_cpu_supports will be a clearer way for a coder to understand under current circumstance.
So if we use that in future use, why don't we change everything to the same way?

BRs,
Haochen 

-----Original Message-----
From: Uros Bizjak <ubizjak@gmail.com> 
Sent: Friday, May 6, 2022 5:17 PM
To: Hongyu Wang <wwwhhhyyy333@gmail.com>
Cc: Jiang, Haochen <haochen.jiang@intel.com>; Liu, Hongtao <hongtao.liu@intel.com>; gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] Reconstruct i386 testsuite with __builtin_cpu_supports

On Fri, May 6, 2022 at 11:00 AM Hongyu Wang <wwwhhhyyy333@gmail.com> wrote:
>
> > I don't think *_os_support calls should be removed. IIRC,
> > __builtin_cpu_supports function checks if the feature is supported by
> > CPU, whereas *_os_supports calls check via xgetbv if OS supports
> > handling of new registers.
>
> avx_os_support is like
>
> avx_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_SSE | XSTATE_YMM)) == (XSTATE_SSE | XSTATE_YMM);
> }
>
> While in get_avaliable_features we have
>
> #define XCR_AVX_ENABLED_MASK \
>   (XSTATE_SSE | XSTATE_YMM)
>   if ((ecx & bit_OSXSAVE))
>     {
>       /* Check if XMM, YMM, OPMASK, upper 256 bits of ZMM0-ZMM15 and
> ZMM16-ZMM31 states are supported by OSXSAVE.  */
>       unsigned int xcrlow;
>       unsigned int xcrhigh;
>       __asm__ (".byte 0x0f, 0x01, 0xd0" /* xgetbv  */
>        : "=a" (xcrlow), "=d" (xcrhigh)
>        : "c" (XCR_XFEATURE_ENABLED_MASK));
>       if ((xcrlow & XCR_AVX_ENABLED_MASK) == XCR_AVX_ENABLED_MASK)
> {
>   avx_usable = 1;
>
> So __builtin_cpu_supports already inherits same check

Indeed, thanks for the explanation.

OTOH, we don't change the existing tests (perhaps only dg- directives
when infrastructure improves), so I would leave the existing testcases
as they are. In future, new helper functions should be implemented
with __builtin_cpu_supports, but let's leave existing ones as they
are.

Uros.

> Uros Bizjak via Gcc-patches <gcc-patches@gcc.gnu.org> 于2022年5月6日周五 16:27写道:
> >
> > On Fri, May 6, 2022 at 9:57 AM Haochen Jiang <haochen.jiang@intel.com> wrote:
> > >
> > > Hi all,
> > >
> > > There are some check files in i386 testsuite are written before the function __builtin_cpu_supports is introduced. All of them are using __get_cpuid_count. This patch aims to reconstruct the i386 testsuite with __builtin_cpu_supports so that we can have a much clearer code.
> > >
> > > Regtested on x86_64-pc-linux-gnu. Ok for trunk?
> >
> > I don't think *_os_support calls should be removed. IIRC,
> > __builtin_cpu_supports function checks if the feature is supported by
> > CPU, whereas *_os_supports calls check via xgetbv if OS supports
> > handling of new registers.
> >
> > Uros.
> >
> > >
> > > Also when writting this patch, I also find some files in testsuite that might be useless currently. For example, in the file gcc/testsuite/gcc.target/i386/sse-os-support.h, it always return 1. And there are also some files will no longer be included at all with this patch. Should we remove those files when we have time?
> > >
> > > BRs,
> > > Haochen
> > >
> > > gcc/testsuite/ChangeLog:
> > >
> > >         * gcc.target/i386/adx-check.h: Change bit check to
> > >         __builtin_cpu_supports.
> > >         * gcc.target/i386/aes-avx-check.h: Ditto.
> > >         * gcc.target/i386/aes-check.h: Ditto.
> > >         * gcc.target/i386/avx-check.h: Ditto.
> > >         * gcc.target/i386/avx2-check.h: Ditto.
> > >         * gcc.target/i386/avx512-check.h: Ditto.
> > >         * gcc.target/i386/bmi-check.h: Ditto.
> > >         * gcc.target/i386/bmi2-check.h: Ditto.
> > >         * gcc.target/i386/f16c-check.h: Ditto.
> > >         * gcc.target/i386/fma-check.h: Ditto.
> > >         * gcc.target/i386/fma4-check.h: Ditto.
> > >         * gcc.target/i386/lzcnt-check.h: Ditto.
> > >         * gcc.target/i386/mmx-3dnow-check.h: Ditto.
> > >         * gcc.target/i386/mmx-check.h: Ditto.
> > >         * gcc.target/i386/pclmul-avx-check.h: Ditto.
> > >         * gcc.target/i386/pclmul-check.h: Ditto.
> > >         * gcc.target/i386/rtm-check.h: Ditto.
> > >         * gcc.target/i386/sha-check.h: Ditto.
> > >         * gcc.target/i386/sse-check.h: Ditto.
> > >         * gcc.target/i386/sse2-check.h: Ditto.
> > >         * gcc.target/i386/sse3-check.h: Ditto.
> > >         * gcc.target/i386/sse4_1-check.h: Ditto.
> > >         * gcc.target/i386/sse4_2-check.h: Ditto.
> > >         * gcc.target/i386/sse4a-check.h: Ditto.
> > >         * gcc.target/i386/ssse3-check.h: Ditto.
> > >         * gcc.target/i386/xop-check.h: Ditto.
> > > ---
> > >  gcc/testsuite/gcc.target/i386/adx-check.h     | 10 +---
> > >  gcc/testsuite/gcc.target/i386/aes-avx-check.h | 14 +----
> > >  gcc/testsuite/gcc.target/i386/aes-check.h     | 11 +---
> > >  gcc/testsuite/gcc.target/i386/avx-check.h     | 12 +---
> > >  gcc/testsuite/gcc.target/i386/avx2-check.h    | 20 +------
> > >  gcc/testsuite/gcc.target/i386/avx512-check.h  | 59 +++++++------------
> > >  gcc/testsuite/gcc.target/i386/bmi-check.h     | 11 +---
> > >  gcc/testsuite/gcc.target/i386/bmi2-check.h    | 10 +---
> > >  gcc/testsuite/gcc.target/i386/f16c-check.h    | 10 +---
> > >  gcc/testsuite/gcc.target/i386/fma-check.h     | 11 +---
> > >  gcc/testsuite/gcc.target/i386/fma4-check.h    | 11 +---
> > >  gcc/testsuite/gcc.target/i386/lzcnt-check.h   | 11 +---
> > >  .../gcc.target/i386/mmx-3dnow-check.h         | 11 +---
> > >  gcc/testsuite/gcc.target/i386/mmx-check.h     | 11 +---
> > >  .../gcc.target/i386/pclmul-avx-check.h        | 14 +----
> > >  gcc/testsuite/gcc.target/i386/pclmul-check.h  | 11 +---
> > >  gcc/testsuite/gcc.target/i386/rtm-check.h     | 10 +---
> > >  gcc/testsuite/gcc.target/i386/sha-check.h     | 10 +---
> > >  gcc/testsuite/gcc.target/i386/sse-check.h     | 11 +---
> > >  gcc/testsuite/gcc.target/i386/sse2-check.h    | 11 +---
> > >  gcc/testsuite/gcc.target/i386/sse3-check.h    | 11 +---
> > >  gcc/testsuite/gcc.target/i386/sse4_1-check.h  | 11 +---
> > >  gcc/testsuite/gcc.target/i386/sse4_2-check.h  | 11 +---
> > >  gcc/testsuite/gcc.target/i386/sse4a-check.h   | 11 +---
> > >  gcc/testsuite/gcc.target/i386/ssse3-check.h   | 11 +---
> > >  gcc/testsuite/gcc.target/i386/xop-check.h     | 11 +---
> > >  26 files changed, 73 insertions(+), 272 deletions(-)
> > >
> > > diff --git a/gcc/testsuite/gcc.target/i386/adx-check.h b/gcc/testsuite/gcc.target/i386/adx-check.h
> > > index cfed1a38483..bed5dcca385 100644
> > > --- a/gcc/testsuite/gcc.target/i386/adx-check.h
> > > +++ b/gcc/testsuite/gcc.target/i386/adx-check.h
> > > @@ -1,5 +1,4 @@
> > >  #include <stdlib.h>
> > > -#include "cpuid.h"
> > >
> > >  static void adx_test (void);
> > >
> > > @@ -11,13 +10,8 @@ static void __attribute__ ((noinline)) do_test (void)
> > >  int
> > >  main ()
> > >  {
> > > -  unsigned int eax, ebx, ecx, edx;
> > > -
> > > -  if (!__get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx))
> > > -    return 0;
> > > -
> > > -  /* Run ADX test only if host has ADX support.  */
> > > -  if (ebx & bit_ADX)
> > > +  /* Check cpu support for ADX.  */
> > > +  if (__builtin_cpu_supports ("adx"))
> > >      {
> > >        do_test ();
> > >  #ifdef DEBUG
> > > diff --git a/gcc/testsuite/gcc.target/i386/aes-avx-check.h b/gcc/testsuite/gcc.target/i386/aes-avx-check.h
> > > index f2a4ead4014..74bf597ead4 100644
> > > --- a/gcc/testsuite/gcc.target/i386/aes-avx-check.h
> > > +++ b/gcc/testsuite/gcc.target/i386/aes-avx-check.h
> > > @@ -2,8 +2,6 @@
> > >  #include <stdio.h>
> > >  #endif
> > >  #include <stdlib.h>
> > > -#include "cpuid.h"
> > > -#include "avx-os-support.h"
> > >
> > >  static void aes_avx_test (void);
> > >
> > > @@ -17,15 +15,9 @@ do_test (void)
> > >  int
> > >  main ()
> > >  {
> > > -  unsigned int eax, ebx, ecx, edx;
> > > -
> > > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > > -    return 0;
> > > -
> > > -  /* Run AES + AVX test only if host has AES + AVX support.  */
> > > -  if (((ecx & (bit_AVX | bit_OSXSAVE | bit_AES))
> > > -       == (bit_AVX | bit_OSXSAVE | bit_AES))
> > > -      && avx_os_support ())
> > > +  /* Check cpu support for AES and AVX.  */
> > > +  if (__builtin_cpu_supports ("avx")
> > > +      && __builtin_cpu_supports ("aes"))
> > >      {
> > >        do_test ();
> > >  #ifdef DEBUG
> > > diff --git a/gcc/testsuite/gcc.target/i386/aes-check.h b/gcc/testsuite/gcc.target/i386/aes-check.h
> > > index 7e794423e47..7c3a3b324a7 100644
> > > --- a/gcc/testsuite/gcc.target/i386/aes-check.h
> > > +++ b/gcc/testsuite/gcc.target/i386/aes-check.h
> > > @@ -1,8 +1,6 @@
> > >  #include <stdio.h>
> > >  #include <stdlib.h>
> > >
> > > -#include "cpuid.h"
> > > -
> > >  static void aes_test (void);
> > >
> > >  static void
> > > @@ -15,13 +13,8 @@ do_test (void)
> > >  int
> > >  main ()
> > >  {
> > > -  unsigned int eax, ebx, ecx, edx;
> > > -
> > > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > > -    return 0;
> > > -
> > > -  /* Run AES test only if host has AES support.  */
> > > -  if (ecx & bit_AES)
> > > +  /* Check cpu support for AES.  */
> > > +  if (__builtin_cpu_supports ("aes"))
> > >      {
> > >        do_test ();
> > >  #ifdef DEBUG
> > > diff --git a/gcc/testsuite/gcc.target/i386/avx-check.h b/gcc/testsuite/gcc.target/i386/avx-check.h
> > > index 7ddca9d7b80..4a3dbc257bc 100644
> > > --- a/gcc/testsuite/gcc.target/i386/avx-check.h
> > > +++ b/gcc/testsuite/gcc.target/i386/avx-check.h
> > > @@ -1,7 +1,5 @@
> > >  #include <stdlib.h>
> > > -#include "cpuid.h"
> > >  #include "m256-check.h"
> > > -#include "avx-os-support.h"
> > >
> > >  static void avx_test (void);
> > >
> > > @@ -15,14 +13,8 @@ do_test (void)
> > >  int
> > >  main ()
> > >  {
> > > -  unsigned int eax, ebx, ecx, edx;
> > > -
> > > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > > -    return 0;
> > > -
> > > -  /* Run AVX test only if host has AVX support.  */
> > > -  if (((ecx & (bit_AVX | bit_OSXSAVE)) == (bit_AVX | bit_OSXSAVE))
> > > -      && avx_os_support ())
> > > +  /* Check cpu support for AVX.  */
> > > +  if (__builtin_cpu_supports ("avx"))
> > >      {
> > >        do_test ();
> > >  #ifdef DEBUG
> > > diff --git a/gcc/testsuite/gcc.target/i386/avx2-check.h b/gcc/testsuite/gcc.target/i386/avx2-check.h
> > > index 25bed5e0da6..2bc3c4425bb 100644
> > > --- a/gcc/testsuite/gcc.target/i386/avx2-check.h
> > > +++ b/gcc/testsuite/gcc.target/i386/avx2-check.h
> > > @@ -1,7 +1,5 @@
> > >  #include <stdlib.h>
> > > -#include "cpuid.h"
> > >  #include "m256-check.h"
> > > -#include "avx-os-support.h"
> > >
> > >  static void avx2_test (void);
> > >
> > > @@ -10,25 +8,11 @@ static void __attribute__ ((noinline)) do_test (void)
> > >    avx2_test ();
> > >  }
> > >
> > > -static int
> > > -check_osxsave (void)
> > > -{
> > > -  unsigned int eax, ebx, ecx, edx;
> > > -
> > > -  __cpuid (1, eax, ebx, ecx, edx);
> > > -  return (ecx & bit_OSXSAVE) != 0;
> > > -}
> > > -
> > >  int
> > >  main ()
> > >  {
> > > -  unsigned int eax, ebx, ecx, edx;
> > > -
> > > -  if (!__get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx))
> > > -    return 0;
> > > -
> > > -  /* Run AVX2 test only if host has AVX2 support.  */
> > > -  if (check_osxsave () && (ebx & bit_AVX2) && avx_os_support ())
> > > +  /* Check cpu support for AVX2.  */
> > > +  if (__builtin_cpu_supports ("avx2"))
> > >      {
> > >        do_test ();
> > >  #ifdef DEBUG
> > > diff --git a/gcc/testsuite/gcc.target/i386/avx512-check.h b/gcc/testsuite/gcc.target/i386/avx512-check.h
> > > index 0ad9064f637..339c79070c9 100644
> > > --- a/gcc/testsuite/gcc.target/i386/avx512-check.h
> > > +++ b/gcc/testsuite/gcc.target/i386/avx512-check.h
> > > @@ -1,7 +1,5 @@
> > >  #include <stdlib.h>
> > > -#include "cpuid.h"
> > >  #include "m512-check.h"
> > > -#include "avx512f-os-support.h"
> > >
> > >  #ifndef DO_TEST
> > >  #define DO_TEST do_test
> > > @@ -25,81 +23,66 @@ do_test (void)
> > >  }
> > >  #endif
> > >
> > > -static int
> > > -check_osxsave (void)
> > > -{
> > > -  unsigned int eax, ebx, ecx, edx;
> > > -
> > > -  __cpuid (1, eax, ebx, ecx, edx);
> > > -  return (ecx & bit_OSXSAVE) != 0;
> > > -}
> > > -
> > >  int
> > >  main ()
> > >  {
> > > -  unsigned int eax, ebx, ecx, edx;
> > > -
> > > -  if (!__get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx))
> > > -    return 0;
> > > -
> > > -  /* Run AVX512 test only if host has ISA support.  */
> > > -  if (check_osxsave ()
> > > -      && (ebx & bit_AVX512F)
> > > +  /* Check cpu support for AVX512.  */
> > > +  if (__builtin_cpu_supports ("avx512f")
> > >  #ifdef AVX512VL
> > > -      && (ebx & bit_AVX512VL)
> > > +      && __builtin_cpu_supports ("avx512vl")
> > >  #endif
> > >  #ifdef AVX512ER
> > > -      && (ebx & bit_AVX512ER)
> > > +      && __builtin_cpu_supports ("avx512er")
> > >  #endif
> > >  #ifdef AVX512CD
> > > -      && (ebx & bit_AVX512CD)
> > > +      && __builtin_cpu_supports ("avx512cd")
> > >  #endif
> > >  #ifdef AVX512DQ
> > > -      && (ebx & bit_AVX512DQ)
> > > +      && __builtin_cpu_supports ("avx512dq")
> > >  #endif
> > >  #ifdef AVX512BW
> > > -      && (ebx & bit_AVX512BW)
> > > +      && __builtin_cpu_supports ("avx512bw")
> > >  #endif
> > >  #ifdef AVX512IFMA
> > > -      && (ebx & bit_AVX512IFMA)
> > > +      && __builtin_cpu_supports ("avx512ifma")
> > >  #endif
> > >  #ifdef AVX512VBMI
> > > -      && (ecx & bit_AVX512VBMI)
> > > +      && __builtin_cpu_supports ("avx512vbmi")
> > >  #endif
> > >  #ifdef AVX5124FMAPS
> > > -      && (edx & bit_AVX5124FMAPS)
> > > +      && __builtin_cpu_supports ("avx5124fmaps")
> > >  #endif
> > >  #ifdef AVX5124VNNIW
> > > -      && (edx & bit_AVX5124VNNIW)
> > > +      && __builtin_cpu_supports ("avx5124vnniw")
> > >  #endif
> > >  #ifdef AVX512VPOPCNTDQ
> > > -      && (ecx & bit_AVX512VPOPCNTDQ)
> > > +      && __builtin_cpu_supports ("avx512vpopcntdq")
> > >  #endif
> > >  #ifdef AVX512BITALG
> > > -      && (ecx & bit_AVX512BITALG)
> > > +      && __builtin_cpu_supports ("avx512bitalg")
> > >  #endif
> > >  #ifdef GFNI
> > > -      && (ecx & bit_GFNI)
> > > +      && __builtin_cpu_supports ("gfni")
> > >  #endif
> > >  #ifdef AVX512VBMI2
> > > -      && (ecx & bit_AVX512VBMI2)
> > > +      && __builtin_cpu_supports ("avx512vbmi2")
> > >  #endif
> > >  #ifdef AVX512VNNI
> > > -      && (ecx & bit_AVX512VNNI)
> > > +      && __builtin_cpu_supports ("avx512vnni")
> > >  #endif
> > >  #ifdef AVX512FP16
> > > -      && (edx & bit_AVX512FP16)
> > > +      && __builtin_cpu_supports ("avx512fp16")
> > >  #endif
> > >  #ifdef VAES
> > > -      && (ecx & bit_VAES)
> > > +      && __builtin_cpu_supports ("vaes")
> > >  #endif
> > >  #ifdef VPCLMULQDQ
> > > -      && (ecx & bit_VPCLMULQDQ)
> > > +      && __builtin_cpu_supports ("vpclmulqdq")
> > >  #endif
> > >  #ifdef AVX512VP2INTERSECT
> > > -      && (edx & bit_AVX512VP2INTERSECT)
> > > +      && __builtin_cpu_supports ("avx512vp2intersect")
> > >  #endif
> > > -      && avx512f_os_support ())
> > > +      )
> > >      {
> > >        DO_TEST ();
> > >  #ifdef DEBUG
> > > diff --git a/gcc/testsuite/gcc.target/i386/bmi-check.h b/gcc/testsuite/gcc.target/i386/bmi-check.h
> > > index 1973f3b6468..6af0291a947 100644
> > > --- a/gcc/testsuite/gcc.target/i386/bmi-check.h
> > > +++ b/gcc/testsuite/gcc.target/i386/bmi-check.h
> > > @@ -1,8 +1,6 @@
> > >  #include <stdio.h>
> > >  #include <stdlib.h>
> > >
> > > -#include "cpuid.h"
> > > -
> > >  static void bmi_test (void);
> > >
> > >  static void
> > > @@ -15,13 +13,8 @@ do_test (void)
> > >  int
> > >  main ()
> > >  {
> > > -  unsigned int eax, ebx, ecx, edx;
> > > -
> > > -  if (!__get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx))
> > > -    return 0;
> > > -
> > > -  /* Run BMI test only if host has BMI support.  */
> > > -  if (ebx & bit_BMI)
> > > +  /* Check cpu support for BMI.  */
> > > +  if (__builtin_cpu_supports ("bmi"))
> > >      {
> > >        do_test ();
> > >  #ifdef DEBUG
> > > diff --git a/gcc/testsuite/gcc.target/i386/bmi2-check.h b/gcc/testsuite/gcc.target/i386/bmi2-check.h
> > > index ba91ef9b780..75c4d8d9616 100644
> > > --- a/gcc/testsuite/gcc.target/i386/bmi2-check.h
> > > +++ b/gcc/testsuite/gcc.target/i386/bmi2-check.h
> > > @@ -1,6 +1,5 @@
> > >  #include <stdio.h>
> > >  #include <stdlib.h>
> > > -#include "cpuid.h"
> > >
> > >  static void bmi2_test (void);
> > >
> > > @@ -14,13 +13,8 @@ do_test (void)
> > >  int
> > >  main ()
> > >  {
> > > -  unsigned int eax, ebx, ecx, edx;
> > > -
> > > -  if (!__get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx))
> > > -    return 0;
> > > -
> > > -  /* Run BMI2 test only if host has BMI2 support.  */
> > > -  if (ebx & bit_BMI2)
> > > +  /* Check cpu support for BMI2.  */
> > > +  if (__builtin_cpu_supports ("bmi2"))
> > >      {
> > >        do_test ();
> > >  #ifdef DEBUG
> > > diff --git a/gcc/testsuite/gcc.target/i386/f16c-check.h b/gcc/testsuite/gcc.target/i386/f16c-check.h
> > > index af7f32c5f4f..2cbf34ab516 100644
> > > --- a/gcc/testsuite/gcc.target/i386/f16c-check.h
> > > +++ b/gcc/testsuite/gcc.target/i386/f16c-check.h
> > > @@ -1,6 +1,5 @@
> > >  #include <stdlib.h>
> > >  #include <stdio.h>
> > > -#include "cpuid.h"
> > >  #include "m256-check.h"
> > >
> > >  static void f16c_test (void);
> > > @@ -8,13 +7,8 @@ static void f16c_test (void);
> > >  int
> > >  main ()
> > >  {
> > > -  unsigned int eax, ebx, ecx, edx;
> > > -
> > > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > > -    return 0;
> > > -
> > > -  /* Run F16C test only if host has F16C support.  */
> > > -  if (ecx & bit_F16C)
> > > +  /* Check cpu support for F16C.  */
> > > +  if (__builtin_cpu_supports ("f16c"))
> > >      {
> > >        f16c_test ();
> > >  #ifdef DEBUG
> > > diff --git a/gcc/testsuite/gcc.target/i386/fma-check.h b/gcc/testsuite/gcc.target/i386/fma-check.h
> > > index 8390f5088bd..6c1d3372218 100644
> > > --- a/gcc/testsuite/gcc.target/i386/fma-check.h
> > > +++ b/gcc/testsuite/gcc.target/i386/fma-check.h
> > > @@ -1,7 +1,5 @@
> > >  #include <stdlib.h>
> > >
> > > -#include "cpuid.h"
> > > -
> > >  static void fma_test (void);
> > >
> > >  static void __attribute__ ((noinline)) do_test (void)
> > > @@ -12,13 +10,8 @@ static void __attribute__ ((noinline)) do_test (void)
> > >  int
> > >  main ()
> > >  {
> > > -  unsigned int eax, ebx, ecx, edx;
> > > -
> > > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > > -    return 0;
> > > -
> > > -  /* Run FMA test only if host has FMA support.  */
> > > -  if (ecx & bit_FMA)
> > > +  /* Check cpu support for FMA.  */
> > > +  if (__builtin_cpu_supports ("fma"))
> > >      do_test ();
> > >
> > >    return 0;
> > > diff --git a/gcc/testsuite/gcc.target/i386/fma4-check.h b/gcc/testsuite/gcc.target/i386/fma4-check.h
> > > index 33cd9628c04..2d2c2718029 100644
> > > --- a/gcc/testsuite/gcc.target/i386/fma4-check.h
> > > +++ b/gcc/testsuite/gcc.target/i386/fma4-check.h
> > > @@ -1,7 +1,5 @@
> > >  #include <stdlib.h>
> > >
> > > -#include "cpuid.h"
> > > -
> > >  static void fma4_test (void);
> > >
> > >  static void
> > > @@ -14,13 +12,8 @@ do_test (void)
> > >  int
> > >  main ()
> > >  {
> > > -  unsigned int eax, ebx, ecx, edx;
> > > -
> > > -  if (!__get_cpuid (0x80000001, &eax, &ebx, &ecx, &edx))
> > > -    return 0;
> > > -
> > > -  /* Run FMA4 test only if host has FMA4 support.  */
> > > -  if (ecx & bit_FMA4)
> > > +  /* Check cpu support foe FMA4.  */
> > > +  if (__builtin_cpu_supports ("fma4"))
> > >      do_test ();
> > >
> > >    return 0;
> > > diff --git a/gcc/testsuite/gcc.target/i386/lzcnt-check.h b/gcc/testsuite/gcc.target/i386/lzcnt-check.h
> > > index 8aad834d6af..824f1a3b513 100644
> > > --- a/gcc/testsuite/gcc.target/i386/lzcnt-check.h
> > > +++ b/gcc/testsuite/gcc.target/i386/lzcnt-check.h
> > > @@ -1,8 +1,6 @@
> > >  #include <stdio.h>
> > >  #include <stdlib.h>
> > >
> > > -#include "cpuid.h"
> > > -
> > >  static void lzcnt_test (void);
> > >
> > >  static void
> > > @@ -15,13 +13,8 @@ do_test (void)
> > >  int
> > >  main ()
> > >  {
> > > -  unsigned int eax, ebx, ecx, edx;
> > > -
> > > -  if (!__get_cpuid (0x80000001, &eax, &ebx, &ecx, &edx))
> > > -    return 0;
> > > -
> > > -  /* Run LZCNT test only if host has LZCNT support.  */
> > > -  if (ecx & bit_LZCNT)
> > > +  /* Check cpu support for LZCNT.  */
> > > +  if (__builtin_cpu_supports ("lzcnt"))
> > >      {
> > >        do_test ();
> > >  #ifdef DEBUG
> > > diff --git a/gcc/testsuite/gcc.target/i386/mmx-3dnow-check.h b/gcc/testsuite/gcc.target/i386/mmx-3dnow-check.h
> > > index 4f2f7f3ac40..0ec2dca2e19 100644
> > > --- a/gcc/testsuite/gcc.target/i386/mmx-3dnow-check.h
> > > +++ b/gcc/testsuite/gcc.target/i386/mmx-3dnow-check.h
> > > @@ -1,8 +1,6 @@
> > >  #include <stdio.h>
> > >  #include <stdlib.h>
> > >
> > > -#include "cpuid.h"
> > > -
> > >  static void mmx_3dnow_test (void);
> > >
> > >  static void
> > > @@ -15,13 +13,8 @@ do_test (void)
> > >  int
> > >  main ()
> > >  {
> > > -  unsigned int eax, ebx, ecx, edx;
> > > -
> > > -  if (!__get_cpuid (0x80000001, &eax, &ebx, &ecx, &edx))
> > > -    return 0;
> > > -
> > > -  /* Run 3DNow! test only if host has 3DNow! support.  */
> > > -  if (edx & bit_3DNOW)
> > > +  /* Check cpu support for 3DNow!.  */
> > > +  if (__builtin_cpu_supports ("3dnow"))
> > >      do_test ();
> > >
> > >    return 0;
> > > diff --git a/gcc/testsuite/gcc.target/i386/mmx-check.h b/gcc/testsuite/gcc.target/i386/mmx-check.h
> > > index faf9b876f38..2afe5183ba2 100644
> > > --- a/gcc/testsuite/gcc.target/i386/mmx-check.h
> > > +++ b/gcc/testsuite/gcc.target/i386/mmx-check.h
> > > @@ -1,8 +1,6 @@
> > >  #include <stdio.h>
> > >  #include <stdlib.h>
> > >
> > > -#include "cpuid.h"
> > > -
> > >  static void mmx_test (void);
> > >
> > >  static void
> > > @@ -15,13 +13,8 @@ do_test (void)
> > >  int
> > >  main ()
> > >  {
> > > -  unsigned int eax, ebx, ecx, edx;
> > > -
> > > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > > -    return 0;
> > > -
> > > -  /* Run MMX test only if host has MMX support.  */
> > > -  if (edx & bit_MMX)
> > > +  /* Check cpu support for MMX.  */
> > > +  if (__builtin_cpu_supports ("mmx"))
> > >      do_test ();
> > >
> > >    return 0;
> > > diff --git a/gcc/testsuite/gcc.target/i386/pclmul-avx-check.h b/gcc/testsuite/gcc.target/i386/pclmul-avx-check.h
> > > index 5eed2e2203c..b506b3306e6 100644
> > > --- a/gcc/testsuite/gcc.target/i386/pclmul-avx-check.h
> > > +++ b/gcc/testsuite/gcc.target/i386/pclmul-avx-check.h
> > > @@ -2,8 +2,6 @@
> > >  #include <stdio.h>
> > >  #endif
> > >  #include <stdlib.h>
> > > -#include "cpuid.h"
> > > -#include "avx-os-support.h"
> > >
> > >  static void pclmul_avx_test (void);
> > >
> > > @@ -17,15 +15,9 @@ do_test (void)
> > >  int
> > >  main ()
> > >  {
> > > -  unsigned int eax, ebx, ecx, edx;
> > > -
> > > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > > -    return 0;
> > > -
> > > -  /* Run PCLMUL + AVX test only if host has PCLMUL + AVX support.  */
> > > -  if (((ecx & (bit_AVX | bit_OSXSAVE | bit_PCLMUL))
> > > -       == (bit_AVX | bit_OSXSAVE | bit_PCLMUL))
> > > -      && avx_os_support ())
> > > +  /* Check cpu support for PCLMUL and AVX.  */
> > > +  if (__builtin_cpu_supports ("pclmul")
> > > +      && __builtin_cpu_supports ("avx"))
> > >      {
> > >        do_test ();
> > >  #ifdef DEBUG
> > > diff --git a/gcc/testsuite/gcc.target/i386/pclmul-check.h b/gcc/testsuite/gcc.target/i386/pclmul-check.h
> > > index 7526cbe2ddf..3ed1a044627 100644
> > > --- a/gcc/testsuite/gcc.target/i386/pclmul-check.h
> > > +++ b/gcc/testsuite/gcc.target/i386/pclmul-check.h
> > > @@ -1,8 +1,6 @@
> > >  #include <stdio.h>
> > >  #include <stdlib.h>
> > >
> > > -#include "cpuid.h"
> > > -
> > >  static void pclmul_test (void);
> > >
> > >  static void
> > > @@ -15,13 +13,8 @@ do_test (void)
> > >  int
> > >  main ()
> > >  {
> > > -  unsigned int eax, ebx, ecx, edx;
> > > -
> > > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > > -    return 0;
> > > -
> > > -  /* Run PCLMULQDQ test only if host has PCLMULQDQ support.  */
> > > -  if (ecx & bit_PCLMUL)
> > > +  /* Check cpu support for PCLMUL.  */
> > > +  if (__builtin_cpu_supports ("pclmul"))
> > >      {
> > >        do_test ();
> > >  #ifdef DEBUG
> > > diff --git a/gcc/testsuite/gcc.target/i386/rtm-check.h b/gcc/testsuite/gcc.target/i386/rtm-check.h
> > > index bdb5a6dc0bf..4121e602a7f 100644
> > > --- a/gcc/testsuite/gcc.target/i386/rtm-check.h
> > > +++ b/gcc/testsuite/gcc.target/i386/rtm-check.h
> > > @@ -1,5 +1,4 @@
> > >  #include <stdlib.h>
> > > -#include "cpuid.h"
> > >
> > >  static void rtm_test (void);
> > >
> > > @@ -11,13 +10,8 @@ static void __attribute__ ((noinline)) do_test (void)
> > >  int
> > >  main ()
> > >  {
> > > -  unsigned int eax, ebx, ecx, edx;
> > > -
> > > -  if (!__get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx))
> > > -    return 0;
> > > -
> > > -  /* Run RTM test only if host has RTM support.  */
> > > -  if (ebx & bit_RTM)
> > > +  /* Check cpu support for RTM.  */
> > > +  if (__builtin_cpu_supports ("rtm"))
> > >      {
> > >        do_test ();
> > >  #ifdef DEBUG
> > > diff --git a/gcc/testsuite/gcc.target/i386/sha-check.h b/gcc/testsuite/gcc.target/i386/sha-check.h
> > > index 5bc5a59ab80..61ce43053f9 100644
> > > --- a/gcc/testsuite/gcc.target/i386/sha-check.h
> > > +++ b/gcc/testsuite/gcc.target/i386/sha-check.h
> > > @@ -1,5 +1,4 @@
> > >  #include <stdlib.h>
> > > -#include "cpuid.h"
> > >
> > >  static void sha_test (void);
> > >
> > > @@ -13,13 +12,8 @@ do_test (void)
> > >  int
> > >  main ()
> > >  {
> > > -  unsigned int eax, ebx, ecx, edx;
> > > -
> > > -  if (!__get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx))
> > > -    return 0;
> > > -
> > > -  /* Run SHA test only if host has SHA support.  */
> > > -  if (ebx & bit_SHA)
> > > +  /* Check cpu support for SHA.  */
> > > +  if (__builtin_cpu_supports ("sha"))
> > >      {
> > >        do_test ();
> > >  #ifdef DEBUG
> > > diff --git a/gcc/testsuite/gcc.target/i386/sse-check.h b/gcc/testsuite/gcc.target/i386/sse-check.h
> > > index 11b71bc3e97..58bc88c5598 100644
> > > --- a/gcc/testsuite/gcc.target/i386/sse-check.h
> > > +++ b/gcc/testsuite/gcc.target/i386/sse-check.h
> > > @@ -1,7 +1,5 @@
> > >  #include <stdlib.h>
> > >  #include "m128-check.h"
> > > -#include "cpuid.h"
> > > -#include "sse-os-support.h"
> > >
> > >  static void sse_test (void);
> > >
> > > @@ -15,13 +13,8 @@ do_test (void)
> > >  int
> > >  main ()
> > >  {
> > > -  unsigned int eax, ebx, ecx, edx;
> > > -
> > > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > > -    return 0;
> > > -
> > > -  /* Run SSE test only if host has SSE support.  */
> > > -  if ((edx & bit_SSE) && sse_os_support ())
> > > +  /* Check cpu support for SSE.  */
> > > +  if (__builtin_cpu_supports ("sse"))
> > >      do_test ();
> > >
> > >    return 0;
> > > diff --git a/gcc/testsuite/gcc.target/i386/sse2-check.h b/gcc/testsuite/gcc.target/i386/sse2-check.h
> > > index fd4a6ce1dbf..4976a27022d 100644
> > > --- a/gcc/testsuite/gcc.target/i386/sse2-check.h
> > > +++ b/gcc/testsuite/gcc.target/i386/sse2-check.h
> > > @@ -1,7 +1,5 @@
> > >  #include <stdlib.h>
> > > -#include "cpuid.h"
> > >  #include "m128-check.h"
> > > -#include "sse-os-support.h"
> > >
> > >  static void sse2_test (void);
> > >
> > > @@ -15,13 +13,8 @@ do_test (void)
> > >  int
> > >  main ()
> > >  {
> > > -  unsigned int eax, ebx, ecx, edx;
> > > -
> > > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > > -    return 0;
> > > -
> > > -  /* Run SSE2 test only if host has SSE2 support.  */
> > > -  if ((edx & bit_SSE2) && sse_os_support ())
> > > +  /* Check cpu support for SSE2.  */
> > > +  if (__builtin_cpu_supports ("sse2"))
> > >      do_test ();
> > >
> > >    return 0;
> > > diff --git a/gcc/testsuite/gcc.target/i386/sse3-check.h b/gcc/testsuite/gcc.target/i386/sse3-check.h
> > > index 5a0a0b1a02e..3c58361e925 100644
> > > --- a/gcc/testsuite/gcc.target/i386/sse3-check.h
> > > +++ b/gcc/testsuite/gcc.target/i386/sse3-check.h
> > > @@ -1,7 +1,5 @@
> > >  #include <stdio.h>
> > >  #include <stdlib.h>
> > > -#include "cpuid.h"
> > > -#include "sse-os-support.h"
> > >
> > >  static void sse3_test (void);
> > >
> > > @@ -15,13 +13,8 @@ do_test (void)
> > >  int
> > >  main ()
> > >  {
> > > -  unsigned int eax, ebx, ecx, edx;
> > > -
> > > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > > -    return 0;
> > > -
> > > -  /* Run SSE3 test only if host has SSE3 support.  */
> > > -  if ((ecx & bit_SSE3) && sse_os_support ())
> > > +  /* Check cpu support for SSE3.  */
> > > +  if (__builtin_cpu_supports ("sse3"))
> > >      do_test ();
> > >
> > >    return 0;
> > > diff --git a/gcc/testsuite/gcc.target/i386/sse4_1-check.h b/gcc/testsuite/gcc.target/i386/sse4_1-check.h
> > > index 788f65d61cb..61d0d0284a8 100644
> > > --- a/gcc/testsuite/gcc.target/i386/sse4_1-check.h
> > > +++ b/gcc/testsuite/gcc.target/i386/sse4_1-check.h
> > > @@ -1,6 +1,4 @@
> > >  #include <stdlib.h>
> > > -
> > > -#include "cpuid.h"
> > >  #include "m128-check.h"
> > >
> > >  static void sse4_1_test (void);
> > > @@ -17,13 +15,8 @@ do_test (void)
> > >  int
> > >  main ()
> > >  {
> > > -  unsigned int eax, ebx, ecx, edx;
> > > -
> > > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > > -    return 0;
> > > -
> > > -  /* Run SSE4.1 test only if host has SSE4.1 support.  */
> > > -  if (ecx & bit_SSE4_1)
> > > +  /* Check cpu support for SSE4.1.  */
> > > +  if (__builtin_cpu_supports ("sse4.1"))
> > >      do_test ();
> > >
> > >    return 0;
> > > diff --git a/gcc/testsuite/gcc.target/i386/sse4_2-check.h b/gcc/testsuite/gcc.target/i386/sse4_2-check.h
> > > index c33cd1b4986..6c921ac52c7 100644
> > > --- a/gcc/testsuite/gcc.target/i386/sse4_2-check.h
> > > +++ b/gcc/testsuite/gcc.target/i386/sse4_2-check.h
> > > @@ -1,8 +1,6 @@
> > >  #include <stdio.h>
> > >  #include <stdlib.h>
> > > -
> > >  #include "m128-check.h"
> > > -#include "cpuid.h"
> > >
> > >  static void sse4_2_test (void);
> > >
> > > @@ -16,13 +14,8 @@ do_test (void)
> > >  int
> > >  main ()
> > >  {
> > > -  unsigned int eax, ebx, ecx, edx;
> > > -
> > > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > > -    return 0;
> > > -
> > > -  /* Run SSE4.2 test only if host has SSE4.2 support.  */
> > > -  if (ecx & bit_SSE4_2)
> > > +  /* Check cpu support for SSE4.2.  */
> > > +  if (__builtin_cpu_supports ("sse4.2"))
> > >      do_test ();
> > >
> > >    return 0;
> > > diff --git a/gcc/testsuite/gcc.target/i386/sse4a-check.h b/gcc/testsuite/gcc.target/i386/sse4a-check.h
> > > index d43b4b222b1..ae70ff0a268 100644
> > > --- a/gcc/testsuite/gcc.target/i386/sse4a-check.h
> > > +++ b/gcc/testsuite/gcc.target/i386/sse4a-check.h
> > > @@ -1,8 +1,6 @@
> > >  #include <stdio.h>
> > >  #include <stdlib.h>
> > >
> > > -#include "cpuid.h"
> > > -
> > >  static void sse4a_test (void);
> > >
> > >  static void
> > > @@ -15,13 +13,8 @@ do_test (void)
> > >  int
> > >  main ()
> > >  {
> > > -  unsigned int eax, ebx, ecx, edx;
> > > -
> > > -  if (!__get_cpuid (0x80000001, &eax, &ebx, &ecx, &edx))
> > > -    return 0;
> > > -
> > > -  /* Run SSE4a test only if host has SSE4a support.  */
> > > -  if (ecx & bit_SSE4a)
> > > +  /* Check cpu support for SSE4a.  */
> > > +  if (__builtin_cpu_supports ("sse4a"))
> > >      do_test ();
> > >
> > >    return 0;
> > > diff --git a/gcc/testsuite/gcc.target/i386/ssse3-check.h b/gcc/testsuite/gcc.target/i386/ssse3-check.h
> > > index 3ca79333c7f..3e834811f2d 100644
> > > --- a/gcc/testsuite/gcc.target/i386/ssse3-check.h
> > > +++ b/gcc/testsuite/gcc.target/i386/ssse3-check.h
> > > @@ -1,8 +1,6 @@
> > >  #include <stdio.h>
> > >  #include <stdlib.h>
> > >
> > > -#include "cpuid.h"
> > > -
> > >  static void ssse3_test (void);
> > >
> > >  static void
> > > @@ -15,13 +13,8 @@ do_test (void)
> > >  int
> > >  main ()
> > >  {
> > > -  unsigned int eax, ebx, ecx, edx;
> > > -
> > > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > > -    return 0;
> > > -
> > > -  /* Run SSSE3 test only if host has SSSE3 support.  */
> > > -  if (ecx & bit_SSSE3)
> > > +  /* Check cpu support for SSSE3.  */
> > > +  if (__builtin_cpu_supports ("ssse3"))
> > >      do_test ();
> > >
> > >    return 0;
> > > diff --git a/gcc/testsuite/gcc.target/i386/xop-check.h b/gcc/testsuite/gcc.target/i386/xop-check.h
> > > index 395abe8766d..e1ef1273111 100644
> > > --- a/gcc/testsuite/gcc.target/i386/xop-check.h
> > > +++ b/gcc/testsuite/gcc.target/i386/xop-check.h
> > > @@ -1,6 +1,4 @@
> > >  #include <stdlib.h>
> > > -
> > > -#include "cpuid.h"
> > >  #include "m256-check.h"
> > >
> > >  static void xop_test (void);
> > > @@ -15,13 +13,8 @@ do_test (void)
> > >  int
> > >  main ()
> > >  {
> > > -  unsigned int eax, ebx, ecx, edx;
> > > -
> > > -  if (!__get_cpuid (0x80000001, &eax, &ebx, &ecx, &edx))
> > > -    return 0;
> > > -
> > > -  /* Run XOP test only if host has XOP support.  */
> > > -  if (ecx & bit_XOP)
> > > +  /* Check cpu support for XOP.  */
> > > +  if (__builtin_cpu_supports ("xop"))
> > >      do_test ();
> > >
> > >    return 0;
> > > --
> > > 2.18.1
> > >
Uros Bizjak May 7, 2022, 9:04 a.m. UTC | #5
On Sat, May 7, 2022 at 3:20 AM Jiang, Haochen <haochen.jiang@intel.com> wrote:
>
> Hi Uros,
>
> I understand that we always keep the old testcases there. It is always safe to do that.
>
> But I have another question, if we add something new in one of the existing files in the future,
> should we use __builtin_cpu_supports to keep the code clearer or stick to cpuids?

We should use __builtin_cpu_supports.

> I believe __builtin_cpu_supports will be a clearer way for a coder to understand under current circumstance.
> So if we use that in future use, why don't we change everything to the same way?

Because we test the old and the new approach this way.

Uros.

> BRs,
> Haochen
>
> -----Original Message-----
> From: Uros Bizjak <ubizjak@gmail.com>
> Sent: Friday, May 6, 2022 5:17 PM
> To: Hongyu Wang <wwwhhhyyy333@gmail.com>
> Cc: Jiang, Haochen <haochen.jiang@intel.com>; Liu, Hongtao <hongtao.liu@intel.com>; gcc-patches@gcc.gnu.org
> Subject: Re: [PATCH] Reconstruct i386 testsuite with __builtin_cpu_supports
>
> On Fri, May 6, 2022 at 11:00 AM Hongyu Wang <wwwhhhyyy333@gmail.com> wrote:
> >
> > > I don't think *_os_support calls should be removed. IIRC,
> > > __builtin_cpu_supports function checks if the feature is supported by
> > > CPU, whereas *_os_supports calls check via xgetbv if OS supports
> > > handling of new registers.
> >
> > avx_os_support is like
> >
> > avx_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_SSE | XSTATE_YMM)) == (XSTATE_SSE | XSTATE_YMM);
> > }
> >
> > While in get_avaliable_features we have
> >
> > #define XCR_AVX_ENABLED_MASK \
> >   (XSTATE_SSE | XSTATE_YMM)
> >   if ((ecx & bit_OSXSAVE))
> >     {
> >       /* Check if XMM, YMM, OPMASK, upper 256 bits of ZMM0-ZMM15 and
> > ZMM16-ZMM31 states are supported by OSXSAVE.  */
> >       unsigned int xcrlow;
> >       unsigned int xcrhigh;
> >       __asm__ (".byte 0x0f, 0x01, 0xd0" /* xgetbv  */
> >        : "=a" (xcrlow), "=d" (xcrhigh)
> >        : "c" (XCR_XFEATURE_ENABLED_MASK));
> >       if ((xcrlow & XCR_AVX_ENABLED_MASK) == XCR_AVX_ENABLED_MASK)
> > {
> >   avx_usable = 1;
> >
> > So __builtin_cpu_supports already inherits same check
>
> Indeed, thanks for the explanation.
>
> OTOH, we don't change the existing tests (perhaps only dg- directives
> when infrastructure improves), so I would leave the existing testcases
> as they are. In future, new helper functions should be implemented
> with __builtin_cpu_supports, but let's leave existing ones as they
> are.
>
> Uros.
>
> > Uros Bizjak via Gcc-patches <gcc-patches@gcc.gnu.org> 于2022年5月6日周五 16:27写道:
> > >
> > > On Fri, May 6, 2022 at 9:57 AM Haochen Jiang <haochen.jiang@intel.com> wrote:
> > > >
> > > > Hi all,
> > > >
> > > > There are some check files in i386 testsuite are written before the function __builtin_cpu_supports is introduced. All of them are using __get_cpuid_count. This patch aims to reconstruct the i386 testsuite with __builtin_cpu_supports so that we can have a much clearer code.
> > > >
> > > > Regtested on x86_64-pc-linux-gnu. Ok for trunk?
> > >
> > > I don't think *_os_support calls should be removed. IIRC,
> > > __builtin_cpu_supports function checks if the feature is supported by
> > > CPU, whereas *_os_supports calls check via xgetbv if OS supports
> > > handling of new registers.
> > >
> > > Uros.
> > >
> > > >
> > > > Also when writting this patch, I also find some files in testsuite that might be useless currently. For example, in the file gcc/testsuite/gcc.target/i386/sse-os-support.h, it always return 1. And there are also some files will no longer be included at all with this patch. Should we remove those files when we have time?
> > > >
> > > > BRs,
> > > > Haochen
> > > >
> > > > gcc/testsuite/ChangeLog:
> > > >
> > > >         * gcc.target/i386/adx-check.h: Change bit check to
> > > >         __builtin_cpu_supports.
> > > >         * gcc.target/i386/aes-avx-check.h: Ditto.
> > > >         * gcc.target/i386/aes-check.h: Ditto.
> > > >         * gcc.target/i386/avx-check.h: Ditto.
> > > >         * gcc.target/i386/avx2-check.h: Ditto.
> > > >         * gcc.target/i386/avx512-check.h: Ditto.
> > > >         * gcc.target/i386/bmi-check.h: Ditto.
> > > >         * gcc.target/i386/bmi2-check.h: Ditto.
> > > >         * gcc.target/i386/f16c-check.h: Ditto.
> > > >         * gcc.target/i386/fma-check.h: Ditto.
> > > >         * gcc.target/i386/fma4-check.h: Ditto.
> > > >         * gcc.target/i386/lzcnt-check.h: Ditto.
> > > >         * gcc.target/i386/mmx-3dnow-check.h: Ditto.
> > > >         * gcc.target/i386/mmx-check.h: Ditto.
> > > >         * gcc.target/i386/pclmul-avx-check.h: Ditto.
> > > >         * gcc.target/i386/pclmul-check.h: Ditto.
> > > >         * gcc.target/i386/rtm-check.h: Ditto.
> > > >         * gcc.target/i386/sha-check.h: Ditto.
> > > >         * gcc.target/i386/sse-check.h: Ditto.
> > > >         * gcc.target/i386/sse2-check.h: Ditto.
> > > >         * gcc.target/i386/sse3-check.h: Ditto.
> > > >         * gcc.target/i386/sse4_1-check.h: Ditto.
> > > >         * gcc.target/i386/sse4_2-check.h: Ditto.
> > > >         * gcc.target/i386/sse4a-check.h: Ditto.
> > > >         * gcc.target/i386/ssse3-check.h: Ditto.
> > > >         * gcc.target/i386/xop-check.h: Ditto.
> > > > ---
> > > >  gcc/testsuite/gcc.target/i386/adx-check.h     | 10 +---
> > > >  gcc/testsuite/gcc.target/i386/aes-avx-check.h | 14 +----
> > > >  gcc/testsuite/gcc.target/i386/aes-check.h     | 11 +---
> > > >  gcc/testsuite/gcc.target/i386/avx-check.h     | 12 +---
> > > >  gcc/testsuite/gcc.target/i386/avx2-check.h    | 20 +------
> > > >  gcc/testsuite/gcc.target/i386/avx512-check.h  | 59 +++++++------------
> > > >  gcc/testsuite/gcc.target/i386/bmi-check.h     | 11 +---
> > > >  gcc/testsuite/gcc.target/i386/bmi2-check.h    | 10 +---
> > > >  gcc/testsuite/gcc.target/i386/f16c-check.h    | 10 +---
> > > >  gcc/testsuite/gcc.target/i386/fma-check.h     | 11 +---
> > > >  gcc/testsuite/gcc.target/i386/fma4-check.h    | 11 +---
> > > >  gcc/testsuite/gcc.target/i386/lzcnt-check.h   | 11 +---
> > > >  .../gcc.target/i386/mmx-3dnow-check.h         | 11 +---
> > > >  gcc/testsuite/gcc.target/i386/mmx-check.h     | 11 +---
> > > >  .../gcc.target/i386/pclmul-avx-check.h        | 14 +----
> > > >  gcc/testsuite/gcc.target/i386/pclmul-check.h  | 11 +---
> > > >  gcc/testsuite/gcc.target/i386/rtm-check.h     | 10 +---
> > > >  gcc/testsuite/gcc.target/i386/sha-check.h     | 10 +---
> > > >  gcc/testsuite/gcc.target/i386/sse-check.h     | 11 +---
> > > >  gcc/testsuite/gcc.target/i386/sse2-check.h    | 11 +---
> > > >  gcc/testsuite/gcc.target/i386/sse3-check.h    | 11 +---
> > > >  gcc/testsuite/gcc.target/i386/sse4_1-check.h  | 11 +---
> > > >  gcc/testsuite/gcc.target/i386/sse4_2-check.h  | 11 +---
> > > >  gcc/testsuite/gcc.target/i386/sse4a-check.h   | 11 +---
> > > >  gcc/testsuite/gcc.target/i386/ssse3-check.h   | 11 +---
> > > >  gcc/testsuite/gcc.target/i386/xop-check.h     | 11 +---
> > > >  26 files changed, 73 insertions(+), 272 deletions(-)
> > > >
> > > > diff --git a/gcc/testsuite/gcc.target/i386/adx-check.h b/gcc/testsuite/gcc.target/i386/adx-check.h
> > > > index cfed1a38483..bed5dcca385 100644
> > > > --- a/gcc/testsuite/gcc.target/i386/adx-check.h
> > > > +++ b/gcc/testsuite/gcc.target/i386/adx-check.h
> > > > @@ -1,5 +1,4 @@
> > > >  #include <stdlib.h>
> > > > -#include "cpuid.h"
> > > >
> > > >  static void adx_test (void);
> > > >
> > > > @@ -11,13 +10,8 @@ static void __attribute__ ((noinline)) do_test (void)
> > > >  int
> > > >  main ()
> > > >  {
> > > > -  unsigned int eax, ebx, ecx, edx;
> > > > -
> > > > -  if (!__get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx))
> > > > -    return 0;
> > > > -
> > > > -  /* Run ADX test only if host has ADX support.  */
> > > > -  if (ebx & bit_ADX)
> > > > +  /* Check cpu support for ADX.  */
> > > > +  if (__builtin_cpu_supports ("adx"))
> > > >      {
> > > >        do_test ();
> > > >  #ifdef DEBUG
> > > > diff --git a/gcc/testsuite/gcc.target/i386/aes-avx-check.h b/gcc/testsuite/gcc.target/i386/aes-avx-check.h
> > > > index f2a4ead4014..74bf597ead4 100644
> > > > --- a/gcc/testsuite/gcc.target/i386/aes-avx-check.h
> > > > +++ b/gcc/testsuite/gcc.target/i386/aes-avx-check.h
> > > > @@ -2,8 +2,6 @@
> > > >  #include <stdio.h>
> > > >  #endif
> > > >  #include <stdlib.h>
> > > > -#include "cpuid.h"
> > > > -#include "avx-os-support.h"
> > > >
> > > >  static void aes_avx_test (void);
> > > >
> > > > @@ -17,15 +15,9 @@ do_test (void)
> > > >  int
> > > >  main ()
> > > >  {
> > > > -  unsigned int eax, ebx, ecx, edx;
> > > > -
> > > > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > > > -    return 0;
> > > > -
> > > > -  /* Run AES + AVX test only if host has AES + AVX support.  */
> > > > -  if (((ecx & (bit_AVX | bit_OSXSAVE | bit_AES))
> > > > -       == (bit_AVX | bit_OSXSAVE | bit_AES))
> > > > -      && avx_os_support ())
> > > > +  /* Check cpu support for AES and AVX.  */
> > > > +  if (__builtin_cpu_supports ("avx")
> > > > +      && __builtin_cpu_supports ("aes"))
> > > >      {
> > > >        do_test ();
> > > >  #ifdef DEBUG
> > > > diff --git a/gcc/testsuite/gcc.target/i386/aes-check.h b/gcc/testsuite/gcc.target/i386/aes-check.h
> > > > index 7e794423e47..7c3a3b324a7 100644
> > > > --- a/gcc/testsuite/gcc.target/i386/aes-check.h
> > > > +++ b/gcc/testsuite/gcc.target/i386/aes-check.h
> > > > @@ -1,8 +1,6 @@
> > > >  #include <stdio.h>
> > > >  #include <stdlib.h>
> > > >
> > > > -#include "cpuid.h"
> > > > -
> > > >  static void aes_test (void);
> > > >
> > > >  static void
> > > > @@ -15,13 +13,8 @@ do_test (void)
> > > >  int
> > > >  main ()
> > > >  {
> > > > -  unsigned int eax, ebx, ecx, edx;
> > > > -
> > > > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > > > -    return 0;
> > > > -
> > > > -  /* Run AES test only if host has AES support.  */
> > > > -  if (ecx & bit_AES)
> > > > +  /* Check cpu support for AES.  */
> > > > +  if (__builtin_cpu_supports ("aes"))
> > > >      {
> > > >        do_test ();
> > > >  #ifdef DEBUG
> > > > diff --git a/gcc/testsuite/gcc.target/i386/avx-check.h b/gcc/testsuite/gcc.target/i386/avx-check.h
> > > > index 7ddca9d7b80..4a3dbc257bc 100644
> > > > --- a/gcc/testsuite/gcc.target/i386/avx-check.h
> > > > +++ b/gcc/testsuite/gcc.target/i386/avx-check.h
> > > > @@ -1,7 +1,5 @@
> > > >  #include <stdlib.h>
> > > > -#include "cpuid.h"
> > > >  #include "m256-check.h"
> > > > -#include "avx-os-support.h"
> > > >
> > > >  static void avx_test (void);
> > > >
> > > > @@ -15,14 +13,8 @@ do_test (void)
> > > >  int
> > > >  main ()
> > > >  {
> > > > -  unsigned int eax, ebx, ecx, edx;
> > > > -
> > > > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > > > -    return 0;
> > > > -
> > > > -  /* Run AVX test only if host has AVX support.  */
> > > > -  if (((ecx & (bit_AVX | bit_OSXSAVE)) == (bit_AVX | bit_OSXSAVE))
> > > > -      && avx_os_support ())
> > > > +  /* Check cpu support for AVX.  */
> > > > +  if (__builtin_cpu_supports ("avx"))
> > > >      {
> > > >        do_test ();
> > > >  #ifdef DEBUG
> > > > diff --git a/gcc/testsuite/gcc.target/i386/avx2-check.h b/gcc/testsuite/gcc.target/i386/avx2-check.h
> > > > index 25bed5e0da6..2bc3c4425bb 100644
> > > > --- a/gcc/testsuite/gcc.target/i386/avx2-check.h
> > > > +++ b/gcc/testsuite/gcc.target/i386/avx2-check.h
> > > > @@ -1,7 +1,5 @@
> > > >  #include <stdlib.h>
> > > > -#include "cpuid.h"
> > > >  #include "m256-check.h"
> > > > -#include "avx-os-support.h"
> > > >
> > > >  static void avx2_test (void);
> > > >
> > > > @@ -10,25 +8,11 @@ static void __attribute__ ((noinline)) do_test (void)
> > > >    avx2_test ();
> > > >  }
> > > >
> > > > -static int
> > > > -check_osxsave (void)
> > > > -{
> > > > -  unsigned int eax, ebx, ecx, edx;
> > > > -
> > > > -  __cpuid (1, eax, ebx, ecx, edx);
> > > > -  return (ecx & bit_OSXSAVE) != 0;
> > > > -}
> > > > -
> > > >  int
> > > >  main ()
> > > >  {
> > > > -  unsigned int eax, ebx, ecx, edx;
> > > > -
> > > > -  if (!__get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx))
> > > > -    return 0;
> > > > -
> > > > -  /* Run AVX2 test only if host has AVX2 support.  */
> > > > -  if (check_osxsave () && (ebx & bit_AVX2) && avx_os_support ())
> > > > +  /* Check cpu support for AVX2.  */
> > > > +  if (__builtin_cpu_supports ("avx2"))
> > > >      {
> > > >        do_test ();
> > > >  #ifdef DEBUG
> > > > diff --git a/gcc/testsuite/gcc.target/i386/avx512-check.h b/gcc/testsuite/gcc.target/i386/avx512-check.h
> > > > index 0ad9064f637..339c79070c9 100644
> > > > --- a/gcc/testsuite/gcc.target/i386/avx512-check.h
> > > > +++ b/gcc/testsuite/gcc.target/i386/avx512-check.h
> > > > @@ -1,7 +1,5 @@
> > > >  #include <stdlib.h>
> > > > -#include "cpuid.h"
> > > >  #include "m512-check.h"
> > > > -#include "avx512f-os-support.h"
> > > >
> > > >  #ifndef DO_TEST
> > > >  #define DO_TEST do_test
> > > > @@ -25,81 +23,66 @@ do_test (void)
> > > >  }
> > > >  #endif
> > > >
> > > > -static int
> > > > -check_osxsave (void)
> > > > -{
> > > > -  unsigned int eax, ebx, ecx, edx;
> > > > -
> > > > -  __cpuid (1, eax, ebx, ecx, edx);
> > > > -  return (ecx & bit_OSXSAVE) != 0;
> > > > -}
> > > > -
> > > >  int
> > > >  main ()
> > > >  {
> > > > -  unsigned int eax, ebx, ecx, edx;
> > > > -
> > > > -  if (!__get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx))
> > > > -    return 0;
> > > > -
> > > > -  /* Run AVX512 test only if host has ISA support.  */
> > > > -  if (check_osxsave ()
> > > > -      && (ebx & bit_AVX512F)
> > > > +  /* Check cpu support for AVX512.  */
> > > > +  if (__builtin_cpu_supports ("avx512f")
> > > >  #ifdef AVX512VL
> > > > -      && (ebx & bit_AVX512VL)
> > > > +      && __builtin_cpu_supports ("avx512vl")
> > > >  #endif
> > > >  #ifdef AVX512ER
> > > > -      && (ebx & bit_AVX512ER)
> > > > +      && __builtin_cpu_supports ("avx512er")
> > > >  #endif
> > > >  #ifdef AVX512CD
> > > > -      && (ebx & bit_AVX512CD)
> > > > +      && __builtin_cpu_supports ("avx512cd")
> > > >  #endif
> > > >  #ifdef AVX512DQ
> > > > -      && (ebx & bit_AVX512DQ)
> > > > +      && __builtin_cpu_supports ("avx512dq")
> > > >  #endif
> > > >  #ifdef AVX512BW
> > > > -      && (ebx & bit_AVX512BW)
> > > > +      && __builtin_cpu_supports ("avx512bw")
> > > >  #endif
> > > >  #ifdef AVX512IFMA
> > > > -      && (ebx & bit_AVX512IFMA)
> > > > +      && __builtin_cpu_supports ("avx512ifma")
> > > >  #endif
> > > >  #ifdef AVX512VBMI
> > > > -      && (ecx & bit_AVX512VBMI)
> > > > +      && __builtin_cpu_supports ("avx512vbmi")
> > > >  #endif
> > > >  #ifdef AVX5124FMAPS
> > > > -      && (edx & bit_AVX5124FMAPS)
> > > > +      && __builtin_cpu_supports ("avx5124fmaps")
> > > >  #endif
> > > >  #ifdef AVX5124VNNIW
> > > > -      && (edx & bit_AVX5124VNNIW)
> > > > +      && __builtin_cpu_supports ("avx5124vnniw")
> > > >  #endif
> > > >  #ifdef AVX512VPOPCNTDQ
> > > > -      && (ecx & bit_AVX512VPOPCNTDQ)
> > > > +      && __builtin_cpu_supports ("avx512vpopcntdq")
> > > >  #endif
> > > >  #ifdef AVX512BITALG
> > > > -      && (ecx & bit_AVX512BITALG)
> > > > +      && __builtin_cpu_supports ("avx512bitalg")
> > > >  #endif
> > > >  #ifdef GFNI
> > > > -      && (ecx & bit_GFNI)
> > > > +      && __builtin_cpu_supports ("gfni")
> > > >  #endif
> > > >  #ifdef AVX512VBMI2
> > > > -      && (ecx & bit_AVX512VBMI2)
> > > > +      && __builtin_cpu_supports ("avx512vbmi2")
> > > >  #endif
> > > >  #ifdef AVX512VNNI
> > > > -      && (ecx & bit_AVX512VNNI)
> > > > +      && __builtin_cpu_supports ("avx512vnni")
> > > >  #endif
> > > >  #ifdef AVX512FP16
> > > > -      && (edx & bit_AVX512FP16)
> > > > +      && __builtin_cpu_supports ("avx512fp16")
> > > >  #endif
> > > >  #ifdef VAES
> > > > -      && (ecx & bit_VAES)
> > > > +      && __builtin_cpu_supports ("vaes")
> > > >  #endif
> > > >  #ifdef VPCLMULQDQ
> > > > -      && (ecx & bit_VPCLMULQDQ)
> > > > +      && __builtin_cpu_supports ("vpclmulqdq")
> > > >  #endif
> > > >  #ifdef AVX512VP2INTERSECT
> > > > -      && (edx & bit_AVX512VP2INTERSECT)
> > > > +      && __builtin_cpu_supports ("avx512vp2intersect")
> > > >  #endif
> > > > -      && avx512f_os_support ())
> > > > +      )
> > > >      {
> > > >        DO_TEST ();
> > > >  #ifdef DEBUG
> > > > diff --git a/gcc/testsuite/gcc.target/i386/bmi-check.h b/gcc/testsuite/gcc.target/i386/bmi-check.h
> > > > index 1973f3b6468..6af0291a947 100644
> > > > --- a/gcc/testsuite/gcc.target/i386/bmi-check.h
> > > > +++ b/gcc/testsuite/gcc.target/i386/bmi-check.h
> > > > @@ -1,8 +1,6 @@
> > > >  #include <stdio.h>
> > > >  #include <stdlib.h>
> > > >
> > > > -#include "cpuid.h"
> > > > -
> > > >  static void bmi_test (void);
> > > >
> > > >  static void
> > > > @@ -15,13 +13,8 @@ do_test (void)
> > > >  int
> > > >  main ()
> > > >  {
> > > > -  unsigned int eax, ebx, ecx, edx;
> > > > -
> > > > -  if (!__get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx))
> > > > -    return 0;
> > > > -
> > > > -  /* Run BMI test only if host has BMI support.  */
> > > > -  if (ebx & bit_BMI)
> > > > +  /* Check cpu support for BMI.  */
> > > > +  if (__builtin_cpu_supports ("bmi"))
> > > >      {
> > > >        do_test ();
> > > >  #ifdef DEBUG
> > > > diff --git a/gcc/testsuite/gcc.target/i386/bmi2-check.h b/gcc/testsuite/gcc.target/i386/bmi2-check.h
> > > > index ba91ef9b780..75c4d8d9616 100644
> > > > --- a/gcc/testsuite/gcc.target/i386/bmi2-check.h
> > > > +++ b/gcc/testsuite/gcc.target/i386/bmi2-check.h
> > > > @@ -1,6 +1,5 @@
> > > >  #include <stdio.h>
> > > >  #include <stdlib.h>
> > > > -#include "cpuid.h"
> > > >
> > > >  static void bmi2_test (void);
> > > >
> > > > @@ -14,13 +13,8 @@ do_test (void)
> > > >  int
> > > >  main ()
> > > >  {
> > > > -  unsigned int eax, ebx, ecx, edx;
> > > > -
> > > > -  if (!__get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx))
> > > > -    return 0;
> > > > -
> > > > -  /* Run BMI2 test only if host has BMI2 support.  */
> > > > -  if (ebx & bit_BMI2)
> > > > +  /* Check cpu support for BMI2.  */
> > > > +  if (__builtin_cpu_supports ("bmi2"))
> > > >      {
> > > >        do_test ();
> > > >  #ifdef DEBUG
> > > > diff --git a/gcc/testsuite/gcc.target/i386/f16c-check.h b/gcc/testsuite/gcc.target/i386/f16c-check.h
> > > > index af7f32c5f4f..2cbf34ab516 100644
> > > > --- a/gcc/testsuite/gcc.target/i386/f16c-check.h
> > > > +++ b/gcc/testsuite/gcc.target/i386/f16c-check.h
> > > > @@ -1,6 +1,5 @@
> > > >  #include <stdlib.h>
> > > >  #include <stdio.h>
> > > > -#include "cpuid.h"
> > > >  #include "m256-check.h"
> > > >
> > > >  static void f16c_test (void);
> > > > @@ -8,13 +7,8 @@ static void f16c_test (void);
> > > >  int
> > > >  main ()
> > > >  {
> > > > -  unsigned int eax, ebx, ecx, edx;
> > > > -
> > > > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > > > -    return 0;
> > > > -
> > > > -  /* Run F16C test only if host has F16C support.  */
> > > > -  if (ecx & bit_F16C)
> > > > +  /* Check cpu support for F16C.  */
> > > > +  if (__builtin_cpu_supports ("f16c"))
> > > >      {
> > > >        f16c_test ();
> > > >  #ifdef DEBUG
> > > > diff --git a/gcc/testsuite/gcc.target/i386/fma-check.h b/gcc/testsuite/gcc.target/i386/fma-check.h
> > > > index 8390f5088bd..6c1d3372218 100644
> > > > --- a/gcc/testsuite/gcc.target/i386/fma-check.h
> > > > +++ b/gcc/testsuite/gcc.target/i386/fma-check.h
> > > > @@ -1,7 +1,5 @@
> > > >  #include <stdlib.h>
> > > >
> > > > -#include "cpuid.h"
> > > > -
> > > >  static void fma_test (void);
> > > >
> > > >  static void __attribute__ ((noinline)) do_test (void)
> > > > @@ -12,13 +10,8 @@ static void __attribute__ ((noinline)) do_test (void)
> > > >  int
> > > >  main ()
> > > >  {
> > > > -  unsigned int eax, ebx, ecx, edx;
> > > > -
> > > > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > > > -    return 0;
> > > > -
> > > > -  /* Run FMA test only if host has FMA support.  */
> > > > -  if (ecx & bit_FMA)
> > > > +  /* Check cpu support for FMA.  */
> > > > +  if (__builtin_cpu_supports ("fma"))
> > > >      do_test ();
> > > >
> > > >    return 0;
> > > > diff --git a/gcc/testsuite/gcc.target/i386/fma4-check.h b/gcc/testsuite/gcc.target/i386/fma4-check.h
> > > > index 33cd9628c04..2d2c2718029 100644
> > > > --- a/gcc/testsuite/gcc.target/i386/fma4-check.h
> > > > +++ b/gcc/testsuite/gcc.target/i386/fma4-check.h
> > > > @@ -1,7 +1,5 @@
> > > >  #include <stdlib.h>
> > > >
> > > > -#include "cpuid.h"
> > > > -
> > > >  static void fma4_test (void);
> > > >
> > > >  static void
> > > > @@ -14,13 +12,8 @@ do_test (void)
> > > >  int
> > > >  main ()
> > > >  {
> > > > -  unsigned int eax, ebx, ecx, edx;
> > > > -
> > > > -  if (!__get_cpuid (0x80000001, &eax, &ebx, &ecx, &edx))
> > > > -    return 0;
> > > > -
> > > > -  /* Run FMA4 test only if host has FMA4 support.  */
> > > > -  if (ecx & bit_FMA4)
> > > > +  /* Check cpu support foe FMA4.  */
> > > > +  if (__builtin_cpu_supports ("fma4"))
> > > >      do_test ();
> > > >
> > > >    return 0;
> > > > diff --git a/gcc/testsuite/gcc.target/i386/lzcnt-check.h b/gcc/testsuite/gcc.target/i386/lzcnt-check.h
> > > > index 8aad834d6af..824f1a3b513 100644
> > > > --- a/gcc/testsuite/gcc.target/i386/lzcnt-check.h
> > > > +++ b/gcc/testsuite/gcc.target/i386/lzcnt-check.h
> > > > @@ -1,8 +1,6 @@
> > > >  #include <stdio.h>
> > > >  #include <stdlib.h>
> > > >
> > > > -#include "cpuid.h"
> > > > -
> > > >  static void lzcnt_test (void);
> > > >
> > > >  static void
> > > > @@ -15,13 +13,8 @@ do_test (void)
> > > >  int
> > > >  main ()
> > > >  {
> > > > -  unsigned int eax, ebx, ecx, edx;
> > > > -
> > > > -  if (!__get_cpuid (0x80000001, &eax, &ebx, &ecx, &edx))
> > > > -    return 0;
> > > > -
> > > > -  /* Run LZCNT test only if host has LZCNT support.  */
> > > > -  if (ecx & bit_LZCNT)
> > > > +  /* Check cpu support for LZCNT.  */
> > > > +  if (__builtin_cpu_supports ("lzcnt"))
> > > >      {
> > > >        do_test ();
> > > >  #ifdef DEBUG
> > > > diff --git a/gcc/testsuite/gcc.target/i386/mmx-3dnow-check.h b/gcc/testsuite/gcc.target/i386/mmx-3dnow-check.h
> > > > index 4f2f7f3ac40..0ec2dca2e19 100644
> > > > --- a/gcc/testsuite/gcc.target/i386/mmx-3dnow-check.h
> > > > +++ b/gcc/testsuite/gcc.target/i386/mmx-3dnow-check.h
> > > > @@ -1,8 +1,6 @@
> > > >  #include <stdio.h>
> > > >  #include <stdlib.h>
> > > >
> > > > -#include "cpuid.h"
> > > > -
> > > >  static void mmx_3dnow_test (void);
> > > >
> > > >  static void
> > > > @@ -15,13 +13,8 @@ do_test (void)
> > > >  int
> > > >  main ()
> > > >  {
> > > > -  unsigned int eax, ebx, ecx, edx;
> > > > -
> > > > -  if (!__get_cpuid (0x80000001, &eax, &ebx, &ecx, &edx))
> > > > -    return 0;
> > > > -
> > > > -  /* Run 3DNow! test only if host has 3DNow! support.  */
> > > > -  if (edx & bit_3DNOW)
> > > > +  /* Check cpu support for 3DNow!.  */
> > > > +  if (__builtin_cpu_supports ("3dnow"))
> > > >      do_test ();
> > > >
> > > >    return 0;
> > > > diff --git a/gcc/testsuite/gcc.target/i386/mmx-check.h b/gcc/testsuite/gcc.target/i386/mmx-check.h
> > > > index faf9b876f38..2afe5183ba2 100644
> > > > --- a/gcc/testsuite/gcc.target/i386/mmx-check.h
> > > > +++ b/gcc/testsuite/gcc.target/i386/mmx-check.h
> > > > @@ -1,8 +1,6 @@
> > > >  #include <stdio.h>
> > > >  #include <stdlib.h>
> > > >
> > > > -#include "cpuid.h"
> > > > -
> > > >  static void mmx_test (void);
> > > >
> > > >  static void
> > > > @@ -15,13 +13,8 @@ do_test (void)
> > > >  int
> > > >  main ()
> > > >  {
> > > > -  unsigned int eax, ebx, ecx, edx;
> > > > -
> > > > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > > > -    return 0;
> > > > -
> > > > -  /* Run MMX test only if host has MMX support.  */
> > > > -  if (edx & bit_MMX)
> > > > +  /* Check cpu support for MMX.  */
> > > > +  if (__builtin_cpu_supports ("mmx"))
> > > >      do_test ();
> > > >
> > > >    return 0;
> > > > diff --git a/gcc/testsuite/gcc.target/i386/pclmul-avx-check.h b/gcc/testsuite/gcc.target/i386/pclmul-avx-check.h
> > > > index 5eed2e2203c..b506b3306e6 100644
> > > > --- a/gcc/testsuite/gcc.target/i386/pclmul-avx-check.h
> > > > +++ b/gcc/testsuite/gcc.target/i386/pclmul-avx-check.h
> > > > @@ -2,8 +2,6 @@
> > > >  #include <stdio.h>
> > > >  #endif
> > > >  #include <stdlib.h>
> > > > -#include "cpuid.h"
> > > > -#include "avx-os-support.h"
> > > >
> > > >  static void pclmul_avx_test (void);
> > > >
> > > > @@ -17,15 +15,9 @@ do_test (void)
> > > >  int
> > > >  main ()
> > > >  {
> > > > -  unsigned int eax, ebx, ecx, edx;
> > > > -
> > > > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > > > -    return 0;
> > > > -
> > > > -  /* Run PCLMUL + AVX test only if host has PCLMUL + AVX support.  */
> > > > -  if (((ecx & (bit_AVX | bit_OSXSAVE | bit_PCLMUL))
> > > > -       == (bit_AVX | bit_OSXSAVE | bit_PCLMUL))
> > > > -      && avx_os_support ())
> > > > +  /* Check cpu support for PCLMUL and AVX.  */
> > > > +  if (__builtin_cpu_supports ("pclmul")
> > > > +      && __builtin_cpu_supports ("avx"))
> > > >      {
> > > >        do_test ();
> > > >  #ifdef DEBUG
> > > > diff --git a/gcc/testsuite/gcc.target/i386/pclmul-check.h b/gcc/testsuite/gcc.target/i386/pclmul-check.h
> > > > index 7526cbe2ddf..3ed1a044627 100644
> > > > --- a/gcc/testsuite/gcc.target/i386/pclmul-check.h
> > > > +++ b/gcc/testsuite/gcc.target/i386/pclmul-check.h
> > > > @@ -1,8 +1,6 @@
> > > >  #include <stdio.h>
> > > >  #include <stdlib.h>
> > > >
> > > > -#include "cpuid.h"
> > > > -
> > > >  static void pclmul_test (void);
> > > >
> > > >  static void
> > > > @@ -15,13 +13,8 @@ do_test (void)
> > > >  int
> > > >  main ()
> > > >  {
> > > > -  unsigned int eax, ebx, ecx, edx;
> > > > -
> > > > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > > > -    return 0;
> > > > -
> > > > -  /* Run PCLMULQDQ test only if host has PCLMULQDQ support.  */
> > > > -  if (ecx & bit_PCLMUL)
> > > > +  /* Check cpu support for PCLMUL.  */
> > > > +  if (__builtin_cpu_supports ("pclmul"))
> > > >      {
> > > >        do_test ();
> > > >  #ifdef DEBUG
> > > > diff --git a/gcc/testsuite/gcc.target/i386/rtm-check.h b/gcc/testsuite/gcc.target/i386/rtm-check.h
> > > > index bdb5a6dc0bf..4121e602a7f 100644
> > > > --- a/gcc/testsuite/gcc.target/i386/rtm-check.h
> > > > +++ b/gcc/testsuite/gcc.target/i386/rtm-check.h
> > > > @@ -1,5 +1,4 @@
> > > >  #include <stdlib.h>
> > > > -#include "cpuid.h"
> > > >
> > > >  static void rtm_test (void);
> > > >
> > > > @@ -11,13 +10,8 @@ static void __attribute__ ((noinline)) do_test (void)
> > > >  int
> > > >  main ()
> > > >  {
> > > > -  unsigned int eax, ebx, ecx, edx;
> > > > -
> > > > -  if (!__get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx))
> > > > -    return 0;
> > > > -
> > > > -  /* Run RTM test only if host has RTM support.  */
> > > > -  if (ebx & bit_RTM)
> > > > +  /* Check cpu support for RTM.  */
> > > > +  if (__builtin_cpu_supports ("rtm"))
> > > >      {
> > > >        do_test ();
> > > >  #ifdef DEBUG
> > > > diff --git a/gcc/testsuite/gcc.target/i386/sha-check.h b/gcc/testsuite/gcc.target/i386/sha-check.h
> > > > index 5bc5a59ab80..61ce43053f9 100644
> > > > --- a/gcc/testsuite/gcc.target/i386/sha-check.h
> > > > +++ b/gcc/testsuite/gcc.target/i386/sha-check.h
> > > > @@ -1,5 +1,4 @@
> > > >  #include <stdlib.h>
> > > > -#include "cpuid.h"
> > > >
> > > >  static void sha_test (void);
> > > >
> > > > @@ -13,13 +12,8 @@ do_test (void)
> > > >  int
> > > >  main ()
> > > >  {
> > > > -  unsigned int eax, ebx, ecx, edx;
> > > > -
> > > > -  if (!__get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx))
> > > > -    return 0;
> > > > -
> > > > -  /* Run SHA test only if host has SHA support.  */
> > > > -  if (ebx & bit_SHA)
> > > > +  /* Check cpu support for SHA.  */
> > > > +  if (__builtin_cpu_supports ("sha"))
> > > >      {
> > > >        do_test ();
> > > >  #ifdef DEBUG
> > > > diff --git a/gcc/testsuite/gcc.target/i386/sse-check.h b/gcc/testsuite/gcc.target/i386/sse-check.h
> > > > index 11b71bc3e97..58bc88c5598 100644
> > > > --- a/gcc/testsuite/gcc.target/i386/sse-check.h
> > > > +++ b/gcc/testsuite/gcc.target/i386/sse-check.h
> > > > @@ -1,7 +1,5 @@
> > > >  #include <stdlib.h>
> > > >  #include "m128-check.h"
> > > > -#include "cpuid.h"
> > > > -#include "sse-os-support.h"
> > > >
> > > >  static void sse_test (void);
> > > >
> > > > @@ -15,13 +13,8 @@ do_test (void)
> > > >  int
> > > >  main ()
> > > >  {
> > > > -  unsigned int eax, ebx, ecx, edx;
> > > > -
> > > > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > > > -    return 0;
> > > > -
> > > > -  /* Run SSE test only if host has SSE support.  */
> > > > -  if ((edx & bit_SSE) && sse_os_support ())
> > > > +  /* Check cpu support for SSE.  */
> > > > +  if (__builtin_cpu_supports ("sse"))
> > > >      do_test ();
> > > >
> > > >    return 0;
> > > > diff --git a/gcc/testsuite/gcc.target/i386/sse2-check.h b/gcc/testsuite/gcc.target/i386/sse2-check.h
> > > > index fd4a6ce1dbf..4976a27022d 100644
> > > > --- a/gcc/testsuite/gcc.target/i386/sse2-check.h
> > > > +++ b/gcc/testsuite/gcc.target/i386/sse2-check.h
> > > > @@ -1,7 +1,5 @@
> > > >  #include <stdlib.h>
> > > > -#include "cpuid.h"
> > > >  #include "m128-check.h"
> > > > -#include "sse-os-support.h"
> > > >
> > > >  static void sse2_test (void);
> > > >
> > > > @@ -15,13 +13,8 @@ do_test (void)
> > > >  int
> > > >  main ()
> > > >  {
> > > > -  unsigned int eax, ebx, ecx, edx;
> > > > -
> > > > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > > > -    return 0;
> > > > -
> > > > -  /* Run SSE2 test only if host has SSE2 support.  */
> > > > -  if ((edx & bit_SSE2) && sse_os_support ())
> > > > +  /* Check cpu support for SSE2.  */
> > > > +  if (__builtin_cpu_supports ("sse2"))
> > > >      do_test ();
> > > >
> > > >    return 0;
> > > > diff --git a/gcc/testsuite/gcc.target/i386/sse3-check.h b/gcc/testsuite/gcc.target/i386/sse3-check.h
> > > > index 5a0a0b1a02e..3c58361e925 100644
> > > > --- a/gcc/testsuite/gcc.target/i386/sse3-check.h
> > > > +++ b/gcc/testsuite/gcc.target/i386/sse3-check.h
> > > > @@ -1,7 +1,5 @@
> > > >  #include <stdio.h>
> > > >  #include <stdlib.h>
> > > > -#include "cpuid.h"
> > > > -#include "sse-os-support.h"
> > > >
> > > >  static void sse3_test (void);
> > > >
> > > > @@ -15,13 +13,8 @@ do_test (void)
> > > >  int
> > > >  main ()
> > > >  {
> > > > -  unsigned int eax, ebx, ecx, edx;
> > > > -
> > > > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > > > -    return 0;
> > > > -
> > > > -  /* Run SSE3 test only if host has SSE3 support.  */
> > > > -  if ((ecx & bit_SSE3) && sse_os_support ())
> > > > +  /* Check cpu support for SSE3.  */
> > > > +  if (__builtin_cpu_supports ("sse3"))
> > > >      do_test ();
> > > >
> > > >    return 0;
> > > > diff --git a/gcc/testsuite/gcc.target/i386/sse4_1-check.h b/gcc/testsuite/gcc.target/i386/sse4_1-check.h
> > > > index 788f65d61cb..61d0d0284a8 100644
> > > > --- a/gcc/testsuite/gcc.target/i386/sse4_1-check.h
> > > > +++ b/gcc/testsuite/gcc.target/i386/sse4_1-check.h
> > > > @@ -1,6 +1,4 @@
> > > >  #include <stdlib.h>
> > > > -
> > > > -#include "cpuid.h"
> > > >  #include "m128-check.h"
> > > >
> > > >  static void sse4_1_test (void);
> > > > @@ -17,13 +15,8 @@ do_test (void)
> > > >  int
> > > >  main ()
> > > >  {
> > > > -  unsigned int eax, ebx, ecx, edx;
> > > > -
> > > > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > > > -    return 0;
> > > > -
> > > > -  /* Run SSE4.1 test only if host has SSE4.1 support.  */
> > > > -  if (ecx & bit_SSE4_1)
> > > > +  /* Check cpu support for SSE4.1.  */
> > > > +  if (__builtin_cpu_supports ("sse4.1"))
> > > >      do_test ();
> > > >
> > > >    return 0;
> > > > diff --git a/gcc/testsuite/gcc.target/i386/sse4_2-check.h b/gcc/testsuite/gcc.target/i386/sse4_2-check.h
> > > > index c33cd1b4986..6c921ac52c7 100644
> > > > --- a/gcc/testsuite/gcc.target/i386/sse4_2-check.h
> > > > +++ b/gcc/testsuite/gcc.target/i386/sse4_2-check.h
> > > > @@ -1,8 +1,6 @@
> > > >  #include <stdio.h>
> > > >  #include <stdlib.h>
> > > > -
> > > >  #include "m128-check.h"
> > > > -#include "cpuid.h"
> > > >
> > > >  static void sse4_2_test (void);
> > > >
> > > > @@ -16,13 +14,8 @@ do_test (void)
> > > >  int
> > > >  main ()
> > > >  {
> > > > -  unsigned int eax, ebx, ecx, edx;
> > > > -
> > > > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > > > -    return 0;
> > > > -
> > > > -  /* Run SSE4.2 test only if host has SSE4.2 support.  */
> > > > -  if (ecx & bit_SSE4_2)
> > > > +  /* Check cpu support for SSE4.2.  */
> > > > +  if (__builtin_cpu_supports ("sse4.2"))
> > > >      do_test ();
> > > >
> > > >    return 0;
> > > > diff --git a/gcc/testsuite/gcc.target/i386/sse4a-check.h b/gcc/testsuite/gcc.target/i386/sse4a-check.h
> > > > index d43b4b222b1..ae70ff0a268 100644
> > > > --- a/gcc/testsuite/gcc.target/i386/sse4a-check.h
> > > > +++ b/gcc/testsuite/gcc.target/i386/sse4a-check.h
> > > > @@ -1,8 +1,6 @@
> > > >  #include <stdio.h>
> > > >  #include <stdlib.h>
> > > >
> > > > -#include "cpuid.h"
> > > > -
> > > >  static void sse4a_test (void);
> > > >
> > > >  static void
> > > > @@ -15,13 +13,8 @@ do_test (void)
> > > >  int
> > > >  main ()
> > > >  {
> > > > -  unsigned int eax, ebx, ecx, edx;
> > > > -
> > > > -  if (!__get_cpuid (0x80000001, &eax, &ebx, &ecx, &edx))
> > > > -    return 0;
> > > > -
> > > > -  /* Run SSE4a test only if host has SSE4a support.  */
> > > > -  if (ecx & bit_SSE4a)
> > > > +  /* Check cpu support for SSE4a.  */
> > > > +  if (__builtin_cpu_supports ("sse4a"))
> > > >      do_test ();
> > > >
> > > >    return 0;
> > > > diff --git a/gcc/testsuite/gcc.target/i386/ssse3-check.h b/gcc/testsuite/gcc.target/i386/ssse3-check.h
> > > > index 3ca79333c7f..3e834811f2d 100644
> > > > --- a/gcc/testsuite/gcc.target/i386/ssse3-check.h
> > > > +++ b/gcc/testsuite/gcc.target/i386/ssse3-check.h
> > > > @@ -1,8 +1,6 @@
> > > >  #include <stdio.h>
> > > >  #include <stdlib.h>
> > > >
> > > > -#include "cpuid.h"
> > > > -
> > > >  static void ssse3_test (void);
> > > >
> > > >  static void
> > > > @@ -15,13 +13,8 @@ do_test (void)
> > > >  int
> > > >  main ()
> > > >  {
> > > > -  unsigned int eax, ebx, ecx, edx;
> > > > -
> > > > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > > > -    return 0;
> > > > -
> > > > -  /* Run SSSE3 test only if host has SSSE3 support.  */
> > > > -  if (ecx & bit_SSSE3)
> > > > +  /* Check cpu support for SSSE3.  */
> > > > +  if (__builtin_cpu_supports ("ssse3"))
> > > >      do_test ();
> > > >
> > > >    return 0;
> > > > diff --git a/gcc/testsuite/gcc.target/i386/xop-check.h b/gcc/testsuite/gcc.target/i386/xop-check.h
> > > > index 395abe8766d..e1ef1273111 100644
> > > > --- a/gcc/testsuite/gcc.target/i386/xop-check.h
> > > > +++ b/gcc/testsuite/gcc.target/i386/xop-check.h
> > > > @@ -1,6 +1,4 @@
> > > >  #include <stdlib.h>
> > > > -
> > > > -#include "cpuid.h"
> > > >  #include "m256-check.h"
> > > >
> > > >  static void xop_test (void);
> > > > @@ -15,13 +13,8 @@ do_test (void)
> > > >  int
> > > >  main ()
> > > >  {
> > > > -  unsigned int eax, ebx, ecx, edx;
> > > > -
> > > > -  if (!__get_cpuid (0x80000001, &eax, &ebx, &ecx, &edx))
> > > > -    return 0;
> > > > -
> > > > -  /* Run XOP test only if host has XOP support.  */
> > > > -  if (ecx & bit_XOP)
> > > > +  /* Check cpu support for XOP.  */
> > > > +  if (__builtin_cpu_supports ("xop"))
> > > >      do_test ();
> > > >
> > > >    return 0;
> > > > --
> > > > 2.18.1
> > > >
Li, Pan2 via Gcc-patches May 10, 2022, 5:16 a.m. UTC | #6
That make sense to me. Thx!

> -----Original Message-----
> From: Uros Bizjak <ubizjak@gmail.com>
> Sent: Saturday, May 7, 2022 5:04 PM
> To: Jiang, Haochen <haochen.jiang@intel.com>
> Cc: Hongyu Wang <wwwhhhyyy333@gmail.com>; Liu, Hongtao
> <hongtao.liu@intel.com>; gcc-patches@gcc.gnu.org
> Subject: Re: [PATCH] Reconstruct i386 testsuite with __builtin_cpu_supports
> 
> On Sat, May 7, 2022 at 3:20 AM Jiang, Haochen <haochen.jiang@intel.com>
> wrote:
> >
> > Hi Uros,
> >
> > I understand that we always keep the old testcases there. It is always safe to
> do that.
> >
> > But I have another question, if we add something new in one of the
> > existing files in the future, should we use __builtin_cpu_supports to keep the
> code clearer or stick to cpuids?
> 
> We should use __builtin_cpu_supports.
> 
> > I believe __builtin_cpu_supports will be a clearer way for a coder to
> understand under current circumstance.
> > So if we use that in future use, why don't we change everything to the same
> way?
> 
> Because we test the old and the new approach this way.
> 
> Uros.
> 
> > BRs,
> > Haochen
> >
> > -----Original Message-----
> > From: Uros Bizjak <ubizjak@gmail.com>
> > Sent: Friday, May 6, 2022 5:17 PM
> > To: Hongyu Wang <wwwhhhyyy333@gmail.com>
> > Cc: Jiang, Haochen <haochen.jiang@intel.com>; Liu, Hongtao
> > <hongtao.liu@intel.com>; gcc-patches@gcc.gnu.org
> > Subject: Re: [PATCH] Reconstruct i386 testsuite with
> > __builtin_cpu_supports
> >
> > On Fri, May 6, 2022 at 11:00 AM Hongyu Wang <wwwhhhyyy333@gmail.com>
> wrote:
> > >
> > > > I don't think *_os_support calls should be removed. IIRC,
> > > > __builtin_cpu_supports function checks if the feature is supported
> > > > by CPU, whereas *_os_supports calls check via xgetbv if OS
> > > > supports handling of new registers.
> > >
> > > avx_os_support is like
> > >
> > > avx_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_SSE | XSTATE_YMM)) == (XSTATE_SSE |
> > > XSTATE_YMM); }
> > >
> > > While in get_avaliable_features we have
> > >
> > > #define XCR_AVX_ENABLED_MASK \
> > >   (XSTATE_SSE | XSTATE_YMM)
> > >   if ((ecx & bit_OSXSAVE))
> > >     {
> > >       /* Check if XMM, YMM, OPMASK, upper 256 bits of ZMM0-ZMM15 and
> > > ZMM16-ZMM31 states are supported by OSXSAVE.  */
> > >       unsigned int xcrlow;
> > >       unsigned int xcrhigh;
> > >       __asm__ (".byte 0x0f, 0x01, 0xd0" /* xgetbv  */
> > >        : "=a" (xcrlow), "=d" (xcrhigh)
> > >        : "c" (XCR_XFEATURE_ENABLED_MASK));
> > >       if ((xcrlow & XCR_AVX_ENABLED_MASK) == XCR_AVX_ENABLED_MASK) {
> > >   avx_usable = 1;
> > >
> > > So __builtin_cpu_supports already inherits same check
> >
> > Indeed, thanks for the explanation.
> >
> > OTOH, we don't change the existing tests (perhaps only dg- directives
> > when infrastructure improves), so I would leave the existing testcases
> > as they are. In future, new helper functions should be implemented
> > with __builtin_cpu_supports, but let's leave existing ones as they
> > are.
> >
> > Uros.
> >
> > > Uros Bizjak via Gcc-patches <gcc-patches@gcc.gnu.org> 于2022年5月6
> 日周五
> > > 16:27写道:
> > > >
> > > > On Fri, May 6, 2022 at 9:57 AM Haochen Jiang <haochen.jiang@intel.com>
> wrote:
> > > > >
> > > > > Hi all,
> > > > >
> > > > > There are some check files in i386 testsuite are written before the
> function __builtin_cpu_supports is introduced. All of them are using
> __get_cpuid_count. This patch aims to reconstruct the i386 testsuite with
> __builtin_cpu_supports so that we can have a much clearer code.
> > > > >
> > > > > Regtested on x86_64-pc-linux-gnu. Ok for trunk?
> > > >
> > > > I don't think *_os_support calls should be removed. IIRC,
> > > > __builtin_cpu_supports function checks if the feature is supported
> > > > by CPU, whereas *_os_supports calls check via xgetbv if OS
> > > > supports handling of new registers.
> > > >
> > > > Uros.
> > > >
> > > > >
> > > > > Also when writting this patch, I also find some files in testsuite that might
> be useless currently. For example, in the file gcc/testsuite/gcc.target/i386/sse-
> os-support.h, it always return 1. And there are also some files will no longer be
> included at all with this patch. Should we remove those files when we have time?
> > > > >
> > > > > BRs,
> > > > > Haochen
> > > > >
> > > > > gcc/testsuite/ChangeLog:
> > > > >
> > > > >         * gcc.target/i386/adx-check.h: Change bit check to
> > > > >         __builtin_cpu_supports.
> > > > >         * gcc.target/i386/aes-avx-check.h: Ditto.
> > > > >         * gcc.target/i386/aes-check.h: Ditto.
> > > > >         * gcc.target/i386/avx-check.h: Ditto.
> > > > >         * gcc.target/i386/avx2-check.h: Ditto.
> > > > >         * gcc.target/i386/avx512-check.h: Ditto.
> > > > >         * gcc.target/i386/bmi-check.h: Ditto.
> > > > >         * gcc.target/i386/bmi2-check.h: Ditto.
> > > > >         * gcc.target/i386/f16c-check.h: Ditto.
> > > > >         * gcc.target/i386/fma-check.h: Ditto.
> > > > >         * gcc.target/i386/fma4-check.h: Ditto.
> > > > >         * gcc.target/i386/lzcnt-check.h: Ditto.
> > > > >         * gcc.target/i386/mmx-3dnow-check.h: Ditto.
> > > > >         * gcc.target/i386/mmx-check.h: Ditto.
> > > > >         * gcc.target/i386/pclmul-avx-check.h: Ditto.
> > > > >         * gcc.target/i386/pclmul-check.h: Ditto.
> > > > >         * gcc.target/i386/rtm-check.h: Ditto.
> > > > >         * gcc.target/i386/sha-check.h: Ditto.
> > > > >         * gcc.target/i386/sse-check.h: Ditto.
> > > > >         * gcc.target/i386/sse2-check.h: Ditto.
> > > > >         * gcc.target/i386/sse3-check.h: Ditto.
> > > > >         * gcc.target/i386/sse4_1-check.h: Ditto.
> > > > >         * gcc.target/i386/sse4_2-check.h: Ditto.
> > > > >         * gcc.target/i386/sse4a-check.h: Ditto.
> > > > >         * gcc.target/i386/ssse3-check.h: Ditto.
> > > > >         * gcc.target/i386/xop-check.h: Ditto.
> > > > > ---
> > > > >  gcc/testsuite/gcc.target/i386/adx-check.h     | 10 +---
> > > > >  gcc/testsuite/gcc.target/i386/aes-avx-check.h | 14 +----
> > > > >  gcc/testsuite/gcc.target/i386/aes-check.h     | 11 +---
> > > > >  gcc/testsuite/gcc.target/i386/avx-check.h     | 12 +---
> > > > >  gcc/testsuite/gcc.target/i386/avx2-check.h    | 20 +------
> > > > >  gcc/testsuite/gcc.target/i386/avx512-check.h  | 59 +++++++------------
> > > > >  gcc/testsuite/gcc.target/i386/bmi-check.h     | 11 +---
> > > > >  gcc/testsuite/gcc.target/i386/bmi2-check.h    | 10 +---
> > > > >  gcc/testsuite/gcc.target/i386/f16c-check.h    | 10 +---
> > > > >  gcc/testsuite/gcc.target/i386/fma-check.h     | 11 +---
> > > > >  gcc/testsuite/gcc.target/i386/fma4-check.h    | 11 +---
> > > > >  gcc/testsuite/gcc.target/i386/lzcnt-check.h   | 11 +---
> > > > >  .../gcc.target/i386/mmx-3dnow-check.h         | 11 +---
> > > > >  gcc/testsuite/gcc.target/i386/mmx-check.h     | 11 +---
> > > > >  .../gcc.target/i386/pclmul-avx-check.h        | 14 +----
> > > > >  gcc/testsuite/gcc.target/i386/pclmul-check.h  | 11 +---
> > > > >  gcc/testsuite/gcc.target/i386/rtm-check.h     | 10 +---
> > > > >  gcc/testsuite/gcc.target/i386/sha-check.h     | 10 +---
> > > > >  gcc/testsuite/gcc.target/i386/sse-check.h     | 11 +---
> > > > >  gcc/testsuite/gcc.target/i386/sse2-check.h    | 11 +---
> > > > >  gcc/testsuite/gcc.target/i386/sse3-check.h    | 11 +---
> > > > >  gcc/testsuite/gcc.target/i386/sse4_1-check.h  | 11 +---
> > > > > gcc/testsuite/gcc.target/i386/sse4_2-check.h  | 11 +---
> > > > >  gcc/testsuite/gcc.target/i386/sse4a-check.h   | 11 +---
> > > > >  gcc/testsuite/gcc.target/i386/ssse3-check.h   | 11 +---
> > > > >  gcc/testsuite/gcc.target/i386/xop-check.h     | 11 +---
> > > > >  26 files changed, 73 insertions(+), 272 deletions(-)
> > > > >
> > > > > diff --git a/gcc/testsuite/gcc.target/i386/adx-check.h
> > > > > b/gcc/testsuite/gcc.target/i386/adx-check.h
> > > > > index cfed1a38483..bed5dcca385 100644
> > > > > --- a/gcc/testsuite/gcc.target/i386/adx-check.h
> > > > > +++ b/gcc/testsuite/gcc.target/i386/adx-check.h
> > > > > @@ -1,5 +1,4 @@
> > > > >  #include <stdlib.h>
> > > > > -#include "cpuid.h"
> > > > >
> > > > >  static void adx_test (void);
> > > > >
> > > > > @@ -11,13 +10,8 @@ static void __attribute__ ((noinline))
> > > > > do_test (void)  int  main ()  {
> > > > > -  unsigned int eax, ebx, ecx, edx;
> > > > > -
> > > > > -  if (!__get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx))
> > > > > -    return 0;
> > > > > -
> > > > > -  /* Run ADX test only if host has ADX support.  */
> > > > > -  if (ebx & bit_ADX)
> > > > > +  /* Check cpu support for ADX.  */  if (__builtin_cpu_supports
> > > > > + ("adx"))
> > > > >      {
> > > > >        do_test ();
> > > > >  #ifdef DEBUG
> > > > > diff --git a/gcc/testsuite/gcc.target/i386/aes-avx-check.h
> > > > > b/gcc/testsuite/gcc.target/i386/aes-avx-check.h
> > > > > index f2a4ead4014..74bf597ead4 100644
> > > > > --- a/gcc/testsuite/gcc.target/i386/aes-avx-check.h
> > > > > +++ b/gcc/testsuite/gcc.target/i386/aes-avx-check.h
> > > > > @@ -2,8 +2,6 @@
> > > > >  #include <stdio.h>
> > > > >  #endif
> > > > >  #include <stdlib.h>
> > > > > -#include "cpuid.h"
> > > > > -#include "avx-os-support.h"
> > > > >
> > > > >  static void aes_avx_test (void);
> > > > >
> > > > > @@ -17,15 +15,9 @@ do_test (void)  int  main ()  {
> > > > > -  unsigned int eax, ebx, ecx, edx;
> > > > > -
> > > > > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > > > > -    return 0;
> > > > > -
> > > > > -  /* Run AES + AVX test only if host has AES + AVX support.  */
> > > > > -  if (((ecx & (bit_AVX | bit_OSXSAVE | bit_AES))
> > > > > -       == (bit_AVX | bit_OSXSAVE | bit_AES))
> > > > > -      && avx_os_support ())
> > > > > +  /* Check cpu support for AES and AVX.  */  if
> > > > > + (__builtin_cpu_supports ("avx")
> > > > > +      && __builtin_cpu_supports ("aes"))
> > > > >      {
> > > > >        do_test ();
> > > > >  #ifdef DEBUG
> > > > > diff --git a/gcc/testsuite/gcc.target/i386/aes-check.h
> > > > > b/gcc/testsuite/gcc.target/i386/aes-check.h
> > > > > index 7e794423e47..7c3a3b324a7 100644
> > > > > --- a/gcc/testsuite/gcc.target/i386/aes-check.h
> > > > > +++ b/gcc/testsuite/gcc.target/i386/aes-check.h
> > > > > @@ -1,8 +1,6 @@
> > > > >  #include <stdio.h>
> > > > >  #include <stdlib.h>
> > > > >
> > > > > -#include "cpuid.h"
> > > > > -
> > > > >  static void aes_test (void);
> > > > >
> > > > >  static void
> > > > > @@ -15,13 +13,8 @@ do_test (void)  int  main ()  {
> > > > > -  unsigned int eax, ebx, ecx, edx;
> > > > > -
> > > > > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > > > > -    return 0;
> > > > > -
> > > > > -  /* Run AES test only if host has AES support.  */
> > > > > -  if (ecx & bit_AES)
> > > > > +  /* Check cpu support for AES.  */  if (__builtin_cpu_supports
> > > > > + ("aes"))
> > > > >      {
> > > > >        do_test ();
> > > > >  #ifdef DEBUG
> > > > > diff --git a/gcc/testsuite/gcc.target/i386/avx-check.h
> > > > > b/gcc/testsuite/gcc.target/i386/avx-check.h
> > > > > index 7ddca9d7b80..4a3dbc257bc 100644
> > > > > --- a/gcc/testsuite/gcc.target/i386/avx-check.h
> > > > > +++ b/gcc/testsuite/gcc.target/i386/avx-check.h
> > > > > @@ -1,7 +1,5 @@
> > > > >  #include <stdlib.h>
> > > > > -#include "cpuid.h"
> > > > >  #include "m256-check.h"
> > > > > -#include "avx-os-support.h"
> > > > >
> > > > >  static void avx_test (void);
> > > > >
> > > > > @@ -15,14 +13,8 @@ do_test (void)  int  main ()  {
> > > > > -  unsigned int eax, ebx, ecx, edx;
> > > > > -
> > > > > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > > > > -    return 0;
> > > > > -
> > > > > -  /* Run AVX test only if host has AVX support.  */
> > > > > -  if (((ecx & (bit_AVX | bit_OSXSAVE)) == (bit_AVX | bit_OSXSAVE))
> > > > > -      && avx_os_support ())
> > > > > +  /* Check cpu support for AVX.  */  if (__builtin_cpu_supports
> > > > > + ("avx"))
> > > > >      {
> > > > >        do_test ();
> > > > >  #ifdef DEBUG
> > > > > diff --git a/gcc/testsuite/gcc.target/i386/avx2-check.h
> > > > > b/gcc/testsuite/gcc.target/i386/avx2-check.h
> > > > > index 25bed5e0da6..2bc3c4425bb 100644
> > > > > --- a/gcc/testsuite/gcc.target/i386/avx2-check.h
> > > > > +++ b/gcc/testsuite/gcc.target/i386/avx2-check.h
> > > > > @@ -1,7 +1,5 @@
> > > > >  #include <stdlib.h>
> > > > > -#include "cpuid.h"
> > > > >  #include "m256-check.h"
> > > > > -#include "avx-os-support.h"
> > > > >
> > > > >  static void avx2_test (void);
> > > > >
> > > > > @@ -10,25 +8,11 @@ static void __attribute__ ((noinline)) do_test (void)
> > > > >    avx2_test ();
> > > > >  }
> > > > >
> > > > > -static int
> > > > > -check_osxsave (void)
> > > > > -{
> > > > > -  unsigned int eax, ebx, ecx, edx;
> > > > > -
> > > > > -  __cpuid (1, eax, ebx, ecx, edx);
> > > > > -  return (ecx & bit_OSXSAVE) != 0; -}
> > > > > -
> > > > >  int
> > > > >  main ()
> > > > >  {
> > > > > -  unsigned int eax, ebx, ecx, edx;
> > > > > -
> > > > > -  if (!__get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx))
> > > > > -    return 0;
> > > > > -
> > > > > -  /* Run AVX2 test only if host has AVX2 support.  */
> > > > > -  if (check_osxsave () && (ebx & bit_AVX2) && avx_os_support
> > > > > ())
> > > > > +  /* Check cpu support for AVX2.  */  if
> > > > > + (__builtin_cpu_supports ("avx2"))
> > > > >      {
> > > > >        do_test ();
> > > > >  #ifdef DEBUG
> > > > > diff --git a/gcc/testsuite/gcc.target/i386/avx512-check.h
> > > > > b/gcc/testsuite/gcc.target/i386/avx512-check.h
> > > > > index 0ad9064f637..339c79070c9 100644
> > > > > --- a/gcc/testsuite/gcc.target/i386/avx512-check.h
> > > > > +++ b/gcc/testsuite/gcc.target/i386/avx512-check.h
> > > > > @@ -1,7 +1,5 @@
> > > > >  #include <stdlib.h>
> > > > > -#include "cpuid.h"
> > > > >  #include "m512-check.h"
> > > > > -#include "avx512f-os-support.h"
> > > > >
> > > > >  #ifndef DO_TEST
> > > > >  #define DO_TEST do_test
> > > > > @@ -25,81 +23,66 @@ do_test (void)  }  #endif
> > > > >
> > > > > -static int
> > > > > -check_osxsave (void)
> > > > > -{
> > > > > -  unsigned int eax, ebx, ecx, edx;
> > > > > -
> > > > > -  __cpuid (1, eax, ebx, ecx, edx);
> > > > > -  return (ecx & bit_OSXSAVE) != 0; -}
> > > > > -
> > > > >  int
> > > > >  main ()
> > > > >  {
> > > > > -  unsigned int eax, ebx, ecx, edx;
> > > > > -
> > > > > -  if (!__get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx))
> > > > > -    return 0;
> > > > > -
> > > > > -  /* Run AVX512 test only if host has ISA support.  */
> > > > > -  if (check_osxsave ()
> > > > > -      && (ebx & bit_AVX512F)
> > > > > +  /* Check cpu support for AVX512.  */  if
> > > > > + (__builtin_cpu_supports ("avx512f")
> > > > >  #ifdef AVX512VL
> > > > > -      && (ebx & bit_AVX512VL)
> > > > > +      && __builtin_cpu_supports ("avx512vl")
> > > > >  #endif
> > > > >  #ifdef AVX512ER
> > > > > -      && (ebx & bit_AVX512ER)
> > > > > +      && __builtin_cpu_supports ("avx512er")
> > > > >  #endif
> > > > >  #ifdef AVX512CD
> > > > > -      && (ebx & bit_AVX512CD)
> > > > > +      && __builtin_cpu_supports ("avx512cd")
> > > > >  #endif
> > > > >  #ifdef AVX512DQ
> > > > > -      && (ebx & bit_AVX512DQ)
> > > > > +      && __builtin_cpu_supports ("avx512dq")
> > > > >  #endif
> > > > >  #ifdef AVX512BW
> > > > > -      && (ebx & bit_AVX512BW)
> > > > > +      && __builtin_cpu_supports ("avx512bw")
> > > > >  #endif
> > > > >  #ifdef AVX512IFMA
> > > > > -      && (ebx & bit_AVX512IFMA)
> > > > > +      && __builtin_cpu_supports ("avx512ifma")
> > > > >  #endif
> > > > >  #ifdef AVX512VBMI
> > > > > -      && (ecx & bit_AVX512VBMI)
> > > > > +      && __builtin_cpu_supports ("avx512vbmi")
> > > > >  #endif
> > > > >  #ifdef AVX5124FMAPS
> > > > > -      && (edx & bit_AVX5124FMAPS)
> > > > > +      && __builtin_cpu_supports ("avx5124fmaps")
> > > > >  #endif
> > > > >  #ifdef AVX5124VNNIW
> > > > > -      && (edx & bit_AVX5124VNNIW)
> > > > > +      && __builtin_cpu_supports ("avx5124vnniw")
> > > > >  #endif
> > > > >  #ifdef AVX512VPOPCNTDQ
> > > > > -      && (ecx & bit_AVX512VPOPCNTDQ)
> > > > > +      && __builtin_cpu_supports ("avx512vpopcntdq")
> > > > >  #endif
> > > > >  #ifdef AVX512BITALG
> > > > > -      && (ecx & bit_AVX512BITALG)
> > > > > +      && __builtin_cpu_supports ("avx512bitalg")
> > > > >  #endif
> > > > >  #ifdef GFNI
> > > > > -      && (ecx & bit_GFNI)
> > > > > +      && __builtin_cpu_supports ("gfni")
> > > > >  #endif
> > > > >  #ifdef AVX512VBMI2
> > > > > -      && (ecx & bit_AVX512VBMI2)
> > > > > +      && __builtin_cpu_supports ("avx512vbmi2")
> > > > >  #endif
> > > > >  #ifdef AVX512VNNI
> > > > > -      && (ecx & bit_AVX512VNNI)
> > > > > +      && __builtin_cpu_supports ("avx512vnni")
> > > > >  #endif
> > > > >  #ifdef AVX512FP16
> > > > > -      && (edx & bit_AVX512FP16)
> > > > > +      && __builtin_cpu_supports ("avx512fp16")
> > > > >  #endif
> > > > >  #ifdef VAES
> > > > > -      && (ecx & bit_VAES)
> > > > > +      && __builtin_cpu_supports ("vaes")
> > > > >  #endif
> > > > >  #ifdef VPCLMULQDQ
> > > > > -      && (ecx & bit_VPCLMULQDQ)
> > > > > +      && __builtin_cpu_supports ("vpclmulqdq")
> > > > >  #endif
> > > > >  #ifdef AVX512VP2INTERSECT
> > > > > -      && (edx & bit_AVX512VP2INTERSECT)
> > > > > +      && __builtin_cpu_supports ("avx512vp2intersect")
> > > > >  #endif
> > > > > -      && avx512f_os_support ())
> > > > > +      )
> > > > >      {
> > > > >        DO_TEST ();
> > > > >  #ifdef DEBUG
> > > > > diff --git a/gcc/testsuite/gcc.target/i386/bmi-check.h
> > > > > b/gcc/testsuite/gcc.target/i386/bmi-check.h
> > > > > index 1973f3b6468..6af0291a947 100644
> > > > > --- a/gcc/testsuite/gcc.target/i386/bmi-check.h
> > > > > +++ b/gcc/testsuite/gcc.target/i386/bmi-check.h
> > > > > @@ -1,8 +1,6 @@
> > > > >  #include <stdio.h>
> > > > >  #include <stdlib.h>
> > > > >
> > > > > -#include "cpuid.h"
> > > > > -
> > > > >  static void bmi_test (void);
> > > > >
> > > > >  static void
> > > > > @@ -15,13 +13,8 @@ do_test (void)  int  main ()  {
> > > > > -  unsigned int eax, ebx, ecx, edx;
> > > > > -
> > > > > -  if (!__get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx))
> > > > > -    return 0;
> > > > > -
> > > > > -  /* Run BMI test only if host has BMI support.  */
> > > > > -  if (ebx & bit_BMI)
> > > > > +  /* Check cpu support for BMI.  */  if (__builtin_cpu_supports
> > > > > + ("bmi"))
> > > > >      {
> > > > >        do_test ();
> > > > >  #ifdef DEBUG
> > > > > diff --git a/gcc/testsuite/gcc.target/i386/bmi2-check.h
> > > > > b/gcc/testsuite/gcc.target/i386/bmi2-check.h
> > > > > index ba91ef9b780..75c4d8d9616 100644
> > > > > --- a/gcc/testsuite/gcc.target/i386/bmi2-check.h
> > > > > +++ b/gcc/testsuite/gcc.target/i386/bmi2-check.h
> > > > > @@ -1,6 +1,5 @@
> > > > >  #include <stdio.h>
> > > > >  #include <stdlib.h>
> > > > > -#include "cpuid.h"
> > > > >
> > > > >  static void bmi2_test (void);
> > > > >
> > > > > @@ -14,13 +13,8 @@ do_test (void)  int  main ()  {
> > > > > -  unsigned int eax, ebx, ecx, edx;
> > > > > -
> > > > > -  if (!__get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx))
> > > > > -    return 0;
> > > > > -
> > > > > -  /* Run BMI2 test only if host has BMI2 support.  */
> > > > > -  if (ebx & bit_BMI2)
> > > > > +  /* Check cpu support for BMI2.  */  if
> > > > > + (__builtin_cpu_supports ("bmi2"))
> > > > >      {
> > > > >        do_test ();
> > > > >  #ifdef DEBUG
> > > > > diff --git a/gcc/testsuite/gcc.target/i386/f16c-check.h
> > > > > b/gcc/testsuite/gcc.target/i386/f16c-check.h
> > > > > index af7f32c5f4f..2cbf34ab516 100644
> > > > > --- a/gcc/testsuite/gcc.target/i386/f16c-check.h
> > > > > +++ b/gcc/testsuite/gcc.target/i386/f16c-check.h
> > > > > @@ -1,6 +1,5 @@
> > > > >  #include <stdlib.h>
> > > > >  #include <stdio.h>
> > > > > -#include "cpuid.h"
> > > > >  #include "m256-check.h"
> > > > >
> > > > >  static void f16c_test (void);
> > > > > @@ -8,13 +7,8 @@ static void f16c_test (void);  int  main ()  {
> > > > > -  unsigned int eax, ebx, ecx, edx;
> > > > > -
> > > > > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > > > > -    return 0;
> > > > > -
> > > > > -  /* Run F16C test only if host has F16C support.  */
> > > > > -  if (ecx & bit_F16C)
> > > > > +  /* Check cpu support for F16C.  */  if
> > > > > + (__builtin_cpu_supports ("f16c"))
> > > > >      {
> > > > >        f16c_test ();
> > > > >  #ifdef DEBUG
> > > > > diff --git a/gcc/testsuite/gcc.target/i386/fma-check.h
> > > > > b/gcc/testsuite/gcc.target/i386/fma-check.h
> > > > > index 8390f5088bd..6c1d3372218 100644
> > > > > --- a/gcc/testsuite/gcc.target/i386/fma-check.h
> > > > > +++ b/gcc/testsuite/gcc.target/i386/fma-check.h
> > > > > @@ -1,7 +1,5 @@
> > > > >  #include <stdlib.h>
> > > > >
> > > > > -#include "cpuid.h"
> > > > > -
> > > > >  static void fma_test (void);
> > > > >
> > > > >  static void __attribute__ ((noinline)) do_test (void) @@ -12,13
> > > > > +10,8 @@ static void __attribute__ ((noinline)) do_test (void)
> > > > > int  main ()  {
> > > > > -  unsigned int eax, ebx, ecx, edx;
> > > > > -
> > > > > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > > > > -    return 0;
> > > > > -
> > > > > -  /* Run FMA test only if host has FMA support.  */
> > > > > -  if (ecx & bit_FMA)
> > > > > +  /* Check cpu support for FMA.  */  if (__builtin_cpu_supports
> > > > > + ("fma"))
> > > > >      do_test ();
> > > > >
> > > > >    return 0;
> > > > > diff --git a/gcc/testsuite/gcc.target/i386/fma4-check.h
> > > > > b/gcc/testsuite/gcc.target/i386/fma4-check.h
> > > > > index 33cd9628c04..2d2c2718029 100644
> > > > > --- a/gcc/testsuite/gcc.target/i386/fma4-check.h
> > > > > +++ b/gcc/testsuite/gcc.target/i386/fma4-check.h
> > > > > @@ -1,7 +1,5 @@
> > > > >  #include <stdlib.h>
> > > > >
> > > > > -#include "cpuid.h"
> > > > > -
> > > > >  static void fma4_test (void);
> > > > >
> > > > >  static void
> > > > > @@ -14,13 +12,8 @@ do_test (void)  int  main ()  {
> > > > > -  unsigned int eax, ebx, ecx, edx;
> > > > > -
> > > > > -  if (!__get_cpuid (0x80000001, &eax, &ebx, &ecx, &edx))
> > > > > -    return 0;
> > > > > -
> > > > > -  /* Run FMA4 test only if host has FMA4 support.  */
> > > > > -  if (ecx & bit_FMA4)
> > > > > +  /* Check cpu support foe FMA4.  */  if
> > > > > + (__builtin_cpu_supports ("fma4"))
> > > > >      do_test ();
> > > > >
> > > > >    return 0;
> > > > > diff --git a/gcc/testsuite/gcc.target/i386/lzcnt-check.h
> > > > > b/gcc/testsuite/gcc.target/i386/lzcnt-check.h
> > > > > index 8aad834d6af..824f1a3b513 100644
> > > > > --- a/gcc/testsuite/gcc.target/i386/lzcnt-check.h
> > > > > +++ b/gcc/testsuite/gcc.target/i386/lzcnt-check.h
> > > > > @@ -1,8 +1,6 @@
> > > > >  #include <stdio.h>
> > > > >  #include <stdlib.h>
> > > > >
> > > > > -#include "cpuid.h"
> > > > > -
> > > > >  static void lzcnt_test (void);
> > > > >
> > > > >  static void
> > > > > @@ -15,13 +13,8 @@ do_test (void)  int  main ()  {
> > > > > -  unsigned int eax, ebx, ecx, edx;
> > > > > -
> > > > > -  if (!__get_cpuid (0x80000001, &eax, &ebx, &ecx, &edx))
> > > > > -    return 0;
> > > > > -
> > > > > -  /* Run LZCNT test only if host has LZCNT support.  */
> > > > > -  if (ecx & bit_LZCNT)
> > > > > +  /* Check cpu support for LZCNT.  */  if
> > > > > + (__builtin_cpu_supports ("lzcnt"))
> > > > >      {
> > > > >        do_test ();
> > > > >  #ifdef DEBUG
> > > > > diff --git a/gcc/testsuite/gcc.target/i386/mmx-3dnow-check.h
> > > > > b/gcc/testsuite/gcc.target/i386/mmx-3dnow-check.h
> > > > > index 4f2f7f3ac40..0ec2dca2e19 100644
> > > > > --- a/gcc/testsuite/gcc.target/i386/mmx-3dnow-check.h
> > > > > +++ b/gcc/testsuite/gcc.target/i386/mmx-3dnow-check.h
> > > > > @@ -1,8 +1,6 @@
> > > > >  #include <stdio.h>
> > > > >  #include <stdlib.h>
> > > > >
> > > > > -#include "cpuid.h"
> > > > > -
> > > > >  static void mmx_3dnow_test (void);
> > > > >
> > > > >  static void
> > > > > @@ -15,13 +13,8 @@ do_test (void)  int  main ()  {
> > > > > -  unsigned int eax, ebx, ecx, edx;
> > > > > -
> > > > > -  if (!__get_cpuid (0x80000001, &eax, &ebx, &ecx, &edx))
> > > > > -    return 0;
> > > > > -
> > > > > -  /* Run 3DNow! test only if host has 3DNow! support.  */
> > > > > -  if (edx & bit_3DNOW)
> > > > > +  /* Check cpu support for 3DNow!.  */  if
> > > > > + (__builtin_cpu_supports ("3dnow"))
> > > > >      do_test ();
> > > > >
> > > > >    return 0;
> > > > > diff --git a/gcc/testsuite/gcc.target/i386/mmx-check.h
> > > > > b/gcc/testsuite/gcc.target/i386/mmx-check.h
> > > > > index faf9b876f38..2afe5183ba2 100644
> > > > > --- a/gcc/testsuite/gcc.target/i386/mmx-check.h
> > > > > +++ b/gcc/testsuite/gcc.target/i386/mmx-check.h
> > > > > @@ -1,8 +1,6 @@
> > > > >  #include <stdio.h>
> > > > >  #include <stdlib.h>
> > > > >
> > > > > -#include "cpuid.h"
> > > > > -
> > > > >  static void mmx_test (void);
> > > > >
> > > > >  static void
> > > > > @@ -15,13 +13,8 @@ do_test (void)  int  main ()  {
> > > > > -  unsigned int eax, ebx, ecx, edx;
> > > > > -
> > > > > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > > > > -    return 0;
> > > > > -
> > > > > -  /* Run MMX test only if host has MMX support.  */
> > > > > -  if (edx & bit_MMX)
> > > > > +  /* Check cpu support for MMX.  */  if (__builtin_cpu_supports
> > > > > + ("mmx"))
> > > > >      do_test ();
> > > > >
> > > > >    return 0;
> > > > > diff --git a/gcc/testsuite/gcc.target/i386/pclmul-avx-check.h
> > > > > b/gcc/testsuite/gcc.target/i386/pclmul-avx-check.h
> > > > > index 5eed2e2203c..b506b3306e6 100644
> > > > > --- a/gcc/testsuite/gcc.target/i386/pclmul-avx-check.h
> > > > > +++ b/gcc/testsuite/gcc.target/i386/pclmul-avx-check.h
> > > > > @@ -2,8 +2,6 @@
> > > > >  #include <stdio.h>
> > > > >  #endif
> > > > >  #include <stdlib.h>
> > > > > -#include "cpuid.h"
> > > > > -#include "avx-os-support.h"
> > > > >
> > > > >  static void pclmul_avx_test (void);
> > > > >
> > > > > @@ -17,15 +15,9 @@ do_test (void)  int  main ()  {
> > > > > -  unsigned int eax, ebx, ecx, edx;
> > > > > -
> > > > > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > > > > -    return 0;
> > > > > -
> > > > > -  /* Run PCLMUL + AVX test only if host has PCLMUL + AVX
> > > > > support.  */
> > > > > -  if (((ecx & (bit_AVX | bit_OSXSAVE | bit_PCLMUL))
> > > > > -       == (bit_AVX | bit_OSXSAVE | bit_PCLMUL))
> > > > > -      && avx_os_support ())
> > > > > +  /* Check cpu support for PCLMUL and AVX.  */  if
> > > > > + (__builtin_cpu_supports ("pclmul")
> > > > > +      && __builtin_cpu_supports ("avx"))
> > > > >      {
> > > > >        do_test ();
> > > > >  #ifdef DEBUG
> > > > > diff --git a/gcc/testsuite/gcc.target/i386/pclmul-check.h
> > > > > b/gcc/testsuite/gcc.target/i386/pclmul-check.h
> > > > > index 7526cbe2ddf..3ed1a044627 100644
> > > > > --- a/gcc/testsuite/gcc.target/i386/pclmul-check.h
> > > > > +++ b/gcc/testsuite/gcc.target/i386/pclmul-check.h
> > > > > @@ -1,8 +1,6 @@
> > > > >  #include <stdio.h>
> > > > >  #include <stdlib.h>
> > > > >
> > > > > -#include "cpuid.h"
> > > > > -
> > > > >  static void pclmul_test (void);
> > > > >
> > > > >  static void
> > > > > @@ -15,13 +13,8 @@ do_test (void)  int  main ()  {
> > > > > -  unsigned int eax, ebx, ecx, edx;
> > > > > -
> > > > > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > > > > -    return 0;
> > > > > -
> > > > > -  /* Run PCLMULQDQ test only if host has PCLMULQDQ support.  */
> > > > > -  if (ecx & bit_PCLMUL)
> > > > > +  /* Check cpu support for PCLMUL.  */  if
> > > > > + (__builtin_cpu_supports ("pclmul"))
> > > > >      {
> > > > >        do_test ();
> > > > >  #ifdef DEBUG
> > > > > diff --git a/gcc/testsuite/gcc.target/i386/rtm-check.h
> > > > > b/gcc/testsuite/gcc.target/i386/rtm-check.h
> > > > > index bdb5a6dc0bf..4121e602a7f 100644
> > > > > --- a/gcc/testsuite/gcc.target/i386/rtm-check.h
> > > > > +++ b/gcc/testsuite/gcc.target/i386/rtm-check.h
> > > > > @@ -1,5 +1,4 @@
> > > > >  #include <stdlib.h>
> > > > > -#include "cpuid.h"
> > > > >
> > > > >  static void rtm_test (void);
> > > > >
> > > > > @@ -11,13 +10,8 @@ static void __attribute__ ((noinline))
> > > > > do_test (void)  int  main ()  {
> > > > > -  unsigned int eax, ebx, ecx, edx;
> > > > > -
> > > > > -  if (!__get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx))
> > > > > -    return 0;
> > > > > -
> > > > > -  /* Run RTM test only if host has RTM support.  */
> > > > > -  if (ebx & bit_RTM)
> > > > > +  /* Check cpu support for RTM.  */  if (__builtin_cpu_supports
> > > > > + ("rtm"))
> > > > >      {
> > > > >        do_test ();
> > > > >  #ifdef DEBUG
> > > > > diff --git a/gcc/testsuite/gcc.target/i386/sha-check.h
> > > > > b/gcc/testsuite/gcc.target/i386/sha-check.h
> > > > > index 5bc5a59ab80..61ce43053f9 100644
> > > > > --- a/gcc/testsuite/gcc.target/i386/sha-check.h
> > > > > +++ b/gcc/testsuite/gcc.target/i386/sha-check.h
> > > > > @@ -1,5 +1,4 @@
> > > > >  #include <stdlib.h>
> > > > > -#include "cpuid.h"
> > > > >
> > > > >  static void sha_test (void);
> > > > >
> > > > > @@ -13,13 +12,8 @@ do_test (void)  int  main ()  {
> > > > > -  unsigned int eax, ebx, ecx, edx;
> > > > > -
> > > > > -  if (!__get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx))
> > > > > -    return 0;
> > > > > -
> > > > > -  /* Run SHA test only if host has SHA support.  */
> > > > > -  if (ebx & bit_SHA)
> > > > > +  /* Check cpu support for SHA.  */  if (__builtin_cpu_supports
> > > > > + ("sha"))
> > > > >      {
> > > > >        do_test ();
> > > > >  #ifdef DEBUG
> > > > > diff --git a/gcc/testsuite/gcc.target/i386/sse-check.h
> > > > > b/gcc/testsuite/gcc.target/i386/sse-check.h
> > > > > index 11b71bc3e97..58bc88c5598 100644
> > > > > --- a/gcc/testsuite/gcc.target/i386/sse-check.h
> > > > > +++ b/gcc/testsuite/gcc.target/i386/sse-check.h
> > > > > @@ -1,7 +1,5 @@
> > > > >  #include <stdlib.h>
> > > > >  #include "m128-check.h"
> > > > > -#include "cpuid.h"
> > > > > -#include "sse-os-support.h"
> > > > >
> > > > >  static void sse_test (void);
> > > > >
> > > > > @@ -15,13 +13,8 @@ do_test (void)  int  main ()  {
> > > > > -  unsigned int eax, ebx, ecx, edx;
> > > > > -
> > > > > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > > > > -    return 0;
> > > > > -
> > > > > -  /* Run SSE test only if host has SSE support.  */
> > > > > -  if ((edx & bit_SSE) && sse_os_support ())
> > > > > +  /* Check cpu support for SSE.  */  if (__builtin_cpu_supports
> > > > > + ("sse"))
> > > > >      do_test ();
> > > > >
> > > > >    return 0;
> > > > > diff --git a/gcc/testsuite/gcc.target/i386/sse2-check.h
> > > > > b/gcc/testsuite/gcc.target/i386/sse2-check.h
> > > > > index fd4a6ce1dbf..4976a27022d 100644
> > > > > --- a/gcc/testsuite/gcc.target/i386/sse2-check.h
> > > > > +++ b/gcc/testsuite/gcc.target/i386/sse2-check.h
> > > > > @@ -1,7 +1,5 @@
> > > > >  #include <stdlib.h>
> > > > > -#include "cpuid.h"
> > > > >  #include "m128-check.h"
> > > > > -#include "sse-os-support.h"
> > > > >
> > > > >  static void sse2_test (void);
> > > > >
> > > > > @@ -15,13 +13,8 @@ do_test (void)  int  main ()  {
> > > > > -  unsigned int eax, ebx, ecx, edx;
> > > > > -
> > > > > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > > > > -    return 0;
> > > > > -
> > > > > -  /* Run SSE2 test only if host has SSE2 support.  */
> > > > > -  if ((edx & bit_SSE2) && sse_os_support ())
> > > > > +  /* Check cpu support for SSE2.  */  if
> > > > > + (__builtin_cpu_supports ("sse2"))
> > > > >      do_test ();
> > > > >
> > > > >    return 0;
> > > > > diff --git a/gcc/testsuite/gcc.target/i386/sse3-check.h
> > > > > b/gcc/testsuite/gcc.target/i386/sse3-check.h
> > > > > index 5a0a0b1a02e..3c58361e925 100644
> > > > > --- a/gcc/testsuite/gcc.target/i386/sse3-check.h
> > > > > +++ b/gcc/testsuite/gcc.target/i386/sse3-check.h
> > > > > @@ -1,7 +1,5 @@
> > > > >  #include <stdio.h>
> > > > >  #include <stdlib.h>
> > > > > -#include "cpuid.h"
> > > > > -#include "sse-os-support.h"
> > > > >
> > > > >  static void sse3_test (void);
> > > > >
> > > > > @@ -15,13 +13,8 @@ do_test (void)  int  main ()  {
> > > > > -  unsigned int eax, ebx, ecx, edx;
> > > > > -
> > > > > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > > > > -    return 0;
> > > > > -
> > > > > -  /* Run SSE3 test only if host has SSE3 support.  */
> > > > > -  if ((ecx & bit_SSE3) && sse_os_support ())
> > > > > +  /* Check cpu support for SSE3.  */  if
> > > > > + (__builtin_cpu_supports ("sse3"))
> > > > >      do_test ();
> > > > >
> > > > >    return 0;
> > > > > diff --git a/gcc/testsuite/gcc.target/i386/sse4_1-check.h
> > > > > b/gcc/testsuite/gcc.target/i386/sse4_1-check.h
> > > > > index 788f65d61cb..61d0d0284a8 100644
> > > > > --- a/gcc/testsuite/gcc.target/i386/sse4_1-check.h
> > > > > +++ b/gcc/testsuite/gcc.target/i386/sse4_1-check.h
> > > > > @@ -1,6 +1,4 @@
> > > > >  #include <stdlib.h>
> > > > > -
> > > > > -#include "cpuid.h"
> > > > >  #include "m128-check.h"
> > > > >
> > > > >  static void sse4_1_test (void); @@ -17,13 +15,8 @@ do_test
> > > > > (void)  int  main ()  {
> > > > > -  unsigned int eax, ebx, ecx, edx;
> > > > > -
> > > > > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > > > > -    return 0;
> > > > > -
> > > > > -  /* Run SSE4.1 test only if host has SSE4.1 support.  */
> > > > > -  if (ecx & bit_SSE4_1)
> > > > > +  /* Check cpu support for SSE4.1.  */  if
> > > > > + (__builtin_cpu_supports ("sse4.1"))
> > > > >      do_test ();
> > > > >
> > > > >    return 0;
> > > > > diff --git a/gcc/testsuite/gcc.target/i386/sse4_2-check.h
> > > > > b/gcc/testsuite/gcc.target/i386/sse4_2-check.h
> > > > > index c33cd1b4986..6c921ac52c7 100644
> > > > > --- a/gcc/testsuite/gcc.target/i386/sse4_2-check.h
> > > > > +++ b/gcc/testsuite/gcc.target/i386/sse4_2-check.h
> > > > > @@ -1,8 +1,6 @@
> > > > >  #include <stdio.h>
> > > > >  #include <stdlib.h>
> > > > > -
> > > > >  #include "m128-check.h"
> > > > > -#include "cpuid.h"
> > > > >
> > > > >  static void sse4_2_test (void);
> > > > >
> > > > > @@ -16,13 +14,8 @@ do_test (void)  int  main ()  {
> > > > > -  unsigned int eax, ebx, ecx, edx;
> > > > > -
> > > > > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > > > > -    return 0;
> > > > > -
> > > > > -  /* Run SSE4.2 test only if host has SSE4.2 support.  */
> > > > > -  if (ecx & bit_SSE4_2)
> > > > > +  /* Check cpu support for SSE4.2.  */  if
> > > > > + (__builtin_cpu_supports ("sse4.2"))
> > > > >      do_test ();
> > > > >
> > > > >    return 0;
> > > > > diff --git a/gcc/testsuite/gcc.target/i386/sse4a-check.h
> > > > > b/gcc/testsuite/gcc.target/i386/sse4a-check.h
> > > > > index d43b4b222b1..ae70ff0a268 100644
> > > > > --- a/gcc/testsuite/gcc.target/i386/sse4a-check.h
> > > > > +++ b/gcc/testsuite/gcc.target/i386/sse4a-check.h
> > > > > @@ -1,8 +1,6 @@
> > > > >  #include <stdio.h>
> > > > >  #include <stdlib.h>
> > > > >
> > > > > -#include "cpuid.h"
> > > > > -
> > > > >  static void sse4a_test (void);
> > > > >
> > > > >  static void
> > > > > @@ -15,13 +13,8 @@ do_test (void)  int  main ()  {
> > > > > -  unsigned int eax, ebx, ecx, edx;
> > > > > -
> > > > > -  if (!__get_cpuid (0x80000001, &eax, &ebx, &ecx, &edx))
> > > > > -    return 0;
> > > > > -
> > > > > -  /* Run SSE4a test only if host has SSE4a support.  */
> > > > > -  if (ecx & bit_SSE4a)
> > > > > +  /* Check cpu support for SSE4a.  */  if
> > > > > + (__builtin_cpu_supports ("sse4a"))
> > > > >      do_test ();
> > > > >
> > > > >    return 0;
> > > > > diff --git a/gcc/testsuite/gcc.target/i386/ssse3-check.h
> > > > > b/gcc/testsuite/gcc.target/i386/ssse3-check.h
> > > > > index 3ca79333c7f..3e834811f2d 100644
> > > > > --- a/gcc/testsuite/gcc.target/i386/ssse3-check.h
> > > > > +++ b/gcc/testsuite/gcc.target/i386/ssse3-check.h
> > > > > @@ -1,8 +1,6 @@
> > > > >  #include <stdio.h>
> > > > >  #include <stdlib.h>
> > > > >
> > > > > -#include "cpuid.h"
> > > > > -
> > > > >  static void ssse3_test (void);
> > > > >
> > > > >  static void
> > > > > @@ -15,13 +13,8 @@ do_test (void)  int  main ()  {
> > > > > -  unsigned int eax, ebx, ecx, edx;
> > > > > -
> > > > > -  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
> > > > > -    return 0;
> > > > > -
> > > > > -  /* Run SSSE3 test only if host has SSSE3 support.  */
> > > > > -  if (ecx & bit_SSSE3)
> > > > > +  /* Check cpu support for SSSE3.  */  if
> > > > > + (__builtin_cpu_supports ("ssse3"))
> > > > >      do_test ();
> > > > >
> > > > >    return 0;
> > > > > diff --git a/gcc/testsuite/gcc.target/i386/xop-check.h
> > > > > b/gcc/testsuite/gcc.target/i386/xop-check.h
> > > > > index 395abe8766d..e1ef1273111 100644
> > > > > --- a/gcc/testsuite/gcc.target/i386/xop-check.h
> > > > > +++ b/gcc/testsuite/gcc.target/i386/xop-check.h
> > > > > @@ -1,6 +1,4 @@
> > > > >  #include <stdlib.h>
> > > > > -
> > > > > -#include "cpuid.h"
> > > > >  #include "m256-check.h"
> > > > >
> > > > >  static void xop_test (void);
> > > > > @@ -15,13 +13,8 @@ do_test (void)  int  main ()  {
> > > > > -  unsigned int eax, ebx, ecx, edx;
> > > > > -
> > > > > -  if (!__get_cpuid (0x80000001, &eax, &ebx, &ecx, &edx))
> > > > > -    return 0;
> > > > > -
> > > > > -  /* Run XOP test only if host has XOP support.  */
> > > > > -  if (ecx & bit_XOP)
> > > > > +  /* Check cpu support for XOP.  */  if (__builtin_cpu_supports
> > > > > + ("xop"))
> > > > >      do_test ();
> > > > >
> > > > >    return 0;
> > > > > --
> > > > > 2.18.1
> > > > >
diff mbox series

Patch

diff --git a/gcc/testsuite/gcc.target/i386/adx-check.h b/gcc/testsuite/gcc.target/i386/adx-check.h
index cfed1a38483..bed5dcca385 100644
--- a/gcc/testsuite/gcc.target/i386/adx-check.h
+++ b/gcc/testsuite/gcc.target/i386/adx-check.h
@@ -1,5 +1,4 @@ 
 #include <stdlib.h>
-#include "cpuid.h"
 
 static void adx_test (void);
 
@@ -11,13 +10,8 @@  static void __attribute__ ((noinline)) do_test (void)
 int
 main ()
 {
-  unsigned int eax, ebx, ecx, edx;
-
-  if (!__get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx))
-    return 0;
-
-  /* Run ADX test only if host has ADX support.  */
-  if (ebx & bit_ADX)
+  /* Check cpu support for ADX.  */
+  if (__builtin_cpu_supports ("adx"))
     {
       do_test ();
 #ifdef DEBUG
diff --git a/gcc/testsuite/gcc.target/i386/aes-avx-check.h b/gcc/testsuite/gcc.target/i386/aes-avx-check.h
index f2a4ead4014..74bf597ead4 100644
--- a/gcc/testsuite/gcc.target/i386/aes-avx-check.h
+++ b/gcc/testsuite/gcc.target/i386/aes-avx-check.h
@@ -2,8 +2,6 @@ 
 #include <stdio.h>
 #endif
 #include <stdlib.h>
-#include "cpuid.h"
-#include "avx-os-support.h"
 
 static void aes_avx_test (void);
 
@@ -17,15 +15,9 @@  do_test (void)
 int
 main ()
 {
-  unsigned int eax, ebx, ecx, edx;
- 
-  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
-    return 0;
-
-  /* Run AES + AVX test only if host has AES + AVX support.  */
-  if (((ecx & (bit_AVX | bit_OSXSAVE | bit_AES))
-       == (bit_AVX | bit_OSXSAVE | bit_AES))
-      && avx_os_support ())
+  /* Check cpu support for AES and AVX.  */
+  if (__builtin_cpu_supports ("avx")
+      && __builtin_cpu_supports ("aes"))
     {
       do_test ();
 #ifdef DEBUG
diff --git a/gcc/testsuite/gcc.target/i386/aes-check.h b/gcc/testsuite/gcc.target/i386/aes-check.h
index 7e794423e47..7c3a3b324a7 100644
--- a/gcc/testsuite/gcc.target/i386/aes-check.h
+++ b/gcc/testsuite/gcc.target/i386/aes-check.h
@@ -1,8 +1,6 @@ 
 #include <stdio.h>
 #include <stdlib.h>
 
-#include "cpuid.h"
-
 static void aes_test (void);
 
 static void
@@ -15,13 +13,8 @@  do_test (void)
 int
 main ()
 {
-  unsigned int eax, ebx, ecx, edx;
- 
-  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
-    return 0;
-
-  /* Run AES test only if host has AES support.  */
-  if (ecx & bit_AES)
+  /* Check cpu support for AES.  */
+  if (__builtin_cpu_supports ("aes"))
     {
       do_test ();
 #ifdef DEBUG
diff --git a/gcc/testsuite/gcc.target/i386/avx-check.h b/gcc/testsuite/gcc.target/i386/avx-check.h
index 7ddca9d7b80..4a3dbc257bc 100644
--- a/gcc/testsuite/gcc.target/i386/avx-check.h
+++ b/gcc/testsuite/gcc.target/i386/avx-check.h
@@ -1,7 +1,5 @@ 
 #include <stdlib.h>
-#include "cpuid.h"
 #include "m256-check.h"
-#include "avx-os-support.h"
 
 static void avx_test (void);
 
@@ -15,14 +13,8 @@  do_test (void)
 int
 main ()
 {
-  unsigned int eax, ebx, ecx, edx;
- 
-  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
-    return 0;
-
-  /* Run AVX test only if host has AVX support.  */
-  if (((ecx & (bit_AVX | bit_OSXSAVE)) == (bit_AVX | bit_OSXSAVE))
-      && avx_os_support ())
+  /* Check cpu support for AVX.  */
+  if (__builtin_cpu_supports ("avx"))
     {
       do_test ();
 #ifdef DEBUG
diff --git a/gcc/testsuite/gcc.target/i386/avx2-check.h b/gcc/testsuite/gcc.target/i386/avx2-check.h
index 25bed5e0da6..2bc3c4425bb 100644
--- a/gcc/testsuite/gcc.target/i386/avx2-check.h
+++ b/gcc/testsuite/gcc.target/i386/avx2-check.h
@@ -1,7 +1,5 @@ 
 #include <stdlib.h>
-#include "cpuid.h"
 #include "m256-check.h"
-#include "avx-os-support.h"
 
 static void avx2_test (void);
 
@@ -10,25 +8,11 @@  static void __attribute__ ((noinline)) do_test (void)
   avx2_test ();
 }
 
-static int
-check_osxsave (void)
-{
-  unsigned int eax, ebx, ecx, edx;
-
-  __cpuid (1, eax, ebx, ecx, edx);
-  return (ecx & bit_OSXSAVE) != 0;
-}
-
 int
 main ()
 {
-  unsigned int eax, ebx, ecx, edx;
-
-  if (!__get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx))
-    return 0;
-
-  /* Run AVX2 test only if host has AVX2 support.  */
-  if (check_osxsave () && (ebx & bit_AVX2) && avx_os_support ())
+  /* Check cpu support for AVX2.  */
+  if (__builtin_cpu_supports ("avx2"))
     {
       do_test ();
 #ifdef DEBUG
diff --git a/gcc/testsuite/gcc.target/i386/avx512-check.h b/gcc/testsuite/gcc.target/i386/avx512-check.h
index 0ad9064f637..339c79070c9 100644
--- a/gcc/testsuite/gcc.target/i386/avx512-check.h
+++ b/gcc/testsuite/gcc.target/i386/avx512-check.h
@@ -1,7 +1,5 @@ 
 #include <stdlib.h>
-#include "cpuid.h"
 #include "m512-check.h"
-#include "avx512f-os-support.h"
 
 #ifndef DO_TEST
 #define DO_TEST do_test
@@ -25,81 +23,66 @@  do_test (void)
 }
 #endif
 
-static int
-check_osxsave (void)
-{
-  unsigned int eax, ebx, ecx, edx;
-
-  __cpuid (1, eax, ebx, ecx, edx);
-  return (ecx & bit_OSXSAVE) != 0;
-}
-
 int
 main ()
 {
-  unsigned int eax, ebx, ecx, edx;
-
-  if (!__get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx))
-    return 0;
-
-  /* Run AVX512 test only if host has ISA support.  */
-  if (check_osxsave ()
-      && (ebx & bit_AVX512F)
+  /* Check cpu support for AVX512.  */
+  if (__builtin_cpu_supports ("avx512f")
 #ifdef AVX512VL
-      && (ebx & bit_AVX512VL)
+      && __builtin_cpu_supports ("avx512vl")
 #endif
 #ifdef AVX512ER
-      && (ebx & bit_AVX512ER)
+      && __builtin_cpu_supports ("avx512er")
 #endif
 #ifdef AVX512CD
-      && (ebx & bit_AVX512CD)
+      && __builtin_cpu_supports ("avx512cd")
 #endif
 #ifdef AVX512DQ
-      && (ebx & bit_AVX512DQ)
+      && __builtin_cpu_supports ("avx512dq")
 #endif
 #ifdef AVX512BW
-      && (ebx & bit_AVX512BW)
+      && __builtin_cpu_supports ("avx512bw")
 #endif
 #ifdef AVX512IFMA
-      && (ebx & bit_AVX512IFMA)
+      && __builtin_cpu_supports ("avx512ifma")
 #endif
 #ifdef AVX512VBMI
-      && (ecx & bit_AVX512VBMI)
+      && __builtin_cpu_supports ("avx512vbmi")
 #endif
 #ifdef AVX5124FMAPS
-      && (edx & bit_AVX5124FMAPS)
+      && __builtin_cpu_supports ("avx5124fmaps")
 #endif
 #ifdef AVX5124VNNIW
-      && (edx & bit_AVX5124VNNIW)
+      && __builtin_cpu_supports ("avx5124vnniw")
 #endif
 #ifdef AVX512VPOPCNTDQ
-      && (ecx & bit_AVX512VPOPCNTDQ)
+      && __builtin_cpu_supports ("avx512vpopcntdq")
 #endif
 #ifdef AVX512BITALG
-      && (ecx & bit_AVX512BITALG)
+      && __builtin_cpu_supports ("avx512bitalg")
 #endif
 #ifdef GFNI
-      && (ecx & bit_GFNI)
+      && __builtin_cpu_supports ("gfni")
 #endif
 #ifdef AVX512VBMI2
-      && (ecx & bit_AVX512VBMI2)
+      && __builtin_cpu_supports ("avx512vbmi2")
 #endif
 #ifdef AVX512VNNI
-      && (ecx & bit_AVX512VNNI)
+      && __builtin_cpu_supports ("avx512vnni")
 #endif
 #ifdef AVX512FP16
-      && (edx & bit_AVX512FP16)
+      && __builtin_cpu_supports ("avx512fp16")
 #endif
 #ifdef VAES
-      && (ecx & bit_VAES)
+      && __builtin_cpu_supports ("vaes")
 #endif
 #ifdef VPCLMULQDQ
-      && (ecx & bit_VPCLMULQDQ)
+      && __builtin_cpu_supports ("vpclmulqdq")
 #endif
 #ifdef AVX512VP2INTERSECT
-      && (edx & bit_AVX512VP2INTERSECT)
+      && __builtin_cpu_supports ("avx512vp2intersect")
 #endif
-      && avx512f_os_support ())
+      )
     {
       DO_TEST ();
 #ifdef DEBUG
diff --git a/gcc/testsuite/gcc.target/i386/bmi-check.h b/gcc/testsuite/gcc.target/i386/bmi-check.h
index 1973f3b6468..6af0291a947 100644
--- a/gcc/testsuite/gcc.target/i386/bmi-check.h
+++ b/gcc/testsuite/gcc.target/i386/bmi-check.h
@@ -1,8 +1,6 @@ 
 #include <stdio.h>
 #include <stdlib.h>
 
-#include "cpuid.h"
-
 static void bmi_test (void);
 
 static void
@@ -15,13 +13,8 @@  do_test (void)
 int
 main ()
 {
-  unsigned int eax, ebx, ecx, edx;
-
-  if (!__get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx))
-    return 0;
-
-  /* Run BMI test only if host has BMI support.  */
-  if (ebx & bit_BMI)
+  /* Check cpu support for BMI.  */
+  if (__builtin_cpu_supports ("bmi"))
     {
       do_test ();
 #ifdef DEBUG
diff --git a/gcc/testsuite/gcc.target/i386/bmi2-check.h b/gcc/testsuite/gcc.target/i386/bmi2-check.h
index ba91ef9b780..75c4d8d9616 100644
--- a/gcc/testsuite/gcc.target/i386/bmi2-check.h
+++ b/gcc/testsuite/gcc.target/i386/bmi2-check.h
@@ -1,6 +1,5 @@ 
 #include <stdio.h>
 #include <stdlib.h>
-#include "cpuid.h"
 
 static void bmi2_test (void);
 
@@ -14,13 +13,8 @@  do_test (void)
 int
 main ()
 {
-  unsigned int eax, ebx, ecx, edx;
-
-  if (!__get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx))
-    return 0;
-
-  /* Run BMI2 test only if host has BMI2 support.  */
-  if (ebx & bit_BMI2)
+  /* Check cpu support for BMI2.  */
+  if (__builtin_cpu_supports ("bmi2"))
     {
       do_test ();
 #ifdef DEBUG
diff --git a/gcc/testsuite/gcc.target/i386/f16c-check.h b/gcc/testsuite/gcc.target/i386/f16c-check.h
index af7f32c5f4f..2cbf34ab516 100644
--- a/gcc/testsuite/gcc.target/i386/f16c-check.h
+++ b/gcc/testsuite/gcc.target/i386/f16c-check.h
@@ -1,6 +1,5 @@ 
 #include <stdlib.h>
 #include <stdio.h>
-#include "cpuid.h"
 #include "m256-check.h"
 
 static void f16c_test (void);
@@ -8,13 +7,8 @@  static void f16c_test (void);
 int
 main ()
 {
-  unsigned int eax, ebx, ecx, edx;
-
-  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
-    return 0;
-
-  /* Run F16C test only if host has F16C support.  */
-  if (ecx & bit_F16C)
+  /* Check cpu support for F16C.  */
+  if (__builtin_cpu_supports ("f16c"))
     {
       f16c_test ();
 #ifdef DEBUG
diff --git a/gcc/testsuite/gcc.target/i386/fma-check.h b/gcc/testsuite/gcc.target/i386/fma-check.h
index 8390f5088bd..6c1d3372218 100644
--- a/gcc/testsuite/gcc.target/i386/fma-check.h
+++ b/gcc/testsuite/gcc.target/i386/fma-check.h
@@ -1,7 +1,5 @@ 
 #include <stdlib.h>
 
-#include "cpuid.h"
-
 static void fma_test (void);
 
 static void __attribute__ ((noinline)) do_test (void)
@@ -12,13 +10,8 @@  static void __attribute__ ((noinline)) do_test (void)
 int
 main ()
 {
-  unsigned int eax, ebx, ecx, edx;
-
-  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
-    return 0;
-
-  /* Run FMA test only if host has FMA support.  */
-  if (ecx & bit_FMA)
+  /* Check cpu support for FMA.  */
+  if (__builtin_cpu_supports ("fma"))
     do_test ();
 
   return 0;
diff --git a/gcc/testsuite/gcc.target/i386/fma4-check.h b/gcc/testsuite/gcc.target/i386/fma4-check.h
index 33cd9628c04..2d2c2718029 100644
--- a/gcc/testsuite/gcc.target/i386/fma4-check.h
+++ b/gcc/testsuite/gcc.target/i386/fma4-check.h
@@ -1,7 +1,5 @@ 
 #include <stdlib.h>
 
-#include "cpuid.h"
-
 static void fma4_test (void);
 
 static void
@@ -14,13 +12,8 @@  do_test (void)
 int
 main ()
 {
-  unsigned int eax, ebx, ecx, edx;
- 
-  if (!__get_cpuid (0x80000001, &eax, &ebx, &ecx, &edx))
-    return 0;
-
-  /* Run FMA4 test only if host has FMA4 support.  */
-  if (ecx & bit_FMA4)
+  /* Check cpu support foe FMA4.  */
+  if (__builtin_cpu_supports ("fma4"))
     do_test ();
 
   return 0;
diff --git a/gcc/testsuite/gcc.target/i386/lzcnt-check.h b/gcc/testsuite/gcc.target/i386/lzcnt-check.h
index 8aad834d6af..824f1a3b513 100644
--- a/gcc/testsuite/gcc.target/i386/lzcnt-check.h
+++ b/gcc/testsuite/gcc.target/i386/lzcnt-check.h
@@ -1,8 +1,6 @@ 
 #include <stdio.h>
 #include <stdlib.h>
 
-#include "cpuid.h"
-
 static void lzcnt_test (void);
 
 static void
@@ -15,13 +13,8 @@  do_test (void)
 int
 main ()
 {
-  unsigned int eax, ebx, ecx, edx;
-
-  if (!__get_cpuid (0x80000001, &eax, &ebx, &ecx, &edx))
-    return 0;
-
-  /* Run LZCNT test only if host has LZCNT support.  */
-  if (ecx & bit_LZCNT)
+  /* Check cpu support for LZCNT.  */
+  if (__builtin_cpu_supports ("lzcnt"))
     {
       do_test ();
 #ifdef DEBUG
diff --git a/gcc/testsuite/gcc.target/i386/mmx-3dnow-check.h b/gcc/testsuite/gcc.target/i386/mmx-3dnow-check.h
index 4f2f7f3ac40..0ec2dca2e19 100644
--- a/gcc/testsuite/gcc.target/i386/mmx-3dnow-check.h
+++ b/gcc/testsuite/gcc.target/i386/mmx-3dnow-check.h
@@ -1,8 +1,6 @@ 
 #include <stdio.h>
 #include <stdlib.h>
 
-#include "cpuid.h"
-
 static void mmx_3dnow_test (void);
 
 static void
@@ -15,13 +13,8 @@  do_test (void)
 int
 main ()
 {
-  unsigned int eax, ebx, ecx, edx;
- 
-  if (!__get_cpuid (0x80000001, &eax, &ebx, &ecx, &edx))
-    return 0;
-
-  /* Run 3DNow! test only if host has 3DNow! support.  */
-  if (edx & bit_3DNOW)
+  /* Check cpu support for 3DNow!.  */
+  if (__builtin_cpu_supports ("3dnow"))
     do_test ();
 
   return 0;
diff --git a/gcc/testsuite/gcc.target/i386/mmx-check.h b/gcc/testsuite/gcc.target/i386/mmx-check.h
index faf9b876f38..2afe5183ba2 100644
--- a/gcc/testsuite/gcc.target/i386/mmx-check.h
+++ b/gcc/testsuite/gcc.target/i386/mmx-check.h
@@ -1,8 +1,6 @@ 
 #include <stdio.h>
 #include <stdlib.h>
 
-#include "cpuid.h"
-
 static void mmx_test (void);
 
 static void
@@ -15,13 +13,8 @@  do_test (void)
 int
 main ()
 {
-  unsigned int eax, ebx, ecx, edx;
- 
-  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
-    return 0;
-
-  /* Run MMX test only if host has MMX support.  */
-  if (edx & bit_MMX)
+  /* Check cpu support for MMX.  */
+  if (__builtin_cpu_supports ("mmx"))
     do_test ();
 
   return 0;
diff --git a/gcc/testsuite/gcc.target/i386/pclmul-avx-check.h b/gcc/testsuite/gcc.target/i386/pclmul-avx-check.h
index 5eed2e2203c..b506b3306e6 100644
--- a/gcc/testsuite/gcc.target/i386/pclmul-avx-check.h
+++ b/gcc/testsuite/gcc.target/i386/pclmul-avx-check.h
@@ -2,8 +2,6 @@ 
 #include <stdio.h>
 #endif
 #include <stdlib.h>
-#include "cpuid.h"
-#include "avx-os-support.h"
 
 static void pclmul_avx_test (void);
 
@@ -17,15 +15,9 @@  do_test (void)
 int
 main ()
 {
-  unsigned int eax, ebx, ecx, edx;
- 
-  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
-    return 0;
-
-  /* Run PCLMUL + AVX test only if host has PCLMUL + AVX support.  */
-  if (((ecx & (bit_AVX | bit_OSXSAVE | bit_PCLMUL))
-       == (bit_AVX | bit_OSXSAVE | bit_PCLMUL))
-      && avx_os_support ())
+  /* Check cpu support for PCLMUL and AVX.  */
+  if (__builtin_cpu_supports ("pclmul")
+      && __builtin_cpu_supports ("avx"))
     {
       do_test ();
 #ifdef DEBUG
diff --git a/gcc/testsuite/gcc.target/i386/pclmul-check.h b/gcc/testsuite/gcc.target/i386/pclmul-check.h
index 7526cbe2ddf..3ed1a044627 100644
--- a/gcc/testsuite/gcc.target/i386/pclmul-check.h
+++ b/gcc/testsuite/gcc.target/i386/pclmul-check.h
@@ -1,8 +1,6 @@ 
 #include <stdio.h>
 #include <stdlib.h>
 
-#include "cpuid.h"
-
 static void pclmul_test (void);
 
 static void
@@ -15,13 +13,8 @@  do_test (void)
 int
 main ()
 {
-  unsigned int eax, ebx, ecx, edx;
- 
-  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
-    return 0;
-
-  /* Run PCLMULQDQ test only if host has PCLMULQDQ support.  */
-  if (ecx & bit_PCLMUL)
+  /* Check cpu support for PCLMUL.  */
+  if (__builtin_cpu_supports ("pclmul"))
     {
       do_test ();
 #ifdef DEBUG
diff --git a/gcc/testsuite/gcc.target/i386/rtm-check.h b/gcc/testsuite/gcc.target/i386/rtm-check.h
index bdb5a6dc0bf..4121e602a7f 100644
--- a/gcc/testsuite/gcc.target/i386/rtm-check.h
+++ b/gcc/testsuite/gcc.target/i386/rtm-check.h
@@ -1,5 +1,4 @@ 
 #include <stdlib.h>
-#include "cpuid.h"
 
 static void rtm_test (void);
 
@@ -11,13 +10,8 @@  static void __attribute__ ((noinline)) do_test (void)
 int
 main ()
 {
-  unsigned int eax, ebx, ecx, edx;
-
-  if (!__get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx))
-    return 0;
-
-  /* Run RTM test only if host has RTM support.  */
-  if (ebx & bit_RTM)
+  /* Check cpu support for RTM.  */
+  if (__builtin_cpu_supports ("rtm"))
     {
       do_test ();
 #ifdef DEBUG
diff --git a/gcc/testsuite/gcc.target/i386/sha-check.h b/gcc/testsuite/gcc.target/i386/sha-check.h
index 5bc5a59ab80..61ce43053f9 100644
--- a/gcc/testsuite/gcc.target/i386/sha-check.h
+++ b/gcc/testsuite/gcc.target/i386/sha-check.h
@@ -1,5 +1,4 @@ 
 #include <stdlib.h>
-#include "cpuid.h"
 
 static void sha_test (void);
 
@@ -13,13 +12,8 @@  do_test (void)
 int
 main ()
 {
-  unsigned int eax, ebx, ecx, edx;
-
-  if (!__get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx))
-    return 0;
-
-  /* Run SHA test only if host has SHA support.  */
-  if (ebx & bit_SHA)
+  /* Check cpu support for SHA.  */
+  if (__builtin_cpu_supports ("sha"))
     {
       do_test ();
 #ifdef DEBUG
diff --git a/gcc/testsuite/gcc.target/i386/sse-check.h b/gcc/testsuite/gcc.target/i386/sse-check.h
index 11b71bc3e97..58bc88c5598 100644
--- a/gcc/testsuite/gcc.target/i386/sse-check.h
+++ b/gcc/testsuite/gcc.target/i386/sse-check.h
@@ -1,7 +1,5 @@ 
 #include <stdlib.h>
 #include "m128-check.h"
-#include "cpuid.h"
-#include "sse-os-support.h"
 
 static void sse_test (void);
 
@@ -15,13 +13,8 @@  do_test (void)
 int
 main ()
 {
-  unsigned int eax, ebx, ecx, edx;
- 
-  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
-    return 0;
-
-  /* Run SSE test only if host has SSE support.  */
-  if ((edx & bit_SSE) && sse_os_support ())
+  /* Check cpu support for SSE.  */
+  if (__builtin_cpu_supports ("sse"))
     do_test ();
 
   return 0;
diff --git a/gcc/testsuite/gcc.target/i386/sse2-check.h b/gcc/testsuite/gcc.target/i386/sse2-check.h
index fd4a6ce1dbf..4976a27022d 100644
--- a/gcc/testsuite/gcc.target/i386/sse2-check.h
+++ b/gcc/testsuite/gcc.target/i386/sse2-check.h
@@ -1,7 +1,5 @@ 
 #include <stdlib.h>
-#include "cpuid.h"
 #include "m128-check.h"
-#include "sse-os-support.h"
 
 static void sse2_test (void);
 
@@ -15,13 +13,8 @@  do_test (void)
 int
 main ()
 {
-  unsigned int eax, ebx, ecx, edx;
- 
-  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
-    return 0;
-
-  /* Run SSE2 test only if host has SSE2 support.  */
-  if ((edx & bit_SSE2) && sse_os_support ())
+  /* Check cpu support for SSE2.  */
+  if (__builtin_cpu_supports ("sse2"))
     do_test ();
 
   return 0;
diff --git a/gcc/testsuite/gcc.target/i386/sse3-check.h b/gcc/testsuite/gcc.target/i386/sse3-check.h
index 5a0a0b1a02e..3c58361e925 100644
--- a/gcc/testsuite/gcc.target/i386/sse3-check.h
+++ b/gcc/testsuite/gcc.target/i386/sse3-check.h
@@ -1,7 +1,5 @@ 
 #include <stdio.h>
 #include <stdlib.h>
-#include "cpuid.h"
-#include "sse-os-support.h"
 
 static void sse3_test (void);
 
@@ -15,13 +13,8 @@  do_test (void)
 int
 main ()
 {
-  unsigned int eax, ebx, ecx, edx;
- 
-  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
-    return 0;
- 
-  /* Run SSE3 test only if host has SSE3 support.  */
-  if ((ecx & bit_SSE3) && sse_os_support ())
+  /* Check cpu support for SSE3.  */
+  if (__builtin_cpu_supports ("sse3"))
     do_test ();
 
   return 0;
diff --git a/gcc/testsuite/gcc.target/i386/sse4_1-check.h b/gcc/testsuite/gcc.target/i386/sse4_1-check.h
index 788f65d61cb..61d0d0284a8 100644
--- a/gcc/testsuite/gcc.target/i386/sse4_1-check.h
+++ b/gcc/testsuite/gcc.target/i386/sse4_1-check.h
@@ -1,6 +1,4 @@ 
 #include <stdlib.h>
-
-#include "cpuid.h"
 #include "m128-check.h"
 
 static void sse4_1_test (void);
@@ -17,13 +15,8 @@  do_test (void)
 int
 main ()
 {
-  unsigned int eax, ebx, ecx, edx;
- 
-  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
-    return 0;
-
-  /* Run SSE4.1 test only if host has SSE4.1 support.  */
-  if (ecx & bit_SSE4_1)
+  /* Check cpu support for SSE4.1.  */
+  if (__builtin_cpu_supports ("sse4.1"))
     do_test ();
 
   return 0;
diff --git a/gcc/testsuite/gcc.target/i386/sse4_2-check.h b/gcc/testsuite/gcc.target/i386/sse4_2-check.h
index c33cd1b4986..6c921ac52c7 100644
--- a/gcc/testsuite/gcc.target/i386/sse4_2-check.h
+++ b/gcc/testsuite/gcc.target/i386/sse4_2-check.h
@@ -1,8 +1,6 @@ 
 #include <stdio.h>
 #include <stdlib.h>
-
 #include "m128-check.h"
-#include "cpuid.h"
 
 static void sse4_2_test (void);
 
@@ -16,13 +14,8 @@  do_test (void)
 int
 main ()
 {
-  unsigned int eax, ebx, ecx, edx;
- 
-  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
-    return 0;
-
-  /* Run SSE4.2 test only if host has SSE4.2 support.  */
-  if (ecx & bit_SSE4_2)
+  /* Check cpu support for SSE4.2.  */
+  if (__builtin_cpu_supports ("sse4.2"))
     do_test ();
 
   return 0;
diff --git a/gcc/testsuite/gcc.target/i386/sse4a-check.h b/gcc/testsuite/gcc.target/i386/sse4a-check.h
index d43b4b222b1..ae70ff0a268 100644
--- a/gcc/testsuite/gcc.target/i386/sse4a-check.h
+++ b/gcc/testsuite/gcc.target/i386/sse4a-check.h
@@ -1,8 +1,6 @@ 
 #include <stdio.h>
 #include <stdlib.h>
 
-#include "cpuid.h"
-
 static void sse4a_test (void);
 
 static void
@@ -15,13 +13,8 @@  do_test (void)
 int
 main ()
 {
-  unsigned int eax, ebx, ecx, edx;
- 
-  if (!__get_cpuid (0x80000001, &eax, &ebx, &ecx, &edx))
-    return 0;
-
-  /* Run SSE4a test only if host has SSE4a support.  */
-  if (ecx & bit_SSE4a)
+  /* Check cpu support for SSE4a.  */
+  if (__builtin_cpu_supports ("sse4a"))
     do_test ();
 
   return 0;
diff --git a/gcc/testsuite/gcc.target/i386/ssse3-check.h b/gcc/testsuite/gcc.target/i386/ssse3-check.h
index 3ca79333c7f..3e834811f2d 100644
--- a/gcc/testsuite/gcc.target/i386/ssse3-check.h
+++ b/gcc/testsuite/gcc.target/i386/ssse3-check.h
@@ -1,8 +1,6 @@ 
 #include <stdio.h>
 #include <stdlib.h>
 
-#include "cpuid.h"
-
 static void ssse3_test (void);
 
 static void
@@ -15,13 +13,8 @@  do_test (void)
 int
 main ()
 {
-  unsigned int eax, ebx, ecx, edx;
- 
-  if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
-    return 0;
-
-  /* Run SSSE3 test only if host has SSSE3 support.  */
-  if (ecx & bit_SSSE3)
+  /* Check cpu support for SSSE3.  */
+  if (__builtin_cpu_supports ("ssse3"))
     do_test ();
 
   return 0;
diff --git a/gcc/testsuite/gcc.target/i386/xop-check.h b/gcc/testsuite/gcc.target/i386/xop-check.h
index 395abe8766d..e1ef1273111 100644
--- a/gcc/testsuite/gcc.target/i386/xop-check.h
+++ b/gcc/testsuite/gcc.target/i386/xop-check.h
@@ -1,6 +1,4 @@ 
 #include <stdlib.h>
-
-#include "cpuid.h"
 #include "m256-check.h"
 
 static void xop_test (void);
@@ -15,13 +13,8 @@  do_test (void)
 int
 main ()
 {
-  unsigned int eax, ebx, ecx, edx;
- 
-  if (!__get_cpuid (0x80000001, &eax, &ebx, &ecx, &edx))
-    return 0;
-
-  /* Run XOP test only if host has XOP support.  */
-  if (ecx & bit_XOP)
+  /* Check cpu support for XOP.  */
+  if (__builtin_cpu_supports ("xop"))
     do_test ();
 
   return 0;