bug#64058: [PATCH] wc: Fix crashes due to incomplete AVX2 enumeration

2023-06-15 Thread Dave Hansen
On 6/13/23 21:14, Paul Eggert wrote:
> PS. Does the attached cksum.c / pclmul change fix any user-visible
> misbehavior? If so, what should we put into the NEWS file?

Yes, this patch also works for me.  Thanks!

Your news blurb from that patch looks fine to me.  The only tweak I
would suggest is adding some text that a user might actually see if they
hit this issue, like:

 'wc -l' no longer crashes with "Illegal instruction" messages on x86
 Linux kernels that disable XSAVE YMM. [bug introduced in coreutils-9.0]






bug#64058: [PATCH] wc: Fix crashes due to incomplete AVX2 enumeration

2023-06-14 Thread Pádraig Brady

On 14/06/2023 23:04, Paul Eggert wrote:

On 6/14/23 03:46, Pádraig Brady wrote:


Paul you removed the "avx" check from cksum.c. Was that intended?


No, it's a typo I introduced. Thanks for catching that. Fixed in the
first attached patch.

While looking into this I noticed a couple of other cleanups, fixed in
the other attached patches.

I installed these into coreutils on Savannah.


Changes look good.
I pushed the attached to explicitly document the cksum fix,
and cleanup a syntax-check failure.

Marking this as done.

thanks,
PádraigFrom d53190ed46a55f599800ebb2d8ddfe38205dbd24 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= 
Date: Thu, 15 Jun 2023 00:53:54 +0100
Subject: [PATCH] doc: mention cksum error fix with cpu feature checks changes

* NEWS: Mention the error message to aid those searching
for solutions to the issue, and mention cksum also
as that was confirmed to fix the error with the adjusted
cpu feature detection, as discussed at https://bugs.debian.org/1037264
* src/cksum.c: Cleanup syntax-check failure from previous commit.
---
 NEWS| 3 ++-
 src/cksum.c | 4 ++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/NEWS b/NEWS
index 3350f9871..535850549 100644
--- a/NEWS
+++ b/NEWS
@@ -29,7 +29,8 @@ GNU coreutils NEWS-*- outline -*-
   'pr --length=1 --double-space' no longer enters an infinite loop.
   [This bug was present in "the beginning".]
 
-  'wc -l' no longer crashes on x86 Linux kernels that disable XSAVE YMM.
+  'wc -l' and 'cksum' no longer crash with an "Illegal instruction" error
+  on x86 Linux kernels that disable XSAVE YMM.  This was seen on Xen VMs.
   [bug introduced in coreutils-9.0]
 
 ** Changes in behavior
diff --git a/src/cksum.c b/src/cksum.c
index 26bb29bdb..5b6a59c16 100644
--- a/src/cksum.c
+++ b/src/cksum.c
@@ -229,9 +229,9 @@ crc_sum_stream (FILE *stream, void *resstream, uintmax_t *length)
   static bool (*cksum_fp) (FILE *, uint_fast32_t *, uintmax_t *);
   if (! cksum_fp)
 cksum_fp = pclmul_supported () ? cksum_pclmul : cksum_slice8;
-#else
+# else
   bool (*cksum_fp) (FILE *, uint_fast32_t *, uintmax_t *) = cksum_slice8;
-#endif
+# endif
 
   if (! cksum_fp (stream, , _bytes))
 return -1;
-- 
2.40.1



bug#64058: [PATCH] wc: Fix crashes due to incomplete AVX2 enumeration

2023-06-14 Thread Paul Eggert

On 6/14/23 03:46, Pádraig Brady wrote:


Paul you removed the "avx" check from cksum.c. Was that intended?


No, it's a typo I introduced. Thanks for catching that. Fixed in the 
first attached patch.


While looking into this I noticed a couple of other cleanups, fixed in 
the other attached patches.


I installed these into coreutils on Savannah.From 7814596fa91a07fb2f1d0972f93f26de8a4ad547 Mon Sep 17 00:00:00 2001
From: Paul Eggert 
Date: Wed, 14 Jun 2023 14:13:35 -0700
Subject: [PATCH 1/3] cksum: fix bug in check for cksum_pclmul
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This fixes a typo in the previous patch.
Problem reported by Pádraig Brady .
* src/cksum.c (pclmul_supported): Also require AVX support
to use cksum_pclmul.
---
 src/cksum.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/cksum.c b/src/cksum.c
