about summary refs log tree commit diff
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2024-04-04 15:43:50 -0700
committerH.J. Lu <hjl.tools@gmail.com>2024-04-06 05:03:55 -0700
commit9e1f4aef865ddeffeb4b5f6578fefab606783120 (patch)
tree63d8e53c89c6f2987491e177426954b0ea93a3bb
parentc27f8763cffbb7db9b3f1f5e09ef24d26cbb63f4 (diff)
downloadglibc-9e1f4aef865ddeffeb4b5f6578fefab606783120.tar.gz
glibc-9e1f4aef865ddeffeb4b5f6578fefab606783120.tar.xz
glibc-9e1f4aef865ddeffeb4b5f6578fefab606783120.zip
x86-64: Exclude FMA4 IFUNC functions for -mapxf
When -mapxf is used to build glibc, the resulting glibc will never run
on FMA4 machines.  Exclude FMA4 IFUNC functions when -mapxf is used.
This requires GCC which defines __APX_F__ for -mapxf with commit:

1df56719bd8 x86: Define __APX_F__ for -mapxf

Reviewed-by: Sunil K Pandey <skpgkp2@gmail.com>
-rw-r--r--config.h.in3
-rwxr-xr-xsysdeps/x86_64/configure32
-rw-r--r--sysdeps/x86_64/configure.ac18
-rw-r--r--sysdeps/x86_64/fpu/multiarch/Makefile22
-rw-r--r--sysdeps/x86_64/fpu/multiarch/ifunc-avx-fma4.h2
-rw-r--r--sysdeps/x86_64/fpu/multiarch/ifunc-fma4.h2
6 files changed, 70 insertions, 9 deletions
diff --git a/config.h.in b/config.h.in
index cf4212f5eb..fd1499e9e2 100644
--- a/config.h.in
+++ b/config.h.in
@@ -295,4 +295,7 @@
 /* Define if -mmovbe is enabled by default on x86.  */
 #undef HAVE_X86_MOVBE
 
+/* Define if -mapxf is enabled by default on x86.  */
+#undef HAVE_X86_APX
+
 #endif
diff --git a/sysdeps/x86_64/configure b/sysdeps/x86_64/configure
index 04a534fa12..07bdd40a37 100755
--- a/sysdeps/x86_64/configure
+++ b/sysdeps/x86_64/configure
@@ -162,6 +162,38 @@ printf "%s\n" "$libc_cv_x86_have_amx_tile" >&6; }
 config_vars="$config_vars
 have-mamx-tile = $libc_cv_x86_have_amx_tile"
 
+# Check if -mapxf is enabled.
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether -mapxf is enabled" >&5
+printf %s "checking whether -mapxf is enabled... " >&6; }
+if test ${libc_cv_x86_have_apx+y}
+then :
+  printf %s "(cached) " >&6
+else $as_nop
+  cat > conftest.c <<EOF
+#ifndef __APX_F__
+# error APX isn't enabled
+#endif
+EOF
+	       libc_cv_x86_have_apx=no
+	       if { ac_try='${CC-cc} -c $CFLAGS conftest.c -o conftest.o 1>&5'
+  { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; }; then
+		   libc_cv_x86_have_apx=yes
+	       fi
+	       rm -rf conftest*
+fi
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $libc_cv_x86_have_apx" >&5
+printf "%s\n" "$libc_cv_x86_have_apx" >&6; }
+if test $libc_cv_x86_have_apx = yes; then
+  printf "%s\n" "#define HAVE_X86_APX 1" >>confdefs.h
+
+fi
+config_vars="$config_vars
+have-x86-apx = $libc_cv_x86_have_apx"
+
 test -n "$critic_missing" && as_fn_error $? "
 *** $critic_missing" "$LINENO" 5
 
diff --git a/sysdeps/x86_64/configure.ac b/sysdeps/x86_64/configure.ac
index c714c47351..c7b68544a2 100644
--- a/sysdeps/x86_64/configure.ac
+++ b/sysdeps/x86_64/configure.ac
@@ -76,5 +76,23 @@ EOF
 	       rm -rf conftest*])
 LIBC_CONFIG_VAR([have-mamx-tile], [$libc_cv_x86_have_amx_tile])
 
