On 09/22/2017 03:28 AM, Rainer Orth wrote: > Hi Daniel, > >> On 09/22/2017 02:18 AM, Rainer Orth wrote: >>> Hi Daniel, >>> >>>> On 09/21/2017 05:18 PM, Daniel Santos wrote: >>>>> So libgcc doesn't use a config.in. :( >>>> Scratch that, I forgot that we're using gcc/config.in via auto-host.h. >>>> So I only have to add this to gcc/configure.ac and it will be available >>>> for my libgcc header -- this is what I used to sniff out support for the >>>> .hidden directive. >>> Please don't go that route: it's totally the wrong direction. There's >>> work going on to further decouple libgcc from gcc-private headers and >>> configure results. libgcc already has its own configure tests for >>> assembler features, and its own config.in. What's wrong with adapting >>> libitm's avx test in libitm/acinclude.m4 (LIBITM_CHECK_AS_AVX) for >>> libgcc? Should be trivial... >>> >>> Rainer >>> >> Oops, I just saw your email after submitting my other patch. Yes, I am >> mistaken about config.in, sorry about that. I didn't see a config.h >> file, but examining further it looks like it outputs to auto-target.h. >> Also, I was looking for some HAVE_AS* macros, but they are named >> differently. > Right: though some are for assembler features, the macros are named > differently. > >> I had previously included gcc's auto-host.h since it was in the include >> path in order to use HAVE_AS_HIDDEN, so in order to decouple this I'll > HAVE_GAS_HIDDEN actually ;-) > >> need to add that check into libgcc/configure.ac as well. Again, >> shouldn't be that much code. Sound sane to you? > You could do that, but it was already used before your patches, so > please separate it from the current issue if you go down that route. > libgcc is still full of cleanup possibilities :-) > > Rainer
OK, so I'm just adding HAVE_AS_AVX mostly as-is from libitm (we don't have $target_cpu so I'm using $target). I do have minor concerns about how this test will work on a cross-build -- I'm not an autotools expert and I don't understand which assembler it will invoke, but the results of the test failing only means we use .byte instead of the real mnemonic, so it really shouldn't be a problem. I've got tests started again, so presuming that *this* one passes, is it OK for the trunk? gcc/testsuite: * gcc.target/i386/pr82196-1.c: Simplify so that it doesn't break on Solaris or with -mno-omit-frame-pointer. * gcc.target/i386/pr82196-2.c: Likewise. libgcc: * configure.ac: Add check for HAVE_AS_AVX. * config.in: Regenerate. * configure: Likewise. * config/i386/i386-asm.h: Include auto-target.h from libgcc. (SSE_SAVE, SSE_RESTORE): Sniff HAVE_AS_AVX and directly emit raw .byte code when assembler doesn't support avx, correct out-of-date comments. gcc/testsuite/gcc.target/i386/pr82196-1.c | 5 ++- gcc/testsuite/gcc.target/i386/pr82196-2.c | 5 ++- libgcc/config.in | 3 ++ libgcc/config/i386/i386-asm.h | 45 ++++++++++++++++++++++----- libgcc/configure | 39 +++++++++++++++++++++++ libgcc/configure.ac | 16 ++++++++++ 6 files changed, 100 insertions(+), 13 deletions(-) Thanks, Daniel
diff --git a/gcc/testsuite/gcc.target/i386/pr82196-1.c b/gcc/testsuite/gcc.target/i386/pr82196-1.c index ef858328f00..541d975480d 100644 --- a/gcc/testsuite/gcc.target/i386/pr82196-1.c +++ b/gcc/testsuite/gcc.target/i386/pr82196-1.c @@ -1,7 +1,7 @@ /* { dg-do compile { target lp64 } } */ /* { dg-options "-msse -mcall-ms2sysv-xlogues -O2" } */ -/* { dg-final { scan-assembler "call.*__sse_savms64_18" } } */ -/* { dg-final { scan-assembler "jmp.*__sse_resms64x_18" } } */ +/* { dg-final { scan-assembler "call.*__sse_savms64f?_12" } } */ +/* { dg-final { scan-assembler "jmp.*__sse_resms64f?x_12" } } */ void __attribute__((sysv_abi)) a() { } @@ -9,6 +9,5 @@ void __attribute__((sysv_abi)) a() { static void __attribute__((sysv_abi)) (*volatile a_noinfo)() = a; void __attribute__((ms_abi)) b() { - __asm__ __volatile__ ("" :::"rbx", "rbp", "r12", "r13", "r14", "r15"); a_noinfo (); } diff --git a/gcc/testsuite/gcc.target/i386/pr82196-2.c b/gcc/testsuite/gcc.target/i386/pr82196-2.c index 8fe58411d5e..7166d068bc1 100644 --- a/gcc/testsuite/gcc.target/i386/pr82196-2.c +++ b/gcc/testsuite/gcc.target/i386/pr82196-2.c @@ -1,7 +1,7 @@ /* { dg-do compile { target lp64 } } */ /* { dg-options "-mavx -mcall-ms2sysv-xlogues -O2" } */ -/* { dg-final { scan-assembler "call.*__avx_savms64_18" } } */ -/* { dg-final { scan-assembler "jmp.*__avx_resms64x_18" } } */ +/* { dg-final { scan-assembler "call.*__avx_savms64f?_12" } } */ +/* { dg-final { scan-assembler "jmp.*__avx_resms64f?x_12" } } */ void __attribute__((sysv_abi)) a() { } @@ -9,6 +9,5 @@ void __attribute__((sysv_abi)) a() { static void __attribute__((sysv_abi)) (*volatile a_noinfo)() = a; void __attribute__((ms_abi)) b() { - __asm__ __volatile__ ("" :::"rbx", "rbp", "r12", "r13", "r14", "r15"); a_noinfo (); } diff --git a/libgcc/config.in b/libgcc/config.in index 7de22ee0a72..f9fb253874f 100644 --- a/libgcc/config.in +++ b/libgcc/config.in @@ -1,5 +1,8 @@ /* config.in. Generated from configure.ac by autoheader. */ +/* Define to 1 if the assembler supports AVX. */ +#undef HAVE_AS_AVX + /* Define to 1 if the target assembler supports thread-local storage. */ #undef HAVE_CC_TLS diff --git a/libgcc/config/i386/i386-asm.h b/libgcc/config/i386/i386-asm.h index 424e0f72aac..b417bfb93d6 100644 --- a/libgcc/config/i386/i386-asm.h +++ b/libgcc/config/i386/i386-asm.h @@ -26,6 +26,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #ifndef I386_ASM_H #define I386_ASM_H +#include "auto-target.h" #include "auto-host.h" #define PASTE2(a, b) PASTE2a(a, b) @@ -69,13 +70,15 @@ ASMNAME(fn): #ifdef MS2SYSV_STUB_AVX # define MS2SYSV_STUB_PREFIX __avx_ -# define MOVAPS vmovaps +# ifdef HAVE_AS_AVX +# define MOVAPS vmovaps +# endif #elif defined(MS2SYSV_STUB_SSE) # define MS2SYSV_STUB_PREFIX __sse_ # define MOVAPS movaps #endif -#if defined (MS2SYSV_STUB_PREFIX) && defined (MOVAPS) +#if defined (MS2SYSV_STUB_PREFIX) # define MS2SYSV_STUB_BEGIN(base_name) \ HIDDEN_FUNC(PASTE2(MS2SYSV_STUB_PREFIX, base_name)) @@ -83,8 +86,10 @@ ASMNAME(fn): # define MS2SYSV_STUB_END(base_name) \ FUNC_END(PASTE2(MS2SYSV_STUB_PREFIX, base_name)) -/* Save SSE registers 6-15. off is the offset of rax to get to xmm6. */ -# define SSE_SAVE \ +/* If expanding for sse or avx and we have assembler support. */ +# ifdef MOVAPS +/* Save SSE registers 6-15 using rax as the base address. */ +# define SSE_SAVE \ MOVAPS %xmm15,-0x30(%rax); \ MOVAPS %xmm14,-0x20(%rax); \ MOVAPS %xmm13,-0x10(%rax); \ @@ -96,8 +101,8 @@ ASMNAME(fn): MOVAPS %xmm7, 0x50(%rax); \ MOVAPS %xmm6, 0x60(%rax) -/* Restore SSE registers 6-15. off is the offset of rsi to get to xmm6. */ -# define SSE_RESTORE \ +/* Restore SSE registers 6-15 using rsi as the base address. */ +# define SSE_RESTORE \ MOVAPS -0x30(%rsi), %xmm15; \ MOVAPS -0x20(%rsi), %xmm14; \ MOVAPS -0x10(%rsi), %xmm13; \ @@ -108,6 +113,32 @@ ASMNAME(fn): MOVAPS 0x40(%rsi), %xmm8 ; \ MOVAPS 0x50(%rsi), %xmm7 ; \ MOVAPS 0x60(%rsi), %xmm6 - +# else /* MOVAPS */ +/* If the assembler doesn't support AVX then directly emit machine code + for the instructions above directly. */ +# define BYTE .byte +# define SSE_SAVE \ + BYTE 0xc5, 0x78, 0x29, 0x78, 0xd0; /* vmovaps %xmm15,-0x30(%rax) */ \ + BYTE 0xc5, 0x78, 0x29, 0x70, 0xe0; /* vmovaps %xmm14,-0x20(%rax) */ \ + BYTE 0xc5, 0x78, 0x29, 0x68, 0xf0; /* vmovaps %xmm13,-0x10(%rax) */ \ + BYTE 0xc5, 0x78, 0x29, 0x20; /* vmovaps %xmm12, (%rax) */ \ + BYTE 0xc5, 0x78, 0x29, 0x58, 0x10; /* vmovaps %xmm11, 0x10(%rax) */ \ + BYTE 0xc5, 0x78, 0x29, 0x50, 0x20; /* vmovaps %xmm10, 0x20(%rax) */ \ + BYTE 0xc5, 0x78, 0x29, 0x48, 0x30; /* vmovaps %xmm9, 0x30(%rax) */ \ + BYTE 0xc5, 0x78, 0x29, 0x40, 0x40; /* vmovaps %xmm8, 0x40(%rax) */ \ + BYTE 0xc5, 0xf8, 0x29, 0x78, 0x50; /* vmovaps %xmm7, 0x50(%rax) */ \ + BYTE 0xc5, 0xf8, 0x29, 0x70, 0x60; /* vmovaps %xmm6, 0x60(%rax) */ +# define SSE_RESTORE \ + BYTE 0xc5, 0x78, 0x28, 0x7e, 0xd0; /* vmovaps -0x30(%rsi),%xmm15 */ \ + BYTE 0xc5, 0x78, 0x28, 0x76, 0xe0; /* vmovaps -0x20(%rsi),%xmm14 */ \ + BYTE 0xc5, 0x78, 0x28, 0x6e, 0xf0; /* vmovaps -0x10(%rsi),%xmm13 */ \ + BYTE 0xc5, 0x78, 0x28, 0x26; /* vmovaps (%rsi),%xmm12 */ \ + BYTE 0xc5, 0x78, 0x28, 0x5e, 0x10; /* vmovaps 0x10(%rsi),%xmm11 */ \ + BYTE 0xc5, 0x78, 0x28, 0x56, 0x20; /* vmovaps 0x20(%rsi),%xmm10 */ \ + BYTE 0xc5, 0x78, 0x28, 0x4e, 0x30; /* vmovaps 0x30(%rsi),%xmm9 */ \ + BYTE 0xc5, 0x78, 0x28, 0x46, 0x40; /* vmovaps 0x40(%rsi),%xmm8 */ \ + BYTE 0xc5, 0xf8, 0x28, 0x7e, 0x50; /* vmovaps 0x50(%rsi),%xmm7 */ \ + BYTE 0xc5, 0xf8, 0x28, 0x76, 0x60; /* vmovaps 0x60(%rsi),%xmm6 */ +# endif /* MOVAPS */ #endif /* defined (MS2SYSV_STUB_ISA) && defined (MOVAPS) */ #endif /* I386_ASM_H */ diff --git a/libgcc/configure b/libgcc/configure index 15d34b27cc0..63c50c0c7e2 100644 --- a/libgcc/configure +++ b/libgcc/configure @@ -5212,6 +5212,45 @@ if test "$enable_tls $gcc_cv_use_emutls" = "yes yes"; then fi + + +case "${target}" in +i[34567]86-*-* | x86_64-*-*) + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if the assembler supports AVX" >&5 +$as_echo_n "checking if the assembler supports AVX... " >&6; } +if test "${libgcc_cv_as_avx+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ +asm("vzeroupper"); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + libgcc_cv_as_avx=yes +else + libgcc_cv_as_avx=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libgcc_cv_as_avx" >&5 +$as_echo "$libgcc_cv_as_avx" >&6; } + if test x$libgcc_cv_as_avx = xyes; then + +$as_echo "#define HAVE_AS_AVX 1" >>confdefs.h + + fi + ;; +esac + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for init priority support" >&5 $as_echo_n "checking for init priority support... " >&6; } if test "${libgcc_cv_init_priority+set}" = set; then : diff --git a/libgcc/configure.ac b/libgcc/configure.ac index da499716f8c..dd60b01d2f8 100644 --- a/libgcc/configure.ac +++ b/libgcc/configure.ac @@ -506,6 +506,22 @@ if test "$enable_tls $gcc_cv_use_emutls" = "yes yes"; then fi AC_SUBST(set_use_emutls) +dnl Check if as supports AVX instructions. +AC_DEFUN([LIBGCC_CHECK_AS_AVX], [ +case "${target}" in +i[[34567]]86-*-* | x86_64-*-*) + AC_CACHE_CHECK([if the assembler supports AVX], libgcc_cv_as_avx, [ + AC_TRY_COMPILE([], [asm("vzeroupper");], + [libgcc_cv_as_avx=yes], [libgcc_cv_as_avx=no]) + ]) + if test x$libgcc_cv_as_avx = xyes; then + AC_DEFINE(HAVE_AS_AVX, 1, [Define to 1 if the assembler supports AVX.]) + fi + ;; +esac]) +LIBGCC_CHECK_AS_AVX + +dnl Check if as supports RTM instructions. AC_CACHE_CHECK(for init priority support, libgcc_cv_init_priority, [ AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [[void ip (void) __attribute__ ((constructor (1)));]])],