On Tue, Jul 16, 2013 at 07:24:31AM +0200, Jakub Jelinek wrote:
> And on s/390, right now we enable HTM support in libitm when configured for
> -march=zEC12 by default (which isn't ideal).

Ok. What about the following patch (untested so far)?

It basically copies what the Power folks are doing with getauxval.
I've also added the configure check for HTM assembler support which so
far was missing on S/390.

Bye,

-Andreas-

---
 gcc/config/s390/s390.c      |    7 !!!!!!!
 gcc/config/s390/s390.h      |    3 !!!
 libitm/acinclude.m4         |   11 +++++++++++
 libitm/config/s390/target.h |   23 !!!!!!!!!!!!!!!!!!!!!!!
 libitm/configure            |   36 ++++++++++++++++++++++++++++++++++++
 libitm/configure.tgt        |    2 +-
 6 files changed, 48 insertions(+), 1 deletion(-), 33 modifications(!)

Index: libitm/acinclude.m4
===================================================================
*** libitm/acinclude.m4.orig
--- libitm/acinclude.m4
*************** powerpc*)
*** 135,140 ****
--- 135,151 ----
      AC_DEFINE(HAVE_AS_HTM, 1, [Define to 1 if the assembler supports HTM.])
    fi
    ;;
+ s390*)
+   AC_CACHE_CHECK([if the assembler supports HTM], libitm_cv_as_htm, [
+     save_CFLAGS="$CFLAGS"
+     CFLAGS="$CFLAGS -march=zEC12"
+     AC_TRY_COMPILE([], [asm("tbegin 0,0; tend");],
+                  [libitm_cv_as_htm=yes], [libitm_cv_as_htm=no])
+     CFLAGS="$save_CFLAGS"])
+   if test x$libitm_cv_as_htm = xyes; then
+     AC_DEFINE(HAVE_AS_HTM, 1, [Define to 1 if the assembler supports HTM.])
+   fi
+   ;;
  esac])
  
  sinclude(../libtool.m4)
Index: libitm/config/s390/target.h
===================================================================
*** libitm/config/s390/target.h.orig
--- libitm/config/s390/target.h
***************
*** 22,32 ****
     see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
     <http://www.gnu.org/licenses/>.  */
  
! 
! #include <htmintrin.h>
! 
! /* Number of retries for transient failures.  */
! #define _HTM_ITM_RETRIES 10
  
  namespace GTM HIDDEN {
  
--- 22,30 ----
     see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
     <http://www.gnu.org/licenses/>.  */
  
! #ifdef HAVE_SYS_AUXV_H
! #include <sys/auxv.h>
! #endif
  
  namespace GTM HIDDEN {
  
*************** cpu_relax (void)
*** 58,70 ****
    __asm volatile ("" : : : "memory");
  }
  
! #ifdef __HTM__
  #define USE_HTM_FASTPATH
  
  static inline bool
  htm_available ()
  {
!   return true;
  }
  
  static inline uint32_t
--- 56,79 ----
    __asm volatile ("" : : : "memory");
  }
  
! 
! // Use HTM if it is supported by the system.
! // See gtm_thread::begin_transaction for how these functions are used.
! #if defined (__linux__) \
!     && defined (HAVE_AS_HTM) \
!     && defined (HAVE_GETAUXVAL) \
!     && defined (HWCAP_S390_TE)
! 
! #include <htmintrin.h>
! 
! /* Number of retries for transient failures.  */
! #define _HTM_ITM_RETRIES 10
  #define USE_HTM_FASTPATH
  
  static inline bool
  htm_available ()
  {
!   return (getauxval (AT_HWCAP) & HWCAP_S390_TE) ? true : false;
  }
  
  static inline uint32_t
Index: libitm/configure.tgt
===================================================================
*** libitm/configure.tgt.orig
--- libitm/configure.tgt
*************** case "${target_cpu}" in
*** 109,116 ****
        ARCH=x86
        ;;
    s390|s390x)
        ARCH=s390
