https://gcc.gnu.org/g:549ec717abb79c26186af06e01c937b4613c79ba

commit r17-4497-g549ec717abb79c26186af06e01c937b4613c79ba
Author: Iain Sandoe <[email protected]>
Date:   Mon Sep 14 09:24:04 2026 +0100

    testsuite, x86, Darwin: Read avx512 availability from the kernel.
    
    Darwin enables the avx512 XSAVE state lazily; reading XCR0 is not
    reliable - query the kernel instead.
    
    gcc/testsuite/ChangeLog:
    
            * lib/target-supports.exp (check_avx512_os_support_available):
            Query the kernel for avx512 availability on Darwin.
    
    Signed-off-by: Iain Sandoe <[email protected]>

Diff:
---
 gcc/testsuite/lib/target-supports.exp | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/gcc/testsuite/lib/target-supports.exp 
b/gcc/testsuite/lib/target-supports.exp
index cbd39301a8bd..5eb44cb3ee42 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -2896,6 +2896,20 @@ proc check_avx512_os_support_available { } {
        } else {
            # Check that OS has AVX512, AVX and SSE saving enabled.
            check_runtime_nocache avx512_os_support_available {
+               #ifdef __APPLE__
+               #include <sys/sysctl.h>
+               int main ()
+               {
+                 int val = 0;
+                 size_t len = sizeof (val);
+                 /* Darwin enables the avx512 XSAVE state lazily; reading XCR0
+                    is not reliable - query the kernel instead.  */
+                 if (sysctlbyname ("hw.optional.avx512f", &val, &len, 0, 0)
+                     != 0 || val == 0)
+                   return 1;
+                 return 0;
+               }
+               #else
                int main ()
                {
                  unsigned int eax, edx;
@@ -2903,6 +2917,7 @@ proc check_avx512_os_support_available { } {
                  asm ("xgetbv" : "=a" (eax), "=d" (edx) : "c" (0));
                  return (eax & 0xe6) != 0xe6;
                }
+               #endif
            } ""
        }
     }]

Reply via email to