+# Check if -mapxf is enabled.
+AC_CACHE_CHECK(whether -mapxf is enabled,
+	       libc_cv_x86_have_apx, [dnl
+cat > conftest.c <<EOF
+#ifndef __APX_F__
+# error APX isn't enabled
+#endif
+EOF
+	       libc_cv_x86_have_apx=no
+	       if AC_TRY_COMMAND(${CC-cc} -c $CFLAGS conftest.c -o conftest.o 1>&AS_MESSAGE_LOG_FD); then
+		   libc_cv_x86_have_apx=yes
+	       fi
+	       rm -rf conftest*])
+if test $libc_cv_x86_have_apx = yes; then
+  AC_DEFINE(HAVE_X86_APX)
+fi
+LIBC_CONFIG_VAR([have-x86-apx], [$libc_cv_x86_have_apx])
+
 test -n "$critic_missing" && AC_MSG_ERROR([
 *** $critic_missing])
diff --git a/sysdeps/x86_64/fpu/multiarch/Makefile b/sysdeps/x86_64/fpu/multiarch/Makefile
index 6ddd50240c..cbe09d49f4 100644
--- a/sysdeps/x86_64/fpu/multiarch/Makefile
+++ b/sysdeps/x86_64/fpu/multiarch/Makefile
@@ -38,29 +38,36 @@ libm-sysdep_routines += \
   s_truncf-avx \
 # libm-sysdep_routines
 else
+ifeq (no,$(have-x86-apx))
 libm-sysdep_routines += \
-  e_asin-fma \
   e_asin-fma4 \
+  e_atan2-fma4 \
+  e_exp-fma4 \
+  e_log-fma4 \
+  e_pow-fma4 \
+  s_atan-fma4 \
+  s_sin-fma4 \
+  s_sincos-fma4 \
+  s_tan-fma4 \
+# libm-sysdep_routines
+endif
+libm-sysdep_routines += \
+  e_asin-fma \
   e_atan2-avx \
   e_atan2-fma \
-  e_atan2-fma4 \
   e_exp-avx \
   e_exp-fma \
-  e_exp-fma4 \
   e_exp2f-fma \
   e_expf-fma \
   e_log-avx \
   e_log-fma \
-  e_log-fma4 \
   e_log2-fma \
   e_log2f-fma \
   e_logf-fma \
   e_pow-fma \
-  e_pow-fma4 \
   e_powf-fma \
   s_atan-avx \
   s_atan-fma \
-  s_atan-fma4 \
   s_ceil-sse4_1 \
   s_ceilf-sse4_1 \
   s_cosf-fma \
@@ -77,17 +84,14 @@ libm-sysdep_routines += \
   s_roundevenf-sse4_1 \
   s_sin-avx \
   s_sin-fma \
-  s_sin-fma4 \
   s_sincos-avx \
   s_sincos-fma \
-  s_sincos-fma4 \
   s_sincosf-fma \
   s_sincosf-sse2 \
   s_sinf-fma \
   s_sinf-sse2 \
   s_tan-avx \
   s_tan-fma \
-  s_tan-fma4 \
   s_trunc-sse4_1 \
   s_truncf-sse4_1 \
 # libm-sysdep_routines
diff --git a/sysdeps/x86_64/fpu/multiarch/ifunc-avx-fma4.h b/sysdeps/x86_64/fpu/multiarch/ifunc-avx-fma4.h
index 7719188888..d126cf9cd5 100644
--- a/sysdeps/x86_64/fpu/multiarch/ifunc-avx-fma4.h
+++ b/sysdeps/x86_64/fpu/multiarch/ifunc-avx-fma4.h
@@ -33,8 +33,10 @@ IFUNC_SELECTOR (void)
       && CPU_FEATURE_USABLE_P (cpu_features, AVX2))
     return OPTIMIZE (fma);
 
+#ifndef HAVE_X86_APX
   if (CPU_FEATURE_USABLE_P (cpu_features, FMA4))
     return OPTIMIZE (fma4);
+#endif
 
   if (CPU_FEATURE_USABLE_P (cpu_features, AVX))
     return OPTIMIZE (avx);
diff --git a/sysdeps/x86_64/fpu/multiarch/ifunc-fma4.h b/sysdeps/x86_64/fpu/multiarch/ifunc-fma4.h
index c35ba13845..18d372d25c 100644
--- a/sysdeps/x86_64/fpu/multiarch/ifunc-fma4.h
+++ b/sysdeps/x86_64/fpu/multiarch/ifunc-fma4.h
@@ -32,8 +32,10 @@ IFUNC_SELECTOR (void)
       && CPU_FEATURE_USABLE_P (cpu_features, AVX2))
     return OPTIMIZE (fma);
 
+#ifndef HAVE_X86_APX
   if (CPU_FEATURE_USABLE_P (cpu_features, FMA4))
     return OPTIMIZE (fma4);
+#endif
 
   return OPTIMIZE (sse2);
 }