From: Kito Cheng <kito.cheng@gmail.com>
To: Palmer Dabbelt <palmer@rivosinc.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>,
"Patrick O'Neill" <patrick@rivosinc.com>
Subject: Re: [PATCH v4] RISC-V: Add support for inlining subword atomic operations
Date: Fri, 2 Sep 2022 18:08:04 +0800 [thread overview]
Message-ID: <CA+yXCZCyfqpYcj4vvijJEZ6LN1uFA0mwq6s0CaC4Mj8rgkeCLA@mail.gmail.com> (raw)
In-Reply-To: <20220821215823.18207-1-palmer@rivosinc.com>
LGTM with minor comments, it's time to move forward, thanks Patrick and Palmer.
> +
> +void
> +riscv_subword_address (rtx mem, rtx *aligned_mem, rtx *shift, rtx *mask,
> + rtx *not_mask)
> +{
> + /* Align the memory addess to a word. */
> + rtx addr = force_reg (Pmode, XEXP (mem, 0));
> +
> + rtx aligned_addr = gen_reg_rtx (Pmode);
> + emit_move_insn (aligned_addr, gen_rtx_AND (Pmode, addr,
> + gen_int_mode (-4, Pmode)));
> +
> + *aligned_mem = change_address (mem, SImode, aligned_addr);
> +
> + /* Calculate the shift amount. */
> + *shift = gen_reg_rtx (SImode);
Already allocated reg_rtx outside, this line could be removed.
> + emit_move_insn (*shift, gen_rtx_AND (SImode, gen_lowpart (SImode, addr),
> + gen_int_mode (3, SImode)));
> + emit_move_insn (*shift, gen_rtx_ASHIFT (SImode, *shift,
> + gen_int_mode(3, SImode)));
> +
> + /* Calculate the mask. */
> + int unshifted_mask;
> + if (GET_MODE (mem) == QImode)
> + unshifted_mask = 0xFF;
> + else
> + unshifted_mask = 0xFFFF;
> +
> + rtx mask_reg = gen_reg_rtx (SImode);
Ditto.
> @@ -152,6 +348,128 @@
> DONE;
> })
>
> +(define_expand "atomic_compare_and_swap<mode>"
> + [(match_operand:SI 0 "register_operand" "") ;; bool output
> + (match_operand:SHORT 1 "register_operand" "") ;; val output
> + (match_operand:SHORT 2 "memory_operand" "") ;; memory
> + (match_operand:SHORT 3 "reg_or_0_operand" "") ;; expected value
> + (match_operand:SHORT 4 "reg_or_0_operand" "") ;; desired value
> + (match_operand:SI 5 "const_int_operand" "") ;; is_weak
> + (match_operand:SI 6 "const_int_operand" "") ;; mod_s
> + (match_operand:SI 7 "const_int_operand" "")] ;; mod_f
> + "TARGET_ATOMIC && TARGET_INLINE_SUBWORD_ATOMIC"
> +{
> + emit_insn (gen_atomic_cas_value_strong<mode> (operands[1], operands[2],
> + operands[3], operands[4],
> + operands[6], operands[7]));
> +
> + rtx val = gen_reg_rtx (SImode);
> + if (operands[1] != const0_rtx)
> + emit_insn (gen_rtx_SET (val, gen_rtx_SIGN_EXTEND (SImode, operands[1])));
> + else
> + emit_insn (gen_rtx_SET (val, const0_rtx));
nit: emit_move_insn rather than emit_insn + gen_rtx_SET
> +
> + rtx exp = gen_reg_rtx (SImode);
> + if (operands[3] != const0_rtx)
> + emit_insn (gen_rtx_SET (exp, gen_rtx_SIGN_EXTEND (SImode, operands[3])));
> + else
> + emit_insn (gen_rtx_SET (exp, const0_rtx));
nit: emit_move_insn rather than emit_insn + gen_rtx_SET
> +
> + rtx compare = val;
> + if (exp != const0_rtx)
> + {
> + rtx difference = gen_rtx_MINUS (SImode, val, exp);
> + compare = gen_reg_rtx (SImode);
> + emit_insn (gen_rtx_SET (compare, difference));
nit: emit_move_insn rather than emit_insn + gen_rtx_SET
> + }
> +
> + if (word_mode != SImode)
> + {
> + rtx reg = gen_reg_rtx (word_mode);
> + emit_insn (gen_rtx_SET (reg, gen_rtx_SIGN_EXTEND (word_mode, compare)));
nit: emit_move_insn rather than emit_insn + gen_rtx_SET
> + compare = reg;
> + }
> +
> + emit_insn (gen_rtx_SET (operands[0], gen_rtx_EQ (SImode, compare, const0_rtx)));
nit: emit_move_insn rather than emit_insn + gen_rtx_SET
next prev parent reply other threads:[~2022-09-02 10:08 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-21 21:58 Palmer Dabbelt
2022-09-02 10:08 ` Kito Cheng [this message]
2022-10-28 16:55 ` David Abdurachmanov
2022-11-16 3:53 ` Jeff Law
2023-04-18 14:28 ` [PATCH v5] RISCV: Inline subword atomic ops Patrick O'Neill
2023-04-18 15:06 ` Andreas Schwab
2023-04-18 16:39 ` [PATCH v6] " Patrick O'Neill
2023-04-18 20:17 ` Palmer Dabbelt
2023-04-18 21:41 ` [PATCH v7] " Patrick O'Neill
2023-04-24 17:20 ` Patrick O'Neill
2023-04-25 5:52 ` Jeff Law
2023-04-25 15:20 ` Patrick O'Neill
2023-04-26 2:27 ` Jeff Law
2023-04-26 17:01 ` [committed] " Patrick O'Neill
2023-05-02 20:34 ` Patrick O'Neill
2023-05-03 6:32 ` Jeff Law
2023-05-03 9:49 ` Richard Biener
2023-05-03 14:14 ` Palmer Dabbelt
2023-05-03 15:13 ` Jeff Law
2023-05-03 15:33 ` Palmer Dabbelt
2023-05-03 16:13 ` Patrick O'Neill
2023-04-18 16:59 ` [PATCH v5] " Jeff Law
2023-04-18 20:48 ` Patrick O'Neill
2023-04-18 21:04 ` Jeff Law
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CA+yXCZCyfqpYcj4vvijJEZ6LN1uFA0mwq6s0CaC4Mj8rgkeCLA@mail.gmail.com \
--to=kito.cheng@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=palmer@rivosinc.com \
--cc=patrick@rivosinc.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).