diff --git a/gcc/builtins.c b/gcc/builtins.c index b47f218..427bd6b 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -5345,12 +5345,13 @@ get_memmodel (tree exp) return MEMMODEL_SEQ_CST; op = expand_normal (exp); - if (INTVAL (op) < 0 || INTVAL (op) >= MEMMODEL_LAST) + if (INTVAL (op) < 0) { warning (OPT_Winvalid_memory_model, "invalid memory model argument to builtin"); return MEMMODEL_SEQ_CST; } + return (enum memmodel) INTVAL (op); } @@ -5398,11 +5399,14 @@ expand_builtin_atomic_compare_exchange (enum machine_mode mode, tree exp, enum memmodel success, failure; tree weak; bool is_weak; + /* Suppose that higher bits are target dependant. */ + unsigned memmodel_mask = (1<<16) - 1; success = get_memmodel (CALL_EXPR_ARG (exp, 4)); failure = get_memmodel (CALL_EXPR_ARG (exp, 5)); - if (failure == MEMMODEL_RELEASE || failure == MEMMODEL_ACQ_REL) + if ( (failure & memmodel_mask) == MEMMODEL_RELEASE + || (failure & memmodel_mask) == MEMMODEL_ACQ_REL) { error ("invalid failure memory model for %<__atomic_compare_exchange%>"); return NULL_RTX; diff --git a/gcc/config.in b/gcc/config.in index 8806012..4560047 100644 --- a/gcc/config.in +++ b/gcc/config.in @@ -350,6 +350,11 @@ #undef HAVE_AS_IX86_SAHF #endif +/* Define if your assembler supports HLE prefixies. */ +#ifndef USED_FOR_TARGET +#undef HAVE_AS_IX86_HLE +#endif + /* Define if your assembler supports the swap suffix. */ #ifndef USED_FOR_TARGET diff --git a/gcc/config/i386/cpuid.h b/gcc/config/i386/cpuid.h index 6696b7a..a9d25c5 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 09de555..34cd096 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 49fd4d9..c6551e2 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-protos.h b/gcc/config/i386/i386-protos.h index f300a56..5832ab2 100644 --- a/gcc/config/i386/i386-protos.h +++ b/gcc/config/i386/i386-protos.h @@ -104,6 +104,7 @@ extern bool ix86_dep_by_shift_count (const_rtx set_insn, const_rtx use_insn); extern bool ix86_agi_dependent (rtx set_insn, rtx use_insn); extern void ix86_expand_unary_operator (enum rtx_code, enum machine_mode, rtx[]); +extern const char* ix86_generate_hle_prefix (rtx memmodel); extern rtx ix86_build_const_vector (enum machine_mode, bool, rtx); extern rtx ix86_build_signbit_mask (enum machine_mode, bool, bool); extern void ix86_split_convert_uns_si_sse (rtx[]); diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index abe3f1b..b9f2d4a 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}, @@ -3430,6 +3432,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 +4256,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_), @@ -16349,6 +16355,25 @@ ix86_expand_unary_operator (enum rtx_code code, enum machine_mode mode, emit_move_insn (operands[0], dst); } +/* Emit HLE lock prefix depending if specified by memmodel value. */ +const char* +ix86_generate_hle_prefix (rtx memmodel) +{ +#ifdef HAVE_AS_IX86_HLE + if (INTVAL (memmodel) & IX86_HLE_ACQUIRE) + return "xacquire "; + else if (INTVAL (memmodel) & IX86_HLE_RELEASE) + return "xrelease "; +#else + if (INTVAL (memmodel) & IX86_HLE_ACQUIRE) + return "\n" ASM_BYTE "0xf2\n\t"; + else if (INTVAL (memmodel) & IX86_HLE_RELEASE) + return "\n" ASM_BYTE "0xf3\n\t"; +#endif + + return ""; +} + /* Split 32bit/64bit divmod with 8bit unsigned divmod if dividend and divisor are within the range [0-255]. */ diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h index 8942ea8..0944260 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.opt b/gcc/config/i386/i386.opt index bf50aed..1d16149 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 prefixies + 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 faf65ba..13a32d6 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 - (operands[1], operands[2], operands[3], operands[4])); + emit_insn + (gen_atomic_compare_and_swap_single + (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 == 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 - (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,22 @@ (unspec_volatile:SWI [(match_operand:SWI 1 "memory_operand" "+m") (match_operand:SWI 2 "register_operand" "0") - (match_operand:SWI 3 "register_operand" "")] + (match_operand:SWI 3 "register_operand" "") + (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{}\t{%3, %1|%1, %3}") +{ + static char buf[128]; + + snprintf (buf, sizeof (buf), + "lock{%%;} %scmpxchg{}\t{%%3, %%1|%%1, %%3}", + ix86_generate_hle_prefix(operands[4])); + return buf; +}) ;; 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 +413,8 @@ (match_operand: 3 "register_operand" "0") (match_operand: 4 "register_operand" "1") (match_operand: 5 "register_operand" "b") - (match_operand: 6 "register_operand" "c")] + (match_operand: 6 "register_operand" "c") + (match_operand:SI 7 "const_int_operand")] UNSPECV_CMPXCHG_1)) (set (match_operand: 1 "register_operand" "=d") (unspec_volatile: [(const_int 0)] UNSPECV_CMPXCHG_2)) @@ -412,7 +423,14 @@ (set (reg:CCZ FLAGS_REG) (unspec_volatile:CCZ [(const_int 0)] UNSPECV_CMPXCHG_4))] "" - "lock{%;} cmpxchgb\t%2") +{ + static char buf[128]; + + snprintf (buf, sizeof (buf), + "lock{%%;} %scmpxchgb\t%%2", + ix86_generate_hle_prefix(operands[4])); + return buf; +}) ;; 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 @@ -455,7 +473,14 @@ (match_operand:SWI 2 "nonmemory_operand" "0"))) (clobber (reg:CC FLAGS_REG))] "TARGET_XADD" - "lock{%;} xadd{}\t{%0, %1|%1, %0}") +{ + static char buf[128]; + + snprintf (buf, sizeof (buf), + "lock{%%;} %sxadd{}\t{%%0, %%1|%%1, %%0}", + ix86_generate_hle_prefix(operands[3])); + return buf; +}) ;; This peephole2 and following insn optimize ;; __sync_fetch_and_add (x, -N) == N into just lock {add,sub,inc,dec} @@ -526,7 +551,14 @@ (set (match_dup 1) (match_operand:SWI 2 "register_operand" "0"))] ;; input "" - "xchg{}\t{%1, %0|%0, %1}") +{ + static char buf[128]; + + snprintf (buf, sizeof (buf), + "%sxchg{}\t{%%1, %%0|%%0, %%1}", + ix86_generate_hle_prefix(operands[3])); + return buf; +}) (define_insn "atomic_add" [(set (match_operand:SWI 0 "memory_operand" "+m") @@ -538,18 +570,24 @@ (clobber (reg:CC FLAGS_REG))] "" { + static char buf[128]; + const char *default_insn = "lock{%%;} %sadd{}\t{%%1, %%0|%%0, %%1}"; + if (TARGET_USE_INCDEC) { if (operands[1] == const1_rtx) - return "lock{%;} inc{}\t%0"; + default_insn = "lock{%%;} %sinc{}\t%%0"; if (operands[1] == constm1_rtx) - return "lock{%;} dec{}\t%0"; + default_insn = "lock{%%;} %sdec{}\t%%0"; } if (x86_maybe_negate_const_int (&operands[1], mode)) - return "lock{%;} sub{}\t{%1, %0|%0, %1}"; + default_insn = "lock{%%;} %ssub{}\t{%%1, %%0|%%0, %%1}"; - return "lock{%;} add{}\t{%1, %0|%0, %1}"; + snprintf (buf, sizeof (buf), default_insn, + ix86_generate_hle_prefix(operands[2])); + + return buf; }) (define_insn "atomic_sub" @@ -562,18 +600,24 @@ (clobber (reg:CC FLAGS_REG))] "" { + static char buf[128]; + const char *default_insn = "lock{%%;} %ssub{}\t{%%1, %%0|%%0, %%1}"; + if (TARGET_USE_INCDEC) { if (operands[1] == const1_rtx) - return "lock{%;} dec{}\t%0"; + default_insn = "lock{%%;} %sdec{}\t%%0"; if (operands[1] == constm1_rtx) - return "lock{%;} inc{}\t%0"; + default_insn = "lock{%%;} %sinc{}\t%%0"; } if (x86_maybe_negate_const_int (&operands[1], mode)) - return "lock{%;} add{}\t{%1, %0|%0, %1}"; + default_insn = "lock{%%;} %sadd{}\t{%%1, %%0|%%0, %%1}"; + + snprintf (buf, sizeof (buf), default_insn, + ix86_generate_hle_prefix(operands[2])); - return "lock{%;} sub{}\t{%1, %0|%0, %1}"; + return buf; }) (define_insn "atomic_" @@ -585,4 +629,11 @@ UNSPECV_LOCK)) (clobber (reg:CC FLAGS_REG))] "" - "lock{%;} {}\t{%1, %0|%0, %1}") +{ + static char buf[128]; + + snprintf (buf, sizeof (buf), + "lock{%%;} %s{}\t{%%1, %%0|%%0, %%1}", + ix86_generate_hle_prefix(operands[2])); + return buf; +}) diff --git a/gcc/configure b/gcc/configure index c1b0e46..55c3230 100755 --- a/gcc/configure +++ b/gcc/configure @@ -24628,6 +24628,39 @@ $as_echo "#define HAVE_AS_IX86_SAHF 1" >>confdefs.h fi + { $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for hle prefixies" >&5 +$as_echo_n "checking assembler for hle prefixies... " >&6; } +if test "${gcc_cv_as_ix86_hle+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + gcc_cv_as_ix86_hle=no + if test x$gcc_cv_as != x; then + $as_echo '.code64 + lock xacquire cmpxchg %esi, (%rcx) + ' > conftest.s + if { ac_try='$gcc_cv_as $gcc_cv_as_flags -o conftest.o conftest.s >&5' + { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5 + (eval $ac_try) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; } + then + gcc_cv_as_ix86_hle=yes + else + echo "configure: failed program was" >&5 + cat conftest.s >&5 + fi + rm -f conftest.o conftest.s + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_as_ix86_hle" >&5 +$as_echo "$gcc_cv_as_ix86_hle" >&6; } +if test $gcc_cv_as_ix86_hle = yes; then + +$as_echo "#define HAVE_AS_IX86_HLE 1" >>confdefs.h + +fi + { $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for swap suffix" >&5 $as_echo_n "checking assembler for swap suffix... " >&6; } if test "${gcc_cv_as_ix86_swap+set}" = set; then : diff --git a/gcc/configure.ac b/gcc/configure.ac index 8869121..a1c2c67 100644 --- a/gcc/configure.ac +++ b/gcc/configure.ac @@ -3597,6 +3597,14 @@ foo: nop [AC_DEFINE(HAVE_AS_IX86_SAHF, 1, [Define if your assembler supports the sahf mnemonic in 64bit mode.])]) + gcc_GAS_CHECK_FEATURE([hle prefixies], + gcc_cv_as_ix86_hle,,, + [.code64 + lock xacquire cmpxchg %esi, (%rcx) + ],, + [AC_DEFINE(HAVE_AS_IX86_HLE, 1, + [Define if your assembler supports HLE prefixies.])]) + gcc_GAS_CHECK_FEATURE([swap suffix], gcc_cv_as_ix86_swap,,, [movl.s %esp, %ebp],, diff --git a/gcc/testsuite/gcc.target/i386/hle-add-acq-1.c b/gcc/testsuite/gcc.target/i386/hle-add-acq-1.c new file mode 100644 index 0000000..06d3126 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/hle-add-acq-1.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-mhle" } */ +/* { dg-final { scan-assembler "lock\[ \n\t\]+\(xacquire\|\.byte\[ \t\]+0xf2\)\[ \t\n\]+add" } } */ + +void +hle_add (int *p, int v) +{ + __atomic_fetch_add (p, v, __ATOMIC_ACQUIRE | __ATOMIC_HLE_ACQUIRE); +} diff --git a/gcc/testsuite/gcc.target/i386/hle-add-rel-1.c b/gcc/testsuite/gcc.target/i386/hle-add-rel-1.c new file mode 100644 index 0000000..d9f29b9 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/hle-add-rel-1.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-mhle" } */ +/* { dg-final { scan-assembler "lock\[ \n\t\]+\(xrelease\|\.byte\[ \t\]+0xf2\)\[ \t\n\]+add" } } */ + +void +hle_add (int *p, int v) +{ + __atomic_fetch_add (p, v, __ATOMIC_ACQUIRE | __ATOMIC_HLE_RELEASE); +} diff --git a/gcc/testsuite/gcc.target/i386/hle-and-acq-1.c b/gcc/testsuite/gcc.target/i386/hle-and-acq-1.c new file mode 100644 index 0000000..321aa4e --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/hle-and-acq-1.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-mhle" } */ +/* { dg-final { scan-assembler "lock\[ \n\t\]+\(xacquire\|\.byte\[ \t\]+0xf2\)\[ \t\n\]+and" } } */ + +void +hle_and (int *p, int v) +{ + __atomic_fetch_and (p, v, __ATOMIC_ACQUIRE | __ATOMIC_HLE_ACQUIRE); +} diff --git a/gcc/testsuite/gcc.target/i386/hle-and-rel-1.c b/gcc/testsuite/gcc.target/i386/hle-and-rel-1.c new file mode 100644 index 0000000..eceb200 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/hle-and-rel-1.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-mhle" } */ +/* { dg-final { scan-assembler "lock\[ \n\t\]+\(xrelease\|\.byte\[ \t\]+0xf3\)\[ \t\n\]+and" } } */ + +void +hle_and (int *p, int v) +{ + __atomic_fetch_and (p, v, __ATOMIC_ACQUIRE | __ATOMIC_HLE_RELEASE); +} diff --git a/gcc/testsuite/gcc.target/i386/hle-cmpxchg-acq-1.c b/gcc/testsuite/gcc.target/i386/hle-cmpxchg-acq-1.c new file mode 100644 index 0000000..8b43e54 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/hle-cmpxchg-acq-1.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-mhle" } */ +/* { dg-final { scan-assembler "lock\[ \n\t\]+\(xacquire\|\.byte\[ \t\]+0xf2\)\[ \t\n\]+cmpxchg" } } */ + +int +hle_cmpxchg (int *p, int oldv, int newv) +{ + return __atomic_compare_exchange_n (p, &oldv, newv, 0, __ATOMIC_ACQUIRE | __ATOMIC_HLE_ACQUIRE, __ATOMIC_ACQUIRE); +} diff --git a/gcc/testsuite/gcc.target/i386/hle-cmpxchg-rel-1.c b/gcc/testsuite/gcc.target/i386/hle-cmpxchg-rel-1.c new file mode 100644 index 0000000..8549542 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/hle-cmpxchg-rel-1.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-mhle" } */ +/* { dg-final { scan-assembler "lock\[ \n\t\]+\(xrelease\|\.byte\[ \t\]+0xf3\)\[ \t\n\]+cmpxchg" } } */ + +int +hle_cmpxchg (int *p, int oldv, int newv) +{ + return __atomic_compare_exchange_n (p, &oldv, newv, 0, __ATOMIC_RELEASE | __ATOMIC_HLE_RELEASE, __ATOMIC_ACQUIRE); +} diff --git a/gcc/testsuite/gcc.target/i386/hle-or-acq-1.c b/gcc/testsuite/gcc.target/i386/hle-or-acq-1.c new file mode 100644 index 0000000..b742993 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/hle-or-acq-1.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-mhle" } */ +/* { dg-final { scan-assembler "lock\[ \n\t\]+\(xacquire\|\.byte\[ \t\]+0xf2\)\[ \t\n\]+or" } } */ + +void +hle_or (int *p, int v) +{ + __atomic_or_fetch (p, 1, __ATOMIC_ACQUIRE | __ATOMIC_HLE_ACQUIRE); +} diff --git a/gcc/testsuite/gcc.target/i386/hle-or-rel-1.c b/gcc/testsuite/gcc.target/i386/hle-or-rel-1.c new file mode 100644 index 0000000..93e0017 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/hle-or-rel-1.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-mhle" } */ +/* { dg-final { scan-assembler "lock\[ \n\t\]+\(xrelease\|\.byte\[ \t\]+0xf3\)\[ \t\n\]+or" } } */ + +void +hle_xor (int *p, int v) +{ + __atomic_fetch_or (p, v, __ATOMIC_ACQUIRE | __ATOMIC_HLE_RELEASE); +} diff --git a/gcc/testsuite/gcc.target/i386/hle-sub-acq-1.c b/gcc/testsuite/gcc.target/i386/hle-sub-acq-1.c new file mode 100644 index 0000000..c9efa4a --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/hle-sub-acq-1.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-mhle" } */ +/* { dg-final { scan-assembler "lock\[ \n\t\]+\(xacquire\|\.byte\[ \t\]+0xf2\)\[ \t\n\]+sub" } } */ + +void +hle_sub (int *p, int v) +{ + __atomic_fetch_sub (p, v, __ATOMIC_ACQUIRE | __ATOMIC_HLE_ACQUIRE); +} diff --git a/gcc/testsuite/gcc.target/i386/hle-sub-rel-1.c b/gcc/testsuite/gcc.target/i386/hle-sub-rel-1.c new file mode 100644 index 0000000..b9dae1b --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/hle-sub-rel-1.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-mhle" } */ +/* { dg-final { scan-assembler "lock\[ \n\t\]+\(xrelease\|\.byte\[ \t\]+0xf2\)\[ \t\n\]+sub" } } */ + +void +hle_sub (int *p, int v) +{ + __atomic_fetch_sub (p, v, __ATOMIC_ACQUIRE | __ATOMIC_HLE_RELEASE); +} diff --git a/gcc/testsuite/gcc.target/i386/hle-xadd-acq-1.c b/gcc/testsuite/gcc.target/i386/hle-xadd-acq-1.c new file mode 100644 index 0000000..b4f1e22 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/hle-xadd-acq-1.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-mhle" } */ +/* { dg-final { scan-assembler "lock\[ \n\t\]+\(xacquire\|\.byte\[ \t\]+0xf2\)\[ \t\n\]+xadd" } } */ + +int +hle_xadd (int *p, int v) +{ + return __atomic_fetch_add (p, v, __ATOMIC_ACQUIRE | __ATOMIC_HLE_ACQUIRE); +} diff --git a/gcc/testsuite/gcc.target/i386/hle-xadd-rel-1.c b/gcc/testsuite/gcc.target/i386/hle-xadd-rel-1.c new file mode 100644 index 0000000..3bbd706 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/hle-xadd-rel-1.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-mhle" } */ +/* { dg-final { scan-assembler "lock\[ \n\t\]+\(xrelease\|\.byte\[ \t\]+0xf2\)\[ \t\n\]+xadd" } } */ + +int +hle_xadd (int *p, int v) +{ + return __atomic_fetch_add (p, v, __ATOMIC_ACQUIRE | __ATOMIC_HLE_RELEASE); +} diff --git a/gcc/testsuite/gcc.target/i386/hle-xchg-acq-1.c b/gcc/testsuite/gcc.target/i386/hle-xchg-acq-1.c new file mode 100644 index 0000000..441c454 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/hle-xchg-acq-1.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-mhle" } */ +/* { dg-final { scan-assembler "\[ \n\t\]+\(xacquire\|\.byte\[ \t\]+0xf2\)\[ \t\n\]+xchg" } } */ + +int +hle_xchg (int *p, int v) +{ + return __atomic_exchange_n (p, v, __ATOMIC_ACQUIRE | __ATOMIC_HLE_ACQUIRE); +} diff --git a/gcc/testsuite/gcc.target/i386/hle-xchg-rel-1.c b/gcc/testsuite/gcc.target/i386/hle-xchg-rel-1.c new file mode 100644 index 0000000..9993596 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/hle-xchg-rel-1.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-mhle" } */ +/* { dg-final { scan-assembler "\[ \n\t\]+\(xrelease\|\.byte\[ \t\]+0xf2\)\[ \t\n\]+xchg" } } */ + +int +hle_xchg (int *p, int v) +{ + return __atomic_exchange_n (p, v, __ATOMIC_ACQUIRE | __ATOMIC_HLE_RELEASE); +} diff --git a/gcc/testsuite/gcc.target/i386/hle-xor-acq-1.c b/gcc/testsuite/gcc.target/i386/hle-xor-acq-1.c new file mode 100644 index 0000000..f219b58 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/hle-xor-acq-1.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-mhle" } */ +/* { dg-final { scan-assembler "lock\[ \n\t\]+\(xacquire\|\.byte\[ \t\]+0xf2\)\[ \t\n\]+xor" } } */ + +void +hle_xor (int *p, int v) +{ + __atomic_fetch_xor (p, v, __ATOMIC_ACQUIRE | __ATOMIC_HLE_ACQUIRE); +} diff --git a/gcc/testsuite/gcc.target/i386/hle-xor-rel-1.c b/gcc/testsuite/gcc.target/i386/hle-xor-rel-1.c new file mode 100644 index 0000000..2fb9ec5 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/hle-xor-rel-1.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-mhle" } */ +/* { dg-final { scan-assembler "lock\[ \n\t\]+\(xrelease\|\.byte\[ \t\]+0xf3\)\[ \t\n\]+xor" } } */ + +void +hle_xor (int *p, int v) +{ + __atomic_fetch_xor (p, v, __ATOMIC_ACQUIRE | __ATOMIC_HLE_RELEASE); +}