index 631ac3449..e935ba75c 100644
--- a/src/cksum.c
+++ b/src/cksum.c
@@ -160,7 +160,8 @@ static bool
 pclmul_supported (void)
 {
 # if USE_PCLMUL_CRC32
-  bool pclmul_enabled = 0 < __builtin_cpu_supports ("pclmul");
+  bool pclmul_enabled = (0 < __builtin_cpu_supports ("pclmul")
+ && 0 < __builtin_cpu_supports ("avx"));
 
   if (cksum_debug)
 error (0, 0, "%s",
-- 
2.40.1

From 4ac941565fc1f7c1eb7954302f2ec20435fdf34c Mon Sep 17 00:00:00 2001
From: Paul Eggert 
Date: Wed, 14 Jun 2023 14:18:42 -0700
Subject: [PATCH 2/3] =?UTF-8?q?cksum,wc:=20don=E2=80=99t=20include=20?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* src/cksum.c [!CRCTAB && USE_PCLMUL_CRC32]:
* src/wc.c [USE_AVX2_WC_LINECOUNT]:
Don’t include ; no longer needed.
---
 src/cksum.c | 4 +---
 src/wc.c| 3 ---
 2 files changed, 1 insertion(+), 6 deletions(-)

diff --git a/src/cksum.c b/src/cksum.c
index e935ba75c..352a0ba3a 100644
--- a/src/cksum.c
+++ b/src/cksum.c
@@ -141,9 +141,7 @@ main (void)
 # include "error.h"
 
 # include "cksum.h"
-# if USE_PCLMUL_CRC32
-#  include "cpuid.h"
-# else
+# if !USE_PCLMUL_CRC32
 #  define cksum_pclmul cksum_slice8
 # endif /* USE_PCLMUL_CRC32 */
 
diff --git a/src/wc.c b/src/wc.c
index 3708d0b8f..ebe83af4d 100644
--- a/src/wc.c
+++ b/src/wc.c
@@ -38,9 +38,6 @@
 #include "safe-read.h"
 #include "stat-size.h"
 #include "xbinary-io.h"
-#ifdef USE_AVX2_WC_LINECOUNT
-# include 
-#endif
 
 #if !defined iswspace && !HAVE_ISWSPACE
 # define iswspace(wc) \
-- 
2.40.1

From f780a85985f5b069ba8597aaeac49eb74864926a Mon Sep 17 00:00:00 2001
From: Paul Eggert 
Date: Wed, 14 Jun 2023 14:52:37 -0700
Subject: [PATCH 3/3] cksum,wc: clean up hw capability checking
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* src/cksum.c (cksum_pclmul) [!CRCTAB && !USE_PCLMUL_CRC32]:
Remove macro.
(cksum_fp): No longer file-scope.
(pclmul_supported): Define only if USE_PCLMUL_CRC32.
This omits the debug output "using generic hardware support"
for simplicity and consistency with wc’s output.
(crc_sum_stream) [!USE_PCLMUL_32]: No need for static function pointer.
* src/wc.c (wc_lines_p) [USE_AVX2_WC_LINECOUNT]: No longer file-scope.
(wc) [USE_AVX2_WC_LINECOUNT]: Check for avx2 support at most once,
which was surely the code’s original intent.
(wc) [!USE_AVX2_WC_LINECOUNT]: No need for static function pointer.
---
 src/cksum.c | 29 -
 src/wc.c| 14 ++
 2 files changed, 14 insertions(+), 29 deletions(-)

diff --git a/src/cksum.c b/src/cksum.c
index 352a0ba3a..26bb29bdb 100644
--- a/src/cksum.c
+++ b/src/cksum.c
@@ -141,23 +141,14 @@ main (void)
 # include "error.h"
 
 # include "cksum.h"
-# if !USE_PCLMUL_CRC32
-#  define cksum_pclmul cksum_slice8
-# endif /* USE_PCLMUL_CRC32 */
 
 /* Number of bytes to read at once.  */
 # define BUFLEN (1 << 16)
 
-
-static bool
-cksum_slice8 (FILE *fp, uint_fast32_t *crc_out, uintmax_t *length_out);
-static bool
-  (*cksum_fp)(FILE *, uint_fast32_t *, uintmax_t *);
-
+# if USE_PCLMUL_CRC32
 static bool
 pclmul_supported (void)
 {
-# if USE_PCLMUL_CRC32
   bool pclmul_enabled = (0 < __builtin_cpu_supports ("pclmul")
  && 0 < __builtin_cpu_supports ("avx"));
 
@@ -168,12 +159,8 @@ pclmul_supported (void)
 : _("pclmul support not detected")));
 
   return pclmul_enabled;
-# else
-  if (cksum_debug)
-error (0, 0, "%s", _("using generic hardware support"));
-  return false;
-# endif /* USE_PCLMUL_CRC32 */
 }
