From aa85e04a4150b66970331ef85edf4b29239a208a Mon Sep 17 00:00:00 2001 From: Carl Love Date: Mon, 20 Jul 2015 21:25:32 +0000 Subject: [PATCH] Patch 4 and 5 of 7, improve PPC HW capabiltiy checking. The patch was submitted by Will Schmidt (will_schmidt@vnet.ibm.com). Patches 4 and 5 need to be applied together. Add convenience function for processing hwcap entries. Add logic to check for HTM support in compiler. Bugzilla 34979 git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15423 --- configure.ac | 58 ++++++++++++++++++++++++++++++++ none/tests/ppc32/Makefile.am | 10 ++++-- none/tests/ppc64/Makefile.am | 10 ++++-- none/tests/ppc64/test_tm.c | 6 ++-- none/tests/ppc64/test_touch_tm.c | 4 ++- 5 files changed, 79 insertions(+), 9 deletions(-) diff --git a/configure.ac b/configure.ac index 60c4fec97e..deb1acd54e 100644 --- a/configure.ac +++ b/configure.ac @@ -1264,6 +1264,28 @@ AC_CHECK_MEMBER([pthread_mutex_t.__data.__kind], [], [#include ]) +# Convenience function. Set flags based on the existing HWCAP entries. +# The AT_HWCAP entries are generated by glibc, and are based on +# functions supported by the hardware/system/libc. +# Subsequent support for whether the capability will actually be utilized +# will also be checked against the compiler capabilities. +# called as +# AC_HWCAP_CONTAINS_FLAG[hwcap_string_to_match],[VARIABLE_TO_SET] +AC_DEFUN([AC_HWCAP_CONTAINS_FLAG],[ + AUXV_CHECK_FOR=$1 + AC_MSG_CHECKING([if AT_HWCAP contains the $AUXV_CHECK_FOR indicator]) + if `LD_SHOW_AUXV=1 /bin/true | grep ^AT_HWCAP | grep -q -w ${AUXV_CHECK_FOR}` + then + AC_MSG_RESULT([yes]) + AC_SUBST([$2],[yes]) + else + AC_MSG_RESULT([no]) + AC_SUBST([$2],[]) + fi +]) + +# gather hardware capabilities. (hardware/kernel/libc) +AC_HWCAP_CONTAINS_FLAG([htm],[HWCAP_HAS_HTM]) # does this compiler support -maltivec and does it have the include file # ? @@ -1386,6 +1408,42 @@ AC_MSG_RESULT([no]) AM_CONDITIONAL(HAS_ISA_2_07, test x$ac_asm_have_isa_2_07 = xyes) +# HTM (Hardware Transactional Memory) +AC_MSG_CHECKING([if compiler accepts the -mhtm flag]) +safe_CFLAGS=$CFLAGS +CFLAGS="-mhtm -Werror" +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ +]], [[ + return 0; +]])], [ +AC_MSG_RESULT([yes]) +ac_compiler_supports_htm=yes +], [ +AC_MSG_RESULT([no]) +ac_compiler_supports_htm=no +]) +CFLAGS=$safe_CFLAGS + +AC_MSG_CHECKING([if compiler can find the htm builtins]) +safe_CFLAGS=$CFLAGS +CFLAGS="-mhtm -Werror" + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ + ]], [[ + if (__builtin_tbegin (0)) + __builtin_tend (0); + ]])], [ + AC_MSG_RESULT([yes]) +ac_compiler_sees_htm_builtins=yes + ], [ + AC_MSG_RESULT([no]) +ac_compiler_sees_htm_builtins=no + ]) +CFLAGS=$safe_CFLAGS + +AM_CONDITIONAL(SUPPORTS_HTM, test x$ac_compiler_supports_htm = xyes \ + -a x$ac_compiler_sees_htm_builtins = xyes \ + -a x$HWCAP_HAS_HTM = xyes ) + # Check for pthread_create@GLIBC2.0 AC_MSG_CHECKING([for pthread_create@GLIBC2.0()]) diff --git a/none/tests/ppc32/Makefile.am b/none/tests/ppc32/Makefile.am index e66992cdf2..763846057a 100644 --- a/none/tests/ppc32/Makefile.am +++ b/none/tests/ppc32/Makefile.am @@ -99,13 +99,17 @@ DFP_FLAG = endif if HAS_ISA_2_07 -BUILD_FLAGS_ISA_2_07 = -mhtm -mcpu=power8 +BUILD_FLAGS_ISA_2_07 = -mcpu=power8 ISA_2_07_FLAG = -DHAS_ISA_2_07 else BUILD_FLAGS_ISA_2_07 = ISA_2_07_FLAG = endif +if SUPPORTS_HTM +HTM_FLAG = -mhtm -DSUPPORTS_HTM +endif + jm_insns_CFLAGS = $(AM_CFLAGS) -Winline -Wall -O -g -mregnames \ @FLAG_M32@ $(ALTIVEC_FLAG) $(BUILD_FLAG_ALTIVEC) @@ -141,9 +145,9 @@ test_isa_2_07_part1_CFLAGS = $(AM_CFLAGS) -Winline -Wall -O -g -mregnames $(ISA_ test_isa_2_07_part2_CFLAGS = $(AM_CFLAGS) -Winline -Wall -O -g -mregnames $(ISA_2_07_FLAG) \ @FLAG_M32@ $(BUILD_FLAGS_ISA_2_07) -test_tm_CFLAGS = $(AM_CFLAGS) -Winline -Wall -O -g -mregnames $(ISA_2_07_FLAG) \ +test_tm_CFLAGS = $(AM_CFLAGS) -Winline -Wall -O -g -mregnames $(HTM_FLAG) $(ISA_2_07_FLAG) \ @FLAG_M32@ $(BUILD_FLAGS_ISA_2_07) -test_touch_tm_CFLAGS = $(AM_CFLAGS) -Winline -Wall -O -g -mregnames $(ISA_2_07_FLAG) \ +test_touch_tm_CFLAGS = $(AM_CFLAGS) -Winline -Wall -O -g -mregnames $(HTM_FLAG) $(ISA_2_07_FLAG) \ @FLAG_M32@ $(BUILD_FLAGS_ISA_2_07) test_isa_2_06_part3_LDADD = -lm diff --git a/none/tests/ppc64/Makefile.am b/none/tests/ppc64/Makefile.am index d1faca665e..cc1fef42c6 100644 --- a/none/tests/ppc64/Makefile.am +++ b/none/tests/ppc64/Makefile.am @@ -75,13 +75,17 @@ DFP_FLAG = endif if HAS_ISA_2_07 -BUILD_FLAGS_ISA_2_07 = -mhtm -mcpu=power8 +BUILD_FLAGS_ISA_2_07 = -mcpu=power8 ISA_2_07_FLAG = -DHAS_ISA_2_07 else BUILD_FLAGS_ISA_2_07 = ISA_2_07_FLAG = endif +if SUPPORTS_HTM +HTM_FLAG = -mhtm -DSUPPORTS_HTM +endif + test_isa_2_06_part1_CFLAGS = $(AM_CFLAGS) -Winline -Wall -O -g -mregnames $(VSX_FLAG) \ @FLAG_M64@ $(ALTIVEC_FLAG) $(BUILD_FLAG_VSX) @@ -114,9 +118,9 @@ test_isa_2_07_part1_CFLAGS = $(AM_CFLAGS) -Winline -Wall -O -g -mregnames $(ISA_ test_isa_2_07_part2_CFLAGS = $(AM_CFLAGS) -Winline -Wall -O -g -mregnames $(ISA_2_07_FLAG) \ @FLAG_M64@ $(BUILD_FLAGS_ISA_2_07) -test_tm_CFLAGS = $(AM_CFLAGS) -Winline -Wall -O -g -mregnames $(ISA_2_07_FLAG) \ +test_tm_CFLAGS = $(AM_CFLAGS) -Winline -Wall -O -g -mregnames $(HTM_FLAG) $(ISA_2_07_FLAG) \ @FLAG_M64@ $(BUILD_FLAGS_ISA_2_07) -test_touch_tm_CFLAGS = $(AM_CFLAGS) -Winline -Wall -O -g -mregnames $(ISA_2_07_FLAG) \ +test_touch_tm_CFLAGS = $(AM_CFLAGS) -Winline -Wall -O -g -mregnames $(HTM_FLAG) $(ISA_2_07_FLAG) \ @FLAG_M64@ $(BUILD_FLAGS_ISA_2_07) test_isa_2_06_part3_LDADD = -lm diff --git a/none/tests/ppc64/test_tm.c b/none/tests/ppc64/test_tm.c index 29eb5eb73c..c829384e23 100644 --- a/none/tests/ppc64/test_tm.c +++ b/none/tests/ppc64/test_tm.c @@ -1,5 +1,5 @@ #include -#ifdef HAS_ISA_2_07 +#ifdef SUPPORTS_HTM int __attribute__ ((noinline)) htm_begin (int r3, int r4) { int ret; @@ -14,10 +14,12 @@ int __attribute__ ((noinline)) htm_begin (int r3, int r4) #endif int main (void) { -#ifdef HAS_ISA_2_07 +#ifdef SUPPORTS_HTM int ret; ret = htm_begin (10, 20); printf ("ret = %d, expected = 10\n", ret); +#else + printf ("No HTM support."); #endif return 0; } diff --git a/none/tests/ppc64/test_touch_tm.c b/none/tests/ppc64/test_touch_tm.c index 9e40083a55..6c0431dce4 100644 --- a/none/tests/ppc64/test_touch_tm.c +++ b/none/tests/ppc64/test_touch_tm.c @@ -1,7 +1,7 @@ #include int main (void) { -#ifdef HAS_ISA_2_07 +#ifdef SUPPORTS_HTM /* Just get the compiler to generate each of the TM instructions * so we can verify that valgrind recognizes them. * For now, only the tbegin instruction does anything in valgrind. @@ -18,6 +18,8 @@ int main (void) { __builtin_trechkpt (); // not recognized by early HW __builtin_treclaim (0); // not recognized by early HW __builtin_tsr (0); +#else + printf ("No HTM support."); #endif return 0; } -- 2.47.2