diff options
Diffstat (limited to 'gcc/config/i386')
-rw-r--r-- | gcc/config/i386/cpuid.h | 1 | ||||
-rw-r--r-- | gcc/config/i386/driver-i386.c | 6 | ||||
-rw-r--r-- | gcc/config/i386/i386-c.c | 7 | ||||
-rw-r--r-- | gcc/config/i386/i386.c | 66 | ||||
-rw-r--r-- | gcc/config/i386/i386.h | 4 | ||||
-rw-r--r-- | gcc/config/i386/i386.md | 1 | ||||
-rw-r--r-- | gcc/config/i386/i386.opt | 4 | ||||
-rw-r--r-- | gcc/config/i386/sync.md | 49 |
8 files changed, 112 insertions, 26 deletions
diff --git a/gcc/config/i386/cpuid.h b/gcc/config/i386/cpuid.h index 6696b7a7303..a9d25c565cf 100644 --- a/gcc/config/i386/cpuid.h +++ b/gcc/config/i386/cpuid.h @@ -66,6 +66,7 @@ /* Extended Features (%eax == 7) */ #define bit_FSGSBASE (1 << 0) #define bit_BMI (1 << 3) +#define bit_HLE (1 << 4) #define bit_AVX2 (1 << 5) #define bit_BMI2 (1 << 8) #define bit_RTM (1 << 11) diff --git a/gcc/config/i386/driver-i386.c b/gcc/config/i386/driver-i386.c index 09de555bc6e..34cd096109e 100644 --- a/gcc/config/i386/driver-i386.c +++ b/gcc/config/i386/driver-i386.c @@ -397,6 +397,7 @@ const char *host_detect_local_cpu (int argc, const char **argv) unsigned int has_pclmul = 0, has_abm = 0, has_lwp = 0; unsigned int has_fma = 0, has_fma4 = 0, has_xop = 0; unsigned int has_bmi = 0, has_bmi2 = 0, has_tbm = 0, has_lzcnt = 0; + unsigned int has_hle = 0; bool arch; @@ -456,6 +457,7 @@ const char *host_detect_local_cpu (int argc, const char **argv) __cpuid_count (7, 0, eax, ebx, ecx, edx); has_bmi = ebx & bit_BMI; + has_hle = ebx & bit_HLE; has_avx2 = ebx & bit_AVX2; has_bmi2 = ebx & bit_BMI2; } @@ -726,10 +728,12 @@ const char *host_detect_local_cpu (int argc, const char **argv) const char *sse4_2 = has_sse4_2 ? " -msse4.2" : " -mno-sse4.2"; const char *sse4_1 = has_sse4_1 ? " -msse4.1" : " -mno-sse4.1"; const char *lzcnt = has_lzcnt ? " -mlzcnt" : " -mno-lzcnt"; + const char *hle = has_hle ? " -mhle" : "-mno-hle"; options = concat (options, cx16, sahf, movbe, ase, pclmul, popcnt, abm, lwp, fma, fma4, xop, bmi, bmi2, - tbm, avx, avx2, sse4_2, sse4_1, lzcnt, NULL); + tbm, avx, avx2, sse4_2, sse4_1, lzcnt, + hle, NULL); } done: diff --git a/gcc/config/i386/i386-c.c b/gcc/config/i386/i386-c.c index 49fd4d92ca8..c6551e2cbb6 100644 --- a/gcc/config/i386/i386-c.c +++ b/gcc/config/i386/i386-c.c @@ -54,6 +54,7 @@ ix86_target_macros_internal (HOST_WIDE_INT isa_flag, size_t tune_len = strlen (ix86_tune_string); int last_arch_char = ix86_arch_string[arch_len - 1]; int last_tune_char = ix86_tune_string[tune_len - 1]; + char hle_macro[64]; /* Built-ins based on -march=. */ switch (arch) @@ -293,6 +294,12 @@ ix86_target_macros_internal (HOST_WIDE_INT isa_flag, def_or_undef (parse_in, "__SSE_MATH__"); if ((fpmath & FPMATH_SSE) && (isa_flag & OPTION_MASK_ISA_SSE2)) def_or_undef (parse_in, "__SSE2_MATH__"); + + sprintf (hle_macro, "__ATOMIC_HLE_ACQUIRE=%d", IX86_HLE_ACQUIRE); + def_or_undef (parse_in, hle_macro); + + sprintf (hle_macro, "__ATOMIC_HLE_RELEASE=%d", IX86_HLE_RELEASE); + def_or_undef (parse_in, hle_macro); } diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index 903683e3500..46daee10cd7 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -2679,6 +2679,7 @@ ix86_target_string (HOST_WIDE_INT isa, int flags, const char *arch, { "-mbmi", OPTION_MASK_ISA_BMI }, { "-mbmi2", OPTION_MASK_ISA_BMI2 }, { "-mlzcnt", OPTION_MASK_ISA_LZCNT }, + { "-mhle", OPTION_MASK_ISA_HLE }, { "-mtbm", OPTION_MASK_ISA_TBM }, { "-mpopcnt", OPTION_MASK_ISA_POPCNT }, { "-mmovbe", OPTION_MASK_ISA_MOVBE }, @@ -2954,6 +2955,7 @@ ix86_option_override_internal (bool main_args_p) #define PTA_AVX2 (HOST_WIDE_INT_1 << 30) #define PTA_BMI2 (HOST_WIDE_INT_1 << 31) #define PTA_RTM (HOST_WIDE_INT_1 << 32) +#define PTA_HLE (HOST_WIDE_INT_1 << 33) /* if this reaches 64, need to widen struct pta flags below */ static struct pta @@ -3012,7 +3014,7 @@ ix86_option_override_internal (bool main_args_p) | PTA_SSSE3 | PTA_SSE4_1 | PTA_SSE4_2 | PTA_AVX | PTA_AVX2 | PTA_CX16 | PTA_POPCNT | PTA_AES | PTA_PCLMUL | PTA_FSGSBASE | PTA_RDRND | PTA_F16C | PTA_BMI | PTA_BMI2 | PTA_LZCNT - | PTA_FMA | PTA_MOVBE | PTA_RTM}, + | PTA_FMA | PTA_MOVBE | PTA_RTM | PTA_HLE}, {"atom", PROCESSOR_ATOM, CPU_ATOM, PTA_64BIT | PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_SSE3 | PTA_SSSE3 | PTA_CX16 | PTA_MOVBE}, @@ -3075,9 +3077,10 @@ ix86_option_override_internal (bool main_args_p) PTA_64BIT | PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_SSE3 | PTA_SSSE3 | PTA_SSE4A |PTA_ABM | PTA_CX16}, {"generic32", PROCESSOR_GENERIC32, CPU_PENTIUMPRO, - 0 /* flags are only used for -march switch. */ }, + PTA_HLE /* flags are only used for -march switch. */ }, {"generic64", PROCESSOR_GENERIC64, CPU_GENERIC64, - PTA_64BIT /* flags are only used for -march switch. */ }, + PTA_64BIT + | PTA_HLE /* flags are only used for -march switch. */ }, }; /* -mrecip options. */ @@ -3430,6 +3433,9 @@ ix86_option_override_internal (bool main_args_p) if (processor_alias_table[i].flags & PTA_RTM && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_RTM)) ix86_isa_flags |= OPTION_MASK_ISA_RTM; + if (processor_alias_table[i].flags & PTA_HLE + && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_HLE)) + ix86_isa_flags |= OPTION_MASK_ISA_HLE; if (processor_alias_table[i].flags & (PTA_PREFETCH_SSE | PTA_SSE)) x86_prefetch_sse = true; @@ -4251,6 +4257,7 @@ ix86_valid_target_attribute_inner_p (tree args, char *p_strings[], IX86_ATTR_ISA ("rdrnd", OPT_mrdrnd), IX86_ATTR_ISA ("f16c", OPT_mf16c), IX86_ATTR_ISA ("rtm", OPT_mrtm), + IX86_ATTR_ISA ("hle", OPT_mhle), /* enum options */ IX86_ATTR_ENUM ("fpmath=", OPT_mfpmath_), @@ -14340,6 +14347,24 @@ ix86_print_operand (FILE *file, rtx x, int code) x = adjust_address_nv (x, DImode, 8); break; + case 'K': + gcc_assert (CONST_INT_P (x)); + + if (INTVAL (x) & IX86_HLE_ACQUIRE) +#ifdef HAVE_AS_IX86_HLE + fputs ("xacquire ", file); +#else + fputs ("\n" ASM_BYTE "0xf2\n\t", file); +#endif + else if (INTVAL (x) & IX86_HLE_RELEASE) +#ifdef HAVE_AS_IX86_HLE + fputs ("xrelease ", file); +#else + fputs ("\n" ASM_BYTE "0xf3\n\t", file); +#endif + /* We do not want to print value of the operand. */ + return; + case '+': { rtx x; @@ -39302,6 +39327,38 @@ ix86_autovectorize_vector_sizes (void) return (TARGET_AVX && !TARGET_PREFER_AVX128) ? 32 | 16 : 0; } +/* Validate target specific memory model bits in VAL. */ + +static unsigned HOST_WIDE_INT +ix86_memmodel_check (unsigned HOST_WIDE_INT val) +{ + unsigned HOST_WIDE_INT model = val & MEMMODEL_MASK; + unsigned HOST_WIDE_INT strong; + + if (val & ~(unsigned HOST_WIDE_INT)(IX86_HLE_ACQUIRE|IX86_HLE_RELEASE + |MEMMODEL_MASK) + || ((val & IX86_HLE_ACQUIRE) && (val & IX86_HLE_RELEASE))) + { + warning (OPT_Winvalid_memory_model, + "Unknown architecture specific memory model"); + return MEMMODEL_SEQ_CST; + } + strong = (model == MEMMODEL_ACQ_REL || model == MEMMODEL_SEQ_CST); + if (val & IX86_HLE_ACQUIRE && !(model == MEMMODEL_ACQUIRE || strong)) + { + warning (OPT_Winvalid_memory_model, + "HLE_ACQUIRE not used with ACQUIRE or stronger memory model"); + return MEMMODEL_SEQ_CST | IX86_HLE_ACQUIRE; + } + if (val & IX86_HLE_RELEASE && !(model == MEMMODEL_RELEASE || strong)) + { + warning (OPT_Winvalid_memory_model, + "HLE_RELEASE not used with RELEASE or stronger memory model"); + return MEMMODEL_SEQ_CST | IX86_HLE_RELEASE; + } + return val; +} + /* Initialize the GCC target structure. */ #undef TARGET_RETURN_IN_MEMORY #define TARGET_RETURN_IN_MEMORY ix86_return_in_memory @@ -39401,6 +39458,9 @@ ix86_autovectorize_vector_sizes (void) #undef TARGET_FUNCTION_OK_FOR_SIBCALL #define TARGET_FUNCTION_OK_FOR_SIBCALL ix86_function_ok_for_sibcall +#undef TARGET_MEMMODEL_CHECK +#define TARGET_MEMMODEL_CHECK ix86_memmodel_check + #ifdef HAVE_AS_TLS #undef TARGET_HAVE_TLS #define TARGET_HAVE_TLS true diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h index 8942ea86edf..09442604c96 100644 --- a/gcc/config/i386/i386.h +++ b/gcc/config/i386/i386.h @@ -75,6 +75,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #define TARGET_RDRND OPTION_ISA_RDRND #define TARGET_F16C OPTION_ISA_F16C #define TARGET_RTM OPTION_ISA_RTM +#define TARGET_HLE OPTION_ISA_HLE #define TARGET_LP64 OPTION_ABI_64 #define TARGET_X32 OPTION_ABI_X32 @@ -2344,6 +2345,9 @@ extern void debug_dispatch_window (int); #define TARGET_RECIP_VEC_DIV ((recip_mask & RECIP_MASK_VEC_DIV) != 0) #define TARGET_RECIP_VEC_SQRT ((recip_mask & RECIP_MASK_VEC_SQRT) != 0) +#define IX86_HLE_ACQUIRE (1 << 16) +#define IX86_HLE_RELEASE (1 << 17) + /* Local variables: version-control: t diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md index ea77c203b49..9da00cc53d4 100644 --- a/gcc/config/i386/i386.md +++ b/gcc/config/i386/i386.md @@ -58,6 +58,7 @@ ;; X -- don't print any sort of PIC '@' suffix for a symbol. ;; & -- print some in-use local-dynamic symbol name. ;; H -- print a memory address offset by 8; used for sse high-parts +;; K -- print HLE lock prefix ;; Y -- print condition for XOP pcom* instruction. ;; + -- print a branch hint as 'cs' or 'ds' prefix ;; ; -- print a semicolon (after prefixes due to bug in older gas). diff --git a/gcc/config/i386/i386.opt b/gcc/config/i386/i386.opt index bf50aed47a8..db34e1fc073 100644 --- a/gcc/config/i386/i386.opt +++ b/gcc/config/i386/i386.opt @@ -528,6 +528,10 @@ mlzcnt Target Report Mask(ISA_LZCNT) Var(ix86_isa_flags) Save Support LZCNT built-in function and code generation +mhle +Target Report Mask(ISA_HLE) Var(ix86_isa_flags) Save +Support Hardware Lock Elision prefixes + mtbm Target Report Mask(ISA_TBM) Var(ix86_isa_flags) Save Support TBM built-in functions and code generation diff --git a/gcc/config/i386/sync.md b/gcc/config/i386/sync.md index faf65ba8a23..e02a949631e 100644 --- a/gcc/config/i386/sync.md +++ b/gcc/config/i386/sync.md @@ -315,8 +315,9 @@ (match_operand:SI 7 "const_int_operand")] ;; failure model "TARGET_CMPXCHG" { - emit_insn (gen_atomic_compare_and_swap_single<mode> - (operands[1], operands[2], operands[3], operands[4])); + emit_insn + (gen_atomic_compare_and_swap_single<mode> + (operands[1], operands[2], operands[3], operands[4], operands[6])); ix86_expand_setcc (operands[0], EQ, gen_rtx_REG (CCZmode, FLAGS_REG), const0_rtx); DONE; @@ -344,8 +345,9 @@ { if (<MODE>mode == DImode && TARGET_64BIT) { - emit_insn (gen_atomic_compare_and_swap_singledi - (operands[1], operands[2], operands[3], operands[4])); + emit_insn + (gen_atomic_compare_and_swap_singledi + (operands[1], operands[2], operands[3], operands[4], operands[6])); } else { @@ -370,7 +372,7 @@ mem = replace_equiv_address (mem, force_reg (Pmode, XEXP (mem, 0))); emit_insn (gen_atomic_compare_and_swap_double<mode> - (lo_o, hi_o, mem, lo_e, hi_e, lo_n, hi_n)); + (lo_o, hi_o, mem, lo_e, hi_e, lo_n, hi_n, operands[6])); } ix86_expand_setcc (operands[0], EQ, gen_rtx_REG (CCZmode, FLAGS_REG), const0_rtx); @@ -382,14 +384,15 @@ (unspec_volatile:SWI [(match_operand:SWI 1 "memory_operand" "+m") (match_operand:SWI 2 "register_operand" "0") - (match_operand:SWI 3 "register_operand" "<r>")] + (match_operand:SWI 3 "register_operand" "<r>") + (match_operand:SI 4 "const_int_operand")] UNSPECV_CMPXCHG_1)) (set (match_dup 1) (unspec_volatile:SWI [(const_int 0)] UNSPECV_CMPXCHG_2)) (set (reg:CCZ FLAGS_REG) (unspec_volatile:CCZ [(const_int 0)] UNSPECV_CMPXCHG_3))] "TARGET_CMPXCHG" - "lock{%;} cmpxchg{<imodesuffix>}\t{%3, %1|%1, %3}") + "lock{%;} %K4cmpxchg{<imodesuffix>}\t{%3, %1|%1, %3}") ;; For double-word compare and swap, we are obliged to play tricks with ;; the input newval (op5:op6) because the Intel register numbering does @@ -403,7 +406,8 @@ (match_operand:<DCASHMODE> 3 "register_operand" "0") (match_operand:<DCASHMODE> 4 "register_operand" "1") (match_operand:<DCASHMODE> 5 "register_operand" "b") - (match_operand:<DCASHMODE> 6 "register_operand" "c")] + (match_operand:<DCASHMODE> 6 "register_operand" "c") + (match_operand:SI 7 "const_int_operand")] UNSPECV_CMPXCHG_1)) (set (match_operand:<DCASHMODE> 1 "register_operand" "=d") (unspec_volatile:<DCASHMODE> [(const_int 0)] UNSPECV_CMPXCHG_2)) @@ -412,7 +416,7 @@ (set (reg:CCZ FLAGS_REG) (unspec_volatile:CCZ [(const_int 0)] UNSPECV_CMPXCHG_4))] "" - "lock{%;} cmpxchg<doublemodesuffix>b\t%2") + "lock{%;} %K7cmpxchg<doublemodesuffix>b\t%2") ;; Theoretically we'd like to use constraint "r" (any reg) for op5, ;; but that includes ecx. If op5 and op6 are the same (like when @@ -430,7 +434,8 @@ (match_operand:SI 3 "register_operand" "0") (match_operand:SI 4 "register_operand" "1") (match_operand:SI 5 "register_operand" "SD") - (match_operand:SI 6 "register_operand" "c")] + (match_operand:SI 6 "register_operand" "c") + (match_operand:SI 7 "const_int_operand")] UNSPECV_CMPXCHG_1)) (set (match_operand:SI 1 "register_operand" "=d") (unspec_volatile:SI [(const_int 0)] UNSPECV_CMPXCHG_2)) @@ -439,7 +444,7 @@ (set (reg:CCZ FLAGS_REG) (unspec_volatile:CCZ [(const_int 0)] UNSPECV_CMPXCHG_4))] "!TARGET_64BIT && TARGET_CMPXCHG8B && flag_pic" - "xchg{l}\t%%ebx, %5\;lock{%;} cmpxchg8b\t%2\;xchg{l}\t%%ebx, %5") + "xchg{l}\t%%ebx, %5\;lock{%;} %K7cmpxchg8b\t%2\;xchg{l}\t%%ebx, %5") ;; For operand 2 nonmemory_operand predicate is used instead of ;; register_operand to allow combiner to better optimize atomic @@ -455,7 +460,7 @@ (match_operand:SWI 2 "nonmemory_operand" "0"))) (clobber (reg:CC FLAGS_REG))] "TARGET_XADD" - "lock{%;} xadd{<imodesuffix>}\t{%0, %1|%1, %0}") + "lock{%;} %K3xadd{<imodesuffix>}\t{%0, %1|%1, %0}") ;; This peephole2 and following insn optimize ;; __sync_fetch_and_add (x, -N) == N into just lock {add,sub,inc,dec} @@ -526,7 +531,7 @@ (set (match_dup 1) (match_operand:SWI 2 "register_operand" "0"))] ;; input "" - "xchg{<imodesuffix>}\t{%1, %0|%0, %1}") + "%K3xchg{<imodesuffix>}\t{%1, %0|%0, %1}") (define_insn "atomic_add<mode>" [(set (match_operand:SWI 0 "memory_operand" "+m") @@ -541,15 +546,15 @@ if (TARGET_USE_INCDEC) { if (operands[1] == const1_rtx) - return "lock{%;} inc{<imodesuffix>}\t%0"; + return "lock{%;} %K2inc{<imodesuffix>}\t%0"; if (operands[1] == constm1_rtx) - return "lock{%;} dec{<imodesuffix>}\t%0"; + return "lock{%;} %K2dec{<imodesuffix>}\t%0"; } if (x86_maybe_negate_const_int (&operands[1], <MODE>mode)) - return "lock{%;} sub{<imodesuffix>}\t{%1, %0|%0, %1}"; + return "lock{%;} %K2sub{<imodesuffix>}\t{%1, %0|%0, %1}"; - return "lock{%;} add{<imodesuffix>}\t{%1, %0|%0, %1}"; + return "lock{%;} %K2add{<imodesuffix>}\t{%1, %0|%0, %1}"; }) (define_insn "atomic_sub<mode>" @@ -565,15 +570,15 @@ if (TARGET_USE_INCDEC) { if (operands[1] == const1_rtx) - return "lock{%;} dec{<imodesuffix>}\t%0"; + return "lock{%;} %K2dec{<imodesuffix>}\t%0"; if (operands[1] == constm1_rtx) - return "lock{%;} inc{<imodesuffix>}\t%0"; + return "lock{%;} %K2inc{<imodesuffix>}\t%0"; } if (x86_maybe_negate_const_int (&operands[1], <MODE>mode)) - return "lock{%;} add{<imodesuffix>}\t{%1, %0|%0, %1}"; + return "lock{%;} %K2add{<imodesuffix>}\t{%1, %0|%0, %1}"; - return "lock{%;} sub{<imodesuffix>}\t{%1, %0|%0, %1}"; + return "lock{%;} %K2sub{<imodesuffix>}\t{%1, %0|%0, %1}"; }) (define_insn "atomic_<logic><mode>" @@ -585,4 +590,4 @@ UNSPECV_LOCK)) (clobber (reg:CC FLAGS_REG))] "" - "lock{%;} <logic>{<imodesuffix>}\t{%1, %0|%0, %1}") + "lock{%;} %K2<logic>{<imodesuffix>}\t{%1, %0|%0, %1}") |