+# endif /* USE_PCLMUL_CRC32 */
 
 static bool
 cksum_slice8 (FILE *fp, uint_fast32_t *crc_out, uintmax_t *length_out)
@@ -238,13 +225,13 @@ crc_sum_stream (FILE *stream, void *resstream, uintmax_t *length)
   uintmax_t total_bytes = 0;
   uint_fast32_t crc = 0;
 
+# if USE_PCLMUL_CRC32
+  static bool (*cksum_fp) (FILE *, uint_fast32_t *, uintmax_t *);
   if (! cksum_fp)
-{
-   if (pclmul_supported ())
- cksum_fp = cksum_pclmul;
-   else
- cksum_fp = cksum_slice8;

bug#64058: [PATCH] wc: Fix crashes due to incomplete AVX2 enumeration

2023-06-14 Thread Axel Beckert
Control: tag 1037264 + patch

Hi Pádraig,

On Wed, Jun 14, 2023 at 11:46:58AM +0100, Pádraig Brady wrote:
> On 14/06/2023 05:14, Paul Eggert wrote:
> > Thanks for the bug report. I installed the attached patch into coreutils
> > on Savannah. It builds on your idea with several other changes:
> > 
> > * There's a similar issue with cksum.c and pclmul.
> > 
> > * configure.ac can be simplified, since it seems there's no point
> > compiling these instructions if __builtin_cpu_supports doesn't work.
> > 
> > * This lets us simplify the source code a bit more.
> > 
> > Please let me know if the attached patch works for you.
> 
> __builtin_cpu_supports() looks to have sufficient support in
> Arch + compiler versions for our needs, so that's good.
> 
> Paul you removed the "avx" check from cksum.c. Was that intended?
> 
> > PS. Does the attached cksum.c / pclmul change fix any user-visible
> > misbehavior? If so, what should we put into the NEWS file?
> 
> We have an illegal instruction issue with cksum under Xen DomU
> which may be related, as discussed at: https://bugs.debian.org/1037264
> 
> Axel does the attached patch change anything for you?

Yes! This patch helps! Thanks a lot! :-)

Cc'ing the Debian bug report again (and doing a nearly fullquote for
that) and tagging Debian's bug report as containing a patch. (Given
it's high bug report number it should do any harm in GNU's BTS even if
it uses the same control syntax…)

