]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
x86-64: Exclude FMA4 IFUNC functions for -mapxf
authorH.J. Lu <hjl.tools@gmail.com>
Thu, 4 Apr 2024 22:43:50 +0000 (15:43 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Sat, 6 Apr 2024 12:03:55 +0000 (05:03 -0700)
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>
config.h.in
sysdeps/x86_64/configure
sysdeps/x86_64/configure.ac
sysdeps/x86_64/fpu/multiarch/Makefile
sysdeps/x86_64/fpu/multiarch/ifunc-avx-fma4.h
sysdeps/x86_64/fpu/multiarch/ifunc-fma4.h

index cf4212f5ebbe64e2685320cc8902730352f4c8f1..fd1499e9e282aa725eb94f0781d2637c8355d7b6 100644 (file)
 /* 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
index 04a534fa126a7bf77f6086576bb5d45a5c57c0cc..07bdd40a37247c7bd978e39ee6d6fcf62a67e7f6 100755 (executable)
@@ -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
 
index c714c47351e70390b5cf6de35d12e76ab9d87c2e..c7b68544a2c79ae548a2cf31fb31864a38660db2 100644 (file)
@@ -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])
index 6ddd50240ce33d224c1c465058b287ddc93fb2b1..cbe09d49f49581f1ea120d3dcc373c09f2cebceb 100644 (file)
@@ -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
index 7719188888fbec3866612e5d3f3efac774886d91..d126cf9cd5ae55e40ad3d684b3f5b37ba7ada5f8 100644 (file)
@@ -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);
index c35ba13845b7914b61b59df2d49813192c49dfdd..18d372d25cb598f2e985616de60699d668c6bda9 100644 (file)
@@ -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);
 }