Severin Gehwolf eac7e3e
# HG changeset patch
Severin Gehwolf eac7e3e
# User sgehwolf
Severin Gehwolf eac7e3e
# Date 1536142767 -7200
Severin Gehwolf eac7e3e
#      Wed Sep 05 12:19:27 2018 +0200
Severin Gehwolf eac7e3e
# Node ID 7ea57274e55054579d1532e757edb21e67beed83
Severin Gehwolf eac7e3e
# Parent  3ee91722550680c18b977f0e00b1013323b5c9ef
Severin Gehwolf eac7e3e
8210416: [linux] Poor StrictMath performance due to non-optimized compilation
Severin Gehwolf eac7e3e
Summary: Compile fdlibm with -O2 -ffp-contract=off on gcc/clang arches.
Severin Gehwolf eac7e3e
Reviewed-by: aph, erikj, dholmes, darcy
Severin Gehwolf eac7e3e
Severin Gehwolf eac7e3e
diff --git a/make/autoconf/flags-cflags.m4 b/make/autoconf/flags-cflags.m4
Severin Gehwolf eac7e3e
--- a/make/autoconf/flags-cflags.m4
Severin Gehwolf eac7e3e
+++ b/make/autoconf/flags-cflags.m4
Severin Gehwolf eac7e3e
@@ -373,6 +373,18 @@
Severin Gehwolf eac7e3e
 
Severin Gehwolf eac7e3e
   FLAGS_SETUP_CFLAGS_CPU_DEP([BUILD], [OPENJDK_BUILD_])
Severin Gehwolf eac7e3e
 
Severin Gehwolf eac7e3e
+  COMPILER_FP_CONTRACT_OFF_FLAG="-ffp-contract=off"
Severin Gehwolf eac7e3e
+  # Check that the compiler supports -ffp-contract=off flag
Severin Gehwolf eac7e3e
+  # Set FDLIBM_CFLAGS to -ffp-contract=off if it does. Empty
Severin Gehwolf eac7e3e
+  # otherwise.
Severin Gehwolf eac7e3e
+  # These flags are required for GCC-based builds of
Severin Gehwolf eac7e3e
+  # fdlibm with optimization without losing precision.
Severin Gehwolf eac7e3e
+  # Notably, -ffp-contract=off needs to be added for GCC >= 4.6.
Severin Gehwolf eac7e3e
+  FLAGS_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [${COMPILER_FP_CONTRACT_OFF_FLAG}],
Severin Gehwolf eac7e3e
+      IF_TRUE: [FDLIBM_CFLAGS=${COMPILER_FP_CONTRACT_OFF_FLAG}],
Severin Gehwolf eac7e3e
+      IF_FALSE: [FDLIBM_CFLAGS=""])
Severin Gehwolf eac7e3e
+  AC_SUBST(FDLIBM_CFLAGS)
Severin Gehwolf eac7e3e
+
Severin Gehwolf eac7e3e
   # Tests are only ever compiled for TARGET
Severin Gehwolf eac7e3e
   CFLAGS_TESTLIB="$CFLAGS_JDKLIB"
Severin Gehwolf eac7e3e
   CXXFLAGS_TESTLIB="$CXXFLAGS_JDKLIB"
Severin Gehwolf eac7e3e
diff --git a/make/autoconf/spec.gmk.in b/make/autoconf/spec.gmk.in
Severin Gehwolf eac7e3e
--- a/make/autoconf/spec.gmk.in
Severin Gehwolf eac7e3e
+++ b/make/autoconf/spec.gmk.in
Severin Gehwolf eac7e3e
@@ -450,6 +450,7 @@
Severin Gehwolf eac7e3e
 LIBJSIG_HASHSTYLE_LDFLAGS := @LIBJSIG_HASHSTYLE_LDFLAGS@
Severin Gehwolf eac7e3e
 LIBJSIG_NOEXECSTACK_LDFLAGS := @LIBJSIG_NOEXECSTACK_LDFLAGS@
Severin Gehwolf eac7e3e
 
Severin Gehwolf eac7e3e
+FDLIBM_CFLAGS := @FDLIBM_CFLAGS@
Severin Gehwolf eac7e3e
 JVM_CFLAGS := @JVM_CFLAGS@
Severin Gehwolf eac7e3e
 JVM_LDFLAGS := @JVM_LDFLAGS@
