From patchwork Thu Nov 10 00:32:58 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 124765 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 712EBB6F8A for ; Thu, 10 Nov 2011 11:33:18 +1100 (EST) Received: (qmail 319 invoked by alias); 10 Nov 2011 00:33:16 -0000 Received: (qmail 310 invoked by uid 22791); 10 Nov 2011 00:33:15 -0000 X-SWARE-Spam-Status: No, hits=-0.6 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, TW_CP, URIBL_BLACK X-Spam-Check-By: sourceware.org Received: from mail-vx0-f175.google.com (HELO mail-vx0-f175.google.com) (209.85.220.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 10 Nov 2011 00:33:01 +0000 Received: by vcbfl17 with SMTP id fl17so2175683vcb.20 for ; Wed, 09 Nov 2011 16:33:01 -0800 (PST) Received: by 10.52.35.75 with SMTP id f11mr8824208vdj.18.1320885180982; Wed, 09 Nov 2011 16:33:00 -0800 (PST) Received: from anchor.twiddle.net (c-98-203-235-125.hsd1.wa.comcast.net. [98.203.235.125]) by mx.google.com with ESMTPS id b4sm9685615vda.7.2011.11.09.16.33.00 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 09 Nov 2011 16:33:00 -0800 (PST) Message-ID: <4EBB1BBA.7000209@gmail.com> Date: Wed, 09 Nov 2011 16:32:58 -0800 From: Richard Henderson User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:7.0) Gecko/20110927 Thunderbird/7.0 MIME-Version: 1.0 To: GCC Patches Subject: [libitm] Work around missing AVX support Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Not pretty at all. But given the corresponding irritation in writing assembler wrapper functions, it seems like it's about a wash. Tested with and without HAVE_AS_AVX on x86_64-linux. r~ commit 856dd9f4777fbafce3038e889e9a9bf48222215d Author: Richard Henderson Date: Wed Nov 9 16:28:45 2011 -0800 libitm: Work around assembler missing AVX insns. diff --git a/libitm/ChangeLog b/libitm/ChangeLog index b1629b1..8aeb589 100644 --- a/libitm/ChangeLog +++ b/libitm/ChangeLog @@ -1,5 +1,12 @@ 2011-11-09 Richard Henderson + * acinclude.m4 (LIBITM_CHECK_AS_AVX): New. + * configure.ac: Use it. + * config.h.in, configure: Rebuild. + * config/x86/x86_avx.cc: Handle !HAVE_AS_AVX. + +2011-11-09 Richard Henderson + * barrier.tpl, memcpy.cc, memset.cc, method-wbetl.cc: Remove file. * config/alpha/unaligned.h: Remove file. * config/generic/unaligned.h: Remove file. diff --git a/libitm/acinclude.m4 b/libitm/acinclude.m4 index 8fcde4b..58fbf42 100644 --- a/libitm/acinclude.m4 +++ b/libitm/acinclude.m4 @@ -95,6 +95,20 @@ AC_DEFUN([LIBITM_CHECK_SIZE_T_MANGLING], [ [Define to the letter to which size_t is mangled.]) ]) +dnl Check if as supports AVX instructions. +AC_DEFUN([LIBITM_CHECK_AS_AVX], [ +case "${target_cpu}" in +i[3456]86 | x86_64) + AC_CACHE_CHECK([if the assembler supports AVX], libitm_cv_as_avx, [ + AC_TRY_COMPILE([], [asm("vzeroupper");], + [libitm_cv_as_avx=yes], [libitm_cv_as_avx=no]) + ]) + if test x$libitm_cv_as_avx = xyes; then + AC_DEFINE(HAVE_AS_AVX, 1, [Define to 1 if the assembler supports AVX.]) + fi + ;; +esac]) + sinclude(../libtool.m4) dnl The lines below arrange for aclocal not to bring an installed dnl libtool.m4 into aclocal.m4, while still arranging for automake to diff --git a/libitm/config/x86/x86_avx.cc b/libitm/config/x86/x86_avx.cc index 30420aa..cd20fe2 100644 --- a/libitm/config/x86/x86_avx.cc +++ b/libitm/config/x86/x86_avx.cc @@ -22,9 +22,66 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see . */ +#include "config.h" + +// ??? This is pretty gross, but we're going to frob types of the functions. +// Is this better or worse than just admitting we need to do this in pure +// assembly? + +#ifndef HAVE_AS_AVX +#undef __AVX__ +#endif + #include "libitm_i.h" #include "dispatch.h" +extern "C" { + +#ifndef HAVE_AS_AVX +typedef float _ITM_TYPE_M256 __attribute__((vector_size(32), may_alias)); +#endif + +// ??? Re-define the memcpy implementations so that we can frob the +// interface to deal with possibly missing AVX instruction set support. + +#ifdef HAVE_AS_AVX +#define RETURN(X) return X +#define STORE(X,Y) X = Y +#define OUTPUT(T) _ITM_TYPE_##T +#define INPUT(T,X) , _ITM_TYPE_##T X +#else +/* Emit vmovaps (%rax),%ymm0. */ +#define RETURN(X) \ + asm volatile(".byte 0xc5,0xfc,0x28,0x00" : "=m"(X) : "a"(&X)); +/* Emit vmovaps %ymm0,(%rax); vzeroupper. */ +#define STORE(X,Y) \ + asm volatile(".byte 0xc5,0xfc,0x29,0x00,0xc5,0xf8,0x77" : "=m"(X) : "a"(&X)); +#define OUTPUT(T) void +#define INPUT(T,X) +#endif + +#undef ITM_READ_MEMCPY +#define ITM_READ_MEMCPY(T, LSMOD, TARGET, M2) \ +OUTPUT(T) ITM_REGPARM _ITM_##LSMOD##T (const _ITM_TYPE_##T *ptr) \ +{ \ + _ITM_TYPE_##T v; \ + TARGET memtransfer##M2(&v, ptr, sizeof(_ITM_TYPE_##T), false, \ + GTM::abi_dispatch::NONTXNAL, \ + GTM::abi_dispatch::LSMOD); \ + RETURN(v); \ +} + +#undef ITM_WRITE_MEMCPY +#define ITM_WRITE_MEMCPY(T, LSMOD, TARGET, M2) \ +void ITM_REGPARM _ITM_##LSMOD##T (_ITM_TYPE_##T *ptr INPUT(T,in)) \ +{ \ + _ITM_TYPE_##T v; \ + STORE(v, in); \ + TARGET memtransfer##M2(ptr, &v, sizeof(_ITM_TYPE_##T), false, \ + GTM::abi_dispatch::LSMOD, \ + GTM::abi_dispatch::NONTXNAL); \ +} + // ??? Use memcpy for now, until we have figured out how to best instantiate // these loads/stores. CREATE_DISPATCH_FUNCTIONS_T_MEMCPY(M256, GTM::abi_disp()->, ) @@ -34,3 +91,5 @@ _ITM_LM256 (const _ITM_TYPE_M256 *ptr) { GTM::GTM_LB (ptr, sizeof (*ptr)); } + +} diff --git a/libitm/configure.ac b/libitm/configure.ac index c40ecb5..7de5cbe 100644 --- a/libitm/configure.ac +++ b/libitm/configure.ac @@ -237,6 +237,7 @@ CFLAGS="$save_CFLAGS $XCFLAGS" # had a chance to set XCFLAGS. LIBITM_CHECK_SYNC_BUILTINS LIBITM_CHECK_64BIT_SYNC_BUILTINS +LIBITM_CHECK_AS_AVX # Cleanup and exit. CFLAGS="$save_CFLAGS"