]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Patch 4 and 5 of 7, improve PPC HW capabiltiy checking.
authorCarl Love <cel@us.ibm.com>
Mon, 20 Jul 2015 21:25:32 +0000 (21:25 +0000)
committerCarl Love <cel@us.ibm.com>
Mon, 20 Jul 2015 21:25:32 +0000 (21:25 +0000)
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
none/tests/ppc32/Makefile.am
none/tests/ppc64/Makefile.am
none/tests/ppc64/test_tm.c
none/tests/ppc64/test_touch_tm.c

index 60c4fec97ec0bcf394fdc73f72ed234ba62a9f9a..deb1acd54e1744df14e3d4f818f929acc62819cf 100644 (file)
@@ -1264,6 +1264,28 @@ AC_CHECK_MEMBER([pthread_mutex_t.__data.__kind],
                [],
                [#include <pthread.h>])
 
+# 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
 # <altivec.h> ?
@@ -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()])
 
index e66992cdf264471f9f0c0b7a20f672a0c1afef2a..763846057a6f54c69455325293178e8ad1e634d4 100644 (file)
@@ -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
index d1faca665e9b327103fc7dce429f70bca1f7597f..cc1fef42c6823cc9b8e2bead05a236a05b286ec2 100644 (file)
@@ -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
index 29eb5eb73c21319e46bdc22fbf33039306645dcc..c829384e233fe631e1abc2e23b92e514b0a27ec2 100644 (file)
@@ -1,5 +1,5 @@
 #include <stdio.h>
-#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;
 }
index 9e40083a552939d1ba629ed90038a0fb8a5fe3e1..6c0431dce4fa0417772bd13ceadd3b36b6da52fa 100644 (file)
@@ -1,7 +1,7 @@
 #include <stdio.h>
 
 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;
 }