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 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/configure.ac b/configure.ac
index 60c4fec..deb1acd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1264,6 +1264,28 @@
 		[],
 		[#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 @@
 
 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()])