From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1118) id 2A98F3858D39; Mon, 27 Dec 2021 17:56:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2A98F3858D39 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: John David Anglin To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-6125] Improve atomic store implementation on hppa-linux. X-Act-Checkin: gcc X-Git-Author: John David Anglin X-Git-Refname: refs/heads/master X-Git-Oldrev: 916ec36d0a3ef3fe44c1657746922a5f18b60326 X-Git-Newrev: ea8b5640551ee7cbecf5c3ce30f0268963de3039 Message-Id: <20211227175650.2A98F3858D39@sourceware.org> Date: Mon, 27 Dec 2021 17:56:50 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 27 Dec 2021 17:56:50 -0000 https://gcc.gnu.org/g:ea8b5640551ee7cbecf5c3ce30f0268963de3039 commit r12-6125-gea8b5640551ee7cbecf5c3ce30f0268963de3039 Author: John David Anglin Date: Mon Dec 27 17:56:19 2021 +0000 Improve atomic store implementation on hppa-linux. 2021-12-27 John David Anglin gcc/ChangeLog: * config/pa/pa-protos.h: Delete pa_maybe_emit_compare_and_swap_exchange_loop() declaration. * config/pa/pa.c (pa_expand_compare_and_swap_loop): Delete. (pa_maybe_emit_compare_and_swap_exchange_loop): Delete. * config/pa/pa.md (atomic_storeq): Use __sync_lock_test_and_set instead of pa_maybe_emit_compare_and_swap_exchange_loop. (atomic_storehi, atomic_storesi, atomic_storedi): Likewise. Diff: --- gcc/config/pa/pa-protos.h | 1 - gcc/config/pa/pa.c | 76 ----------------------------------------------- gcc/config/pa/pa.md | 40 +++++++++++++++---------- 3 files changed, 24 insertions(+), 93 deletions(-) diff --git a/gcc/config/pa/pa-protos.h b/gcc/config/pa/pa-protos.h index 5bf6fef4968..69377db45c5 100644 --- a/gcc/config/pa/pa-protos.h +++ b/gcc/config/pa/pa-protos.h @@ -73,7 +73,6 @@ extern rtx pa_return_addr_rtx (int, rtx); extern int pa_insn_refs_are_delayed (rtx_insn *); extern rtx pa_get_deferred_plabel (rtx); -extern rtx pa_maybe_emit_compare_and_swap_exchange_loop (rtx, rtx, rtx); #endif /* RTX_CODE */ extern int pa_and_mask_p (unsigned HOST_WIDE_INT); diff --git a/gcc/config/pa/pa.c b/gcc/config/pa/pa.c index 2b10ef34061..895978aea1c 100644 --- a/gcc/config/pa/pa.c +++ b/gcc/config/pa/pa.c @@ -11023,82 +11023,6 @@ pa_output_addr_diff_vec (rtx lab, rtx body) fputs ("\t.end_brtab\n", asm_out_file); } -/* This is a helper function for the other atomic operations. This function - emits a loop that contains SEQ that iterates until a compare-and-swap - operation at the end succeeds. MEM is the memory to be modified. SEQ is - a set of instructions that takes a value from OLD_REG as an input and - produces a value in NEW_REG as an output. Before SEQ, OLD_REG will be - set to the current contents of MEM. After SEQ, a compare-and-swap will - attempt to update MEM with NEW_REG. The function returns true when the - loop was generated successfully. */ - -static bool -pa_expand_compare_and_swap_loop (rtx mem, rtx old_reg, rtx new_reg, rtx seq) -{ - machine_mode mode = GET_MODE (mem); - rtx_code_label *label; - rtx cmp_reg, success, oldval; - - /* The loop we want to generate looks like - - cmp_reg = mem; - label: - old_reg = cmp_reg; - seq; - (success, cmp_reg) = compare-and-swap(mem, old_reg, new_reg) - if (success) - goto label; - - Note that we only do the plain load from memory once. Subsequent - iterations use the value loaded by the compare-and-swap pattern. */ - - label = gen_label_rtx (); - cmp_reg = gen_reg_rtx (mode); - - emit_move_insn (cmp_reg, mem); - emit_label (label); - emit_move_insn (old_reg, cmp_reg); - if (seq) - emit_insn (seq); - - success = NULL_RTX; - oldval = cmp_reg; - if (!expand_atomic_compare_and_swap (&success, &oldval, mem, old_reg, - new_reg, false, MEMMODEL_SYNC_SEQ_CST, - MEMMODEL_RELAXED)) - return false; - - if (oldval != cmp_reg) - emit_move_insn (cmp_reg, oldval); - - /* Mark this jump predicted not taken. */ - emit_cmp_and_jump_insns (success, const0_rtx, EQ, const0_rtx, - GET_MODE (success), 1, label, - profile_probability::guessed_never ()); - return true; -} - -/* This function tries to implement an atomic exchange operation using a - compare_and_swap loop. VAL is written to *MEM. The previous contents of - *MEM are returned, using TARGET if possible. No memory model is required - since a compare_and_swap loop is seq-cst. */ - -rtx -pa_maybe_emit_compare_and_swap_exchange_loop (rtx target, rtx mem, rtx val) -{ - machine_mode mode = GET_MODE (mem); - - if (can_compare_and_swap_p (mode, true)) - { - if (!target || !register_operand (target, mode)) - target = gen_reg_rtx (mode); - if (pa_expand_compare_and_swap_loop (mem, target, val, NULL_RTX)) - return target; - } - - return NULL_RTX; -} - /* Implement TARGET_CALLEE_COPIES. The callee is responsible for copying arguments passed by hidden reference in the 32-bit HP runtime. Users can override this behavior for better compatibility with openmp at the diff --git a/gcc/config/pa/pa.md b/gcc/config/pa/pa.md index f124c301b7a..af5449a9ea3 100644 --- a/gcc/config/pa/pa.md +++ b/gcc/config/pa/pa.md @@ -10366,10 +10366,12 @@ add,l %2,%3,%3\;bv,n %%r0(%3)" { if (TARGET_SYNC_LIBCALL) { - rtx mem = operands[0]; - rtx val = operands[1]; - if (pa_maybe_emit_compare_and_swap_exchange_loop (NULL_RTX, mem, val)) - DONE; + rtx libfunc = init_one_libfunc ("__sync_lock_test_and_set_1"); + + emit_library_call (libfunc, LCT_NORMAL, VOIDmode, + XEXP (operands[0], 0), Pmode, + operands[1], QImode); + DONE; } FAIL; }) @@ -10384,10 +10386,12 @@ add,l %2,%3,%3\;bv,n %%r0(%3)" { if (TARGET_SYNC_LIBCALL) { - rtx mem = operands[0]; - rtx val = operands[1]; - if (pa_maybe_emit_compare_and_swap_exchange_loop (NULL_RTX, mem, val)) - DONE; + rtx libfunc = init_one_libfunc ("__sync_lock_test_and_set_2"); + + emit_library_call (libfunc, LCT_NORMAL, VOIDmode, + XEXP (operands[0], 0), Pmode, + operands[1], HImode); + DONE; } FAIL; }) @@ -10402,10 +10406,12 @@ add,l %2,%3,%3\;bv,n %%r0(%3)" { if (TARGET_SYNC_LIBCALL) { - rtx mem = operands[0]; - rtx val = operands[1]; - if (pa_maybe_emit_compare_and_swap_exchange_loop (NULL_RTX, mem, val)) - DONE; + rtx libfunc = init_one_libfunc ("__sync_lock_test_and_set_4"); + + emit_library_call (libfunc, LCT_NORMAL, VOIDmode, + XEXP (operands[0], 0), Pmode, + operands[1], SImode); + DONE; } FAIL; }) @@ -10453,10 +10459,12 @@ add,l %2,%3,%3\;bv,n %%r0(%3)" if (TARGET_SYNC_LIBCALL) { - rtx mem = operands[0]; - rtx val = operands[1]; - if (pa_maybe_emit_compare_and_swap_exchange_loop (NULL_RTX, mem, val)) - DONE; + rtx libfunc = init_one_libfunc ("__sync_lock_test_and_set_8"); + + emit_library_call (libfunc, LCT_NORMAL, VOIDmode, + XEXP (operands[0], 0), Pmode, + operands[1], DImode); + DONE; } if (TARGET_64BIT || TARGET_SOFT_FLOAT)