From patchwork Mon Dec 27 18:06:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John David Anglin X-Patchwork-Id: 49282 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F0EA83858426 for ; Mon, 27 Dec 2021 18:06:38 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from cmx-torrgo001.bell.net (mta-tor-002.bell.net [209.71.212.29]) by sourceware.org (Postfix) with ESMTP id 11DFD3858D39 for ; Mon, 27 Dec 2021 18:06:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 11DFD3858D39 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=bell.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=bell.net X-RG-CM-BuS: 0 X-RG-CM-SC: 0 X-RG-CM: Clean X-Originating-IP: [67.71.8.137] X-RG-Env-Sender: dave.anglin@bell.net X-RG-Rigid: 61C63178003AA718 X-CM-Envelope: MS4xfBWxKc8h3GUF38hOmG4G+7/HmOWjhdHkHUXm7ICzflqOstjkPazrnup5zzVVWw6xgiCXVvfbi7LEEc70QxbtfAVXw81sdQEJ9VaAW6ypYTMGQ/FqEgBt dHdB97Fsj+YO+t9EXEA7Hc50rcQ7z73vWXHDiqHPaF0WyJ5mjVs1nKXnrN1RWTETNCoaFo2WtSpNKMZLgZe1x6P3JRFM1wjewuoVs5BrNckGOvXbImKBv8S3 iP0wKEu3QVWaKzf4w6pyM9x9LJZAbPf5iyNTdEfBUvdgkjo9MQ+qyb7Q26pXY2O1Za/JrySNZXuJkLyZfQFR7qVgl5Vo1YyeeklOB+hseqc= X-CM-Analysis: v=2.4 cv=f44ruM+M c=1 sm=1 tr=0 ts=61ca009b a=jrdA9tB8yuRqUzQ1EpSZjA==:117 a=jrdA9tB8yuRqUzQ1EpSZjA==:17 a=IOMw9HtfNCkA:10 a=mDV3o1hIAAAA:8 a=YaBqbVrlLDlsidjM1GEA:9 a=CjuIK1q_8ugA:10 a=i_vZj-vN0442tUa0AT8A:9 a=FfaGCDsud1wA:10 a=_FVE-zBwftR9WsbkzFJk:22 Received: from mx3210.localdomain (67.71.8.137) by cmx-torrgo001.bell.net (5.8.716.03) (authenticated as dave.anglin@bell.net) id 61C63178003AA718; Mon, 27 Dec 2021 13:06:19 -0500 Received: by mx3210.localdomain (Postfix, from userid 1000) id C9C05220117; Mon, 27 Dec 2021 18:06:18 +0000 (UTC) Date: Mon, 27 Dec 2021 18:06:18 +0000 From: John David Anglin To: GCC Patches Subject: [committed] hppa: Improve atomic store implementation on hppa-linux Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-9.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Atomic stores on hppa-linux must be synthesized using the kernel light-weight system calls. Instead of using a compare and swap loop, it is more efficient to use the __sync_lock_test_and_set routines in libgcc. Tested on hppa-unknown-linux-gnu. Committed to trunk and gcc-11. Dave --- 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 --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)