> diff --git a/src/cksum.c b/src/cksum.c
> index 85afab0ac..881d90413 100644
> --- a/src/cksum.c
> +++ b/src/cksum.c
> @@ -160,29 +160,16 @@ static bool
>  pclmul_supported (void)
>  {
>  # if USE_PCLMUL_CRC32
> -  unsigned int eax = 0;
> -  unsigned int ebx = 0;
> -  unsigned int ecx = 0;
> -  unsigned int edx = 0;
> -
> -  if (! __get_cpuid (1, , , , ))
> -{
> -  if (cksum_debug)
> -error (0, 0, "%s", _("failed to get cpuid"));
> -  return false;
> -}
> -
> -  if (! (ecx & bit_PCLMUL) || ! (ecx & bit_AVX))
> -{
> -  if (cksum_debug)
> -error (0, 0, "%s", _("pclmul support not detected"));
> -  return false;
> -}
> +  bool pclmul_enabled = 0 < __builtin_cpu_supports ("pclmul")
> +&& 0 < __builtin_cpu_supports ("avx");
>  
>if (cksum_debug)
> -error (0, 0, "%s", _("using pclmul hardware support"));
> +error (0, 0, "%s",
> +   (pclmul_enabled
> +? _("using pclmul hardware support")
> +: _("pclmul support not detected")));
>  
> -  return true;
> +  return pclmul_enabled;
>  # else
>if (cksum_debug)
>  error (0, 0, "%s", _("using generic hardware support"));

Regards, Axel
-- 
 ,''`.  |  Axel Beckert , https://people.debian.org/~abe/
: :' :  |  Debian Developer, ftp.ch.debian.org Admin
`. `'   |  4096R: 2517 B724 C5F6 CA99 5329  6E61 2FF9 CD59 6126 16B5
  `-|  1024D: F067 EA27 26B9 C3FC 1486  202E C09E 1D89 9593 0EDE





bug#64058: [PATCH] wc: Fix crashes due to incomplete AVX2 enumeration

2023-06-14 Thread Pádraig Brady

On 14/06/2023 05:14, Paul Eggert wrote:

Thanks for the bug report. I installed the attached patch into coreutils
on Savannah. It builds on your idea with several other changes:

* There's a similar issue with cksum.c and pclmul.

* configure.ac can be simplified, since it seems there's no point
compiling these instructions if __builtin_cpu_supports doesn't work.

* This lets us simplify the source code a bit more.

Please let me know if the attached patch works for you.


__builtin_cpu_supports() looks to have sufficient support in
Arch + compiler versions for our needs, so that's good.

Paul you removed the "avx" check from cksum.c. Was that intended?


PS. Does the attached cksum.c / pclmul change fix any user-visible
misbehavior? If so, what should we put into the NEWS file?


We have an illegal instruction issue with cksum under Xen DomU
which may be related, as discussed at: https://bugs.debian.org/1037264

Axel does the attached patch change anything for you?

thanks,
Pádraigdiff --git a/src/cksum.c b/src/cksum.c
index 85afab0ac..881d90413 100644
--- a/src/cksum.c
+++ b/src/cksum.c
@@ -160,29 +160,16 @@ static bool
 pclmul_supported (void)
 {
 # if USE_PCLMUL_CRC32
-  unsigned int eax = 0;
-  unsigned int ebx = 0;
-  unsigned int ecx = 0;
-  unsigned int edx = 0;
-
-  if (! __get_cpuid (1, , , , ))
-{
-  if (cksum_debug)
-error (0, 0, "%s", _("failed to get cpuid"));
-  return false;
-}
-
-  if (! (ecx & bit_PCLMUL) || ! (ecx & bit_AVX))
-{
-  if (cksum_debug)
-error (0, 0, "%s", _("pclmul support not detected"));
-  return false;
-}
+  bool pclmul_enabled = 0 < __builtin_cpu_supports ("pclmul")
+&& 0 < __builtin_cpu_supports ("avx");
 
   if (cksum_debug)
-error (0, 0, "%s", _("using pclmul hardware support"));
+error (0, 0, "%s",
+   (pclmul_enabled
+? _("using pclmul hardware support")
+: _("pclmul support not detected")));
 
-  return true;
+  return pclmul_enabled;
 # else
   if (cksum_debug)
 error (0, 0, "%s", _("using generic hardware support"));


bug#64058: [PATCH] wc: Fix crashes due to incomplete AVX2 enumeration

2023-06-13 Thread Paul Eggert
Thanks for the bug report. I installed the attached patch into coreutils 
on Savannah. It builds on your idea with several other changes:


* There's a similar issue with cksum.c and pclmul.

* configure.ac can be simplified, since it seems there's no point 
compiling these instructions if __builtin_cpu_supports doesn't work.


* This lets us simplify the source code a bit more.

Please let me know if the attached patch works for you.

PS. Does the attached cksum.c / pclmul change fix any user-visible 
misbehavior? If so, what should we put into the NEWS file?From 91a74d361461494dd546467e83bc36c24185d6e7 Mon Sep 17 00:00:00 2001
From: Paul Eggert 
Date: Tue, 13 Jun 2023 21:10:24 -0700
Subject: [PATCH] wc: port to kernels that disable XSAVE YMM

Problem reported by Dave Hansen .
Apply similar change to cksum and pclmul, too.
* NEWS: Mention wc fix.
* configure.ac (cpuid_exists, get_cpuid_count_exists):
Remove.  All uses removed, since we no longer use __get_cpuid or
__get_cpuid_count.
(pclmul_intrinsic_exists, avx2_intrinsic_exists): Set to no if
__builtin_cpu_supports calls cannot be compiled.
(HAVE_PCLMUL_INTRINSIC, HAVE_AVX2_INTRINSIC): Remove; unused.
Simplify surrounding code because of this.
* src/cksum.c (pclmul_supported):
* src/wc.c (avx2_supported):
Use __builtin_cpu_supports instead of doing it by hand.
Simplify surrounding code because of this.
---
 NEWS |  3 +++
 configure.ac | 67 
 src/cksum.c  | 26 +---
 src/wc.c | 50 +--
 4 files changed, 25 insertions(+), 121 deletions(-)

diff --git a/NEWS b/NEWS
index 7df9ff5b0..3350f9871 100644
--- a/NEWS
+++ b/NEWS
@@ -29,6 +29,9 @@ GNU coreutils NEWS-*- outline -*-
   'pr --length=1 --double-space' no longer enters an infinite loop.
   [This bug was present in "the beginning".]
 
+  'wc -l' no longer crashes on x86 Linux kernels that disable XSAVE YMM.
+  [bug introduced in coreutils-9.0]
+
 ** Changes in behavior
 
   'cp -v' and 'mv -v' will no longer output a message for each file skipped
diff --git a/configure.ac b/configure.ac
index 520de8184..48dea9d01 100644
--- a/configure.ac
+++ b/configure.ac
@@ -548,27 +548,6 @@ CFLAGS=$ac_save_CFLAGS
 LDFLAGS=$ac_save_LDFLAGS
 ac_c_werror_flag=$cu_save_c_werror_flag
 
-AC_MSG_CHECKING([if __get_cpuid available])
-AC_LINK_IFELSE(
-  [AC_LANG_SOURCE([[
-#include 
-
-int
-main (void)
-{
-  unsigned int eax, ebx, ecx, edx;
-  __get_cpuid (1, , , , );
-  return 1;
-}
-  ]])
-  ],[
-AC_MSG_RESULT([yes])
-AC_DEFINE([HAVE_CPUID], [1], [__get_cpuid available])
-cpuid_exists=yes
-  ],[
-AC_MSG_RESULT([no])
-  ])
-
 ac_save_CFLAGS=$CFLAGS
 CFLAGS="-mavx -mpclmul $CFLAGS"
 AC_MSG_CHECKING([if pclmul intrinsic exists])
@@ -582,46 +561,23 @@ AC_COMPILE_IFELSE(
   __m128i a, b;
   a = _mm_clmulepi64_si128 (a, b, 0x00);
   a = _mm_shuffle_epi8 (a, b);
-  return 1;
+  return __builtin_cpu_supports ("pclmul");
 }
   ]])
   ],[
-AC_MSG_RESULT([yes])
-AC_DEFINE([HAVE_PCLMUL_INTRINSIC], [1], [pclmul intrinsic exists])
 pclmul_intrinsic_exists=yes
   ],[
-AC_MSG_RESULT([no])
+pclmul_intrinsic_exists=no
   ])