Severin Gehwolf eac7e3e
 JVM_ASFLAGS := @JVM_ASFLAGS@
Severin Gehwolf eac7e3e
diff --git a/make/lib/CoreLibraries.gmk b/make/lib/CoreLibraries.gmk
Severin Gehwolf eac7e3e
--- a/make/lib/CoreLibraries.gmk
Severin Gehwolf eac7e3e
+++ b/make/lib/CoreLibraries.gmk
Severin Gehwolf eac7e3e
@@ -39,20 +39,15 @@
Severin Gehwolf eac7e3e
   BUILD_LIBFDLIBM_OPTIMIZATION := HIGH
Severin Gehwolf eac7e3e
 endif
Severin Gehwolf eac7e3e
 
Severin Gehwolf eac7e3e
-ifeq ($(OPENJDK_TARGET_OS), linux)
Severin Gehwolf eac7e3e
-  ifeq ($(OPENJDK_TARGET_CPU), ppc64)
Severin Gehwolf eac7e3e
-    BUILD_LIBFDLIBM_OPTIMIZATION := HIGH
Severin Gehwolf eac7e3e
-  else ifeq ($(OPENJDK_TARGET_CPU), ppc64le)
Severin Gehwolf eac7e3e
-    BUILD_LIBFDLIBM_OPTIMIZATION := HIGH
Severin Gehwolf eac7e3e
-  else ifeq ($(OPENJDK_TARGET_CPU), s390x)
Severin Gehwolf eac7e3e
-    BUILD_LIBFDLIBM_OPTIMIZATION := HIGH
Severin Gehwolf eac7e3e
-  else ifeq ($(OPENJDK_TARGET_CPU), aarch64)
Severin Gehwolf eac7e3e
-    BUILD_LIBFDLIBM_OPTIMIZATION := HIGH
Severin Gehwolf eac7e3e
-  endif
Severin Gehwolf eac7e3e
+# If FDLIBM_CFLAGS is non-empty we know that we can optimize
Severin Gehwolf eac7e3e
+# fdlibm by adding those extra C flags. Currently GCC,
Severin Gehwolf eac7e3e
+# and clang only.
Severin Gehwolf eac7e3e
+ifneq ($(FDLIBM_CFLAGS), )
Severin Gehwolf eac7e3e
+  BUILD_LIBFDLIBM_OPTIMIZATION := LOW
Severin Gehwolf eac7e3e
 endif
Severin Gehwolf eac7e3e
 
Severin Gehwolf eac7e3e
 LIBFDLIBM_SRC := $(TOPDIR)/src/java.base/share/native/libfdlibm
Severin Gehwolf eac7e3e
-LIBFDLIBM_CFLAGS := -I$(LIBFDLIBM_SRC)
Severin Gehwolf eac7e3e
+LIBFDLIBM_CFLAGS := -I$(LIBFDLIBM_SRC) $(FDLIBM_CFLAGS)
Severin Gehwolf eac7e3e
 
Severin Gehwolf eac7e3e
 ifneq ($(OPENJDK_TARGET_OS), macosx)
Severin Gehwolf eac7e3e
   $(eval $(call SetupNativeCompilation, BUILD_LIBFDLIBM, \
Severin Gehwolf eac7e3e
@@ -64,10 +59,6 @@
Severin Gehwolf eac7e3e
       CFLAGS := $(CFLAGS_JDKLIB) $(LIBFDLIBM_CFLAGS), \
Severin Gehwolf eac7e3e
       CFLAGS_windows_debug := -DLOGGING, \
Severin Gehwolf eac7e3e
       CFLAGS_aix := -qfloat=nomaf, \
Severin Gehwolf eac7e3e
-      CFLAGS_linux_ppc64 := -ffp-contract=off, \
Severin Gehwolf eac7e3e
-      CFLAGS_linux_ppc64le := -ffp-contract=off, \
Severin Gehwolf eac7e3e
-      CFLAGS_linux_s390x := -ffp-contract=off, \
Severin Gehwolf eac7e3e
-      CFLAGS_linux_aarch64 := -ffp-contract=off, \
Severin Gehwolf eac7e3e
       DISABLED_WARNINGS_gcc := sign-compare misleading-indentation, \
Severin Gehwolf eac7e3e
       DISABLED_WARNINGS_microsoft := 4146 4244 4018, \
Severin Gehwolf eac7e3e
       ARFLAGS := $(ARFLAGS), \