-       XCFLAGS="${XCFLAGS} -mzarch"
        ;;
  
    *)
--- 109,116 ----
        ARCH=x86
        ;;
    s390|s390x)
+       XCFLAGS="${XCFLAGS} -mzarch -mhtm"
        ARCH=s390
        ;;
  
    *)
Index: gcc/config/s390/s390.c
===================================================================
*** gcc/config/s390/s390.c.orig
--- gcc/config/s390/s390.c
*************** s390_expand_builtin (tree exp, rtx targe
*** 9771,9781 ****
    if (icode == 0)
      internal_error ("bad builtin fcode");
  
!   if (!TARGET_ZEC12)
!     error ("Transactional execution builtins require zEC12 or later\n");
! 
!   if (!TARGET_HTM && TARGET_ZEC12)
!     error ("Transactional execution builtins not enabled (-mtx)\n");
  
    /* Set a flag in the machine specific cfun part in order to support
       saving/restoring of FPRs.  */
--- 9771,9778 ----
    if (icode == 0)
      internal_error ("bad builtin fcode");
  
!   if (!TARGET_HTM)
!     error ("Transactional execution builtins not enabled (-mhtm)\n");
  
    /* Set a flag in the machine specific cfun part in order to support
       saving/restoring of FPRs.  */
Index: gcc/config/s390/s390.h
===================================================================
*** gcc/config/s390/s390.h.orig
--- gcc/config/s390/s390.h
*************** enum processor_flags
*** 81,88 ****
         (TARGET_ZARCH && TARGET_CPU_Z196)
  #define TARGET_ZEC12 \
         (TARGET_ZARCH && TARGET_CPU_ZEC12)
! #define TARGET_HTM \
!        (TARGET_ZARCH && TARGET_CPU_HTM && TARGET_OPT_HTM)
  
  
  #define TARGET_AVOID_CMP_AND_BRANCH (s390_tune == PROCESSOR_2817_Z196)
--- 81,87 ----
         (TARGET_ZARCH && TARGET_CPU_Z196)
  #define TARGET_ZEC12 \
         (TARGET_ZARCH && TARGET_CPU_ZEC12)
! #define TARGET_HTM (TARGET_OPT_HTM)
  
  
  #define TARGET_AVOID_CMP_AND_BRANCH (s390_tune == PROCESSOR_2817_Z196)
Index: libitm/configure
===================================================================
*** libitm/configure.orig
--- libitm/configure
*************** $as_echo "#define HAVE_AS_HTM 1" >>confd
*** 17399,17404 ****
--- 17399,17440 ----
  
    fi
    ;;
+ s390*)
+   { $as_echo "$as_me:${as_lineno-$LINENO}: checking if the assembler supports 
HTM" >&5
+ $as_echo_n "checking if the assembler supports HTM... " >&6; }
+ if test "${libitm_cv_as_htm+set}" = set; then :
+   $as_echo_n "(cached) " >&6
+ else
+ 
+     save_CFLAGS="$CFLAGS"
+     CFLAGS="$CFLAGS -march=zEC12"
+     cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+ /* end confdefs.h.  */
+ 
+ int
+ main ()
+ {
+ asm("tbegin 0,0; tend");
+   ;
+   return 0;
+ }
+ _ACEOF
+ if ac_fn_c_try_compile "$LINENO"; then :
+   libitm_cv_as_htm=yes
+ else
+   libitm_cv_as_htm=no
+ fi
+ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+     CFLAGS="$save_CFLAGS"
+ fi
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $libitm_cv_as_htm" >&5
+ $as_echo "$libitm_cv_as_htm" >&6; }
+   if test x$libitm_cv_as_htm = xyes; then
+ 
+ $as_echo "#define HAVE_AS_HTM 1" >>confdefs.h
+ 
+   fi
+   ;;
  esac
  
  

Reply via email to