-if test "x$cpuid_exists" = "xyes" &&
-   test "x$pclmul_intrinsic_exists" = "xyes"; then
+AC_MSG_RESULT([$pclmul_intrinsic_exists])
+if test $pclmul_intrinsic_exists = yes; then
   AC_DEFINE([USE_PCLMUL_CRC32], [1],
 [CRC32 calculation by pclmul hardware instruction enabled])
 fi
 AM_CONDITIONAL([USE_PCLMUL_CRC32],
-   [test "x$cpuid_exists" = "xyes" &&
-test "x$pclmul_intrinsic_exists" = "xyes"])
+   [test $pclmul_intrinsic_exists = yes])
 CFLAGS=$ac_save_CFLAGS
 
-AC_MSG_CHECKING([if __get_cpuid_count exists])
-AC_LINK_IFELSE(
-  [AC_LANG_SOURCE([[
-#include 
-
-int
-main (void)
-{
-  unsigned int eax = 0, ebx = 0, ecx = 0, edx = 0;
-  __get_cpuid_count (7, 0, , , , );
-  return 1;
-}
-  ]])
-  ],[
-AC_MSG_RESULT([yes])
-get_cpuid_count_exists=yes
-  ],[
-AC_MSG_RESULT([no])
-  ])
-
 CFLAGS="-mavx2 $CFLAGS"
 AC_MSG_CHECKING([if avx2 intrinstics exists])
 AC_COMPILE_IFELSE(
@@ -633,23 +589,20 @@ AC_COMPILE_IFELSE(
 {
   __m256i a, b;
   a = _mm256_sad_epu8 (a, b);
-  return 1;
+  return __builtin_cpu_supports ("avx2");
 }
   ]])
   ],[
-AC_MSG_RESULT([yes])
-AC_DEFINE([HAVE_AVX2_INTRINSIC], [1], [avx2 intrinsics exists])
 avx2_intrinsic_exists=yes
   ],[
-AC_MSG_RESULT([no])
+avx2_intrinsic_exists=no
   ])
-if test "x$get_cpuid_count_exists" = "xyes" &&
-   test "x$avx2_intrinsic_exists" = "xyes"; then
+AC_MSG_RESULT([$avx2_intrinsic_exists])
+if test $avx2_intrinsic_exists = yes; then
   AC_DEFINE([USE_AVX2_WC_LINECOUNT], [1], [Counting lines with AVX2 enabled])
 fi
 AM_CONDITIONAL([USE_AVX2_WC_LINECOUNT],
-  

bug#64058: [PATCH] wc: Fix crashes due to incomplete AVX2 enumeration

2023-06-13 Thread Dave Hansen
The AVX2 enumeration for 'wc -l' is incomplete which may cause wc to
crash.

The Intel SDM documents the whole AVX2 enumeration sequence in its
"Detection of Intel AVX2" section.  There are three pieces:
 1. Ensuring the CPU supports AVX2 instructions
 2. Ensuring the OS has enabled XSAVE
 3. Ensuring XSAVE is managing the YMM registers (XGETBV)

The existing code does #1 and #2 but misses #3.  The kernel will
enable #3 in almost all situations where AVX2 is supported, but there
are situations where the kernel might disable XSAVE YMM support but
leave FP and SSE enabled.  This is _unusual_ today, but can occur when
Linux notices XSAVE enumeration issues or in virtual machines with
odd/buggy XSAVE enumeration.

If wc is used on one of those systems in '-l' mode, it will crash:

# cat foo | ./wc.orig -l
Illegal instruction (core dumped)

Fortunately, gcc and llvm provide a builtin to check for CPU support
and AVX2 is supported.  Use the builtin instead of using CPUID
directly.  This fixes the problem and is also substantially simpler.

The result is that wc no longer crashes on systems where XSAVE YMM
support is disabled:

# cat foo | ./wc.fixed -l
30232

I've reproduced this issue in the current upstream git repo which git
describe says is v9.3-53-g378902407.

I needed to run a patched version of Linux to expose this issue.  We
(the upstream Linux x86 maintainers) are considering merging a patch
to do this in the upstream kernel.  It would be great if a wc fix was
available.
---
 src/wc.c | 36 +---
 1 file changed, 1 insertion(+), 35 deletions(-)

diff --git a/src/wc.c b/src/wc.c
index becceda98..944cfc426 100644
--- a/src/wc.c
+++ b/src/wc.c
@@ -157,41 +157,7 @@ static enum total_type total_mode = total_auto;
 static bool
 avx2_supported (void)
 {
-  unsigned int eax = 0;
-  unsigned int ebx = 0;
-  unsigned int ecx = 0;
-  unsigned int edx = 0;
-  bool getcpuid_ok = false;
-  bool avx_enabled = false;
-
-  if (__get_cpuid (1, , , , ))
-{
-  getcpuid_ok = true;
-  if (ecx & bit_OSXSAVE)
-avx_enabled = true;  /* Support is not disabled.  */
-}
-
-
-  if (avx_enabled)
-{
-  eax = ebx = ecx = edx = 0;
-  if (! __get_cpuid_count (7, 0, , , , ))
-getcpuid_ok = false;
-  else
-{
-  if (! (ebx & bit_AVX2))
-avx_enabled = false;  /* Hardware doesn't support it.  */
-}
-}
-
-
-  if (! getcpuid_ok)
-{
-  if (debug)
-error (0, 0, "%s", _("failed to get cpuid"));
-  return false;
-}
-  else if (! avx_enabled)
+  if (!__builtin_cpu_supports("avx2"))
 {
   if (debug)
 error (0, 0, "%s", _("avx2 support not detected"));
-- 
2.34.1