From: Jan Beulich <jbeulich@suse.com>
To: Binutils <binutils@sourceware.org>
Cc: Palmer Dabbelt <palmer@dabbelt.com>,
Andrew Waterman <andrew@sifive.com>,
Jim Wilson <jim.wilson.gcc@gmail.com>,
Nelson Chu <nelson@rivosinc.com>
Subject: [PATCH 2/2] RISC-V: reduce redundancy in sign/zero extension macro insn handling
Date: Fri, 3 Nov 2023 13:57:23 +0100 [thread overview]
Message-ID: <b3b74bf8-da41-1016-2294-37d246d78ecb@suse.com> (raw)
In-Reply-To: <8255d3af-23e4-054d-be6c-28fae6a76ea0@suse.com>
Fold M_{S,Z}EXTH, deriving signed-ness from the incoming mnemonic. Fold
riscv_ext()'s calls md_assemblef(), the first of which were entirely
identical, while the other pair differed in just a single character.
--- a/gas/config/tc-riscv.c
+++ b/gas/config/tc-riscv.c
@@ -1942,16 +1942,9 @@ load_const (int reg, expressionS *ep)
static void
riscv_ext (int destreg, int srcreg, unsigned shift, bool sign)
{
- if (sign)
- {
- md_assemblef ("slli x%d, x%d, 0x%x", destreg, srcreg, shift);
- md_assemblef ("srai x%d, x%d, 0x%x", destreg, destreg, shift);
- }
- else
- {
- md_assemblef ("slli x%d, x%d, 0x%x", destreg, srcreg, shift);
- md_assemblef ("srli x%d, x%d, 0x%x", destreg, destreg, shift);
- }
+ md_assemblef ("slli x%d, x%d, %#x", destreg, srcreg, shift);
+ md_assemblef ("sr%ci x%d, x%d, %#x",
+ sign ? 'a' : 'l', destreg, destreg, shift);
}
/* Expand RISC-V Vector macros into one or more instructions. */
@@ -2075,8 +2068,8 @@ macro (struct riscv_cl_insn *ip, express
riscv_call (rd, rs1, imm_expr, *imm_reloc);
break;
- case M_ZEXTH:
- riscv_ext (rd, rs1, xlen - 16, false);
+ case M_EXTH:
+ riscv_ext (rd, rs1, xlen - 16, *ip->insn_mo->name == 's');
break;
case M_ZEXTW:
@@ -2087,10 +2080,6 @@ macro (struct riscv_cl_insn *ip, express
riscv_ext (rd, rs1, xlen - 8, true);
break;
- case M_SEXTH:
- riscv_ext (rd, rs1, xlen - 16, true);
- break;
-
case M_VMSGE:
vector_macro (ip);
break;
--- a/include/opcode/riscv.h
+++ b/include/opcode/riscv.h
@@ -544,10 +544,9 @@ enum
M_CALL,
M_J,
M_LI,
- M_ZEXTH,
+ M_EXTH,
M_ZEXTW,
M_SEXTB,
- M_SEXTH,
M_VMSGE,
M_NUM_MACROS
};
--- a/opcodes/riscv-opc.c
+++ b/opcodes/riscv-opc.c
@@ -1042,11 +1042,11 @@ const struct riscv_opcode riscv_opcodes[
{"sext.b", 0, INSN_CLASS_I, "d,s", 0, (int) M_SEXTB, NULL, INSN_MACRO },
{"sext.h", 0, INSN_CLASS_ZCB_AND_ZBB, "Cs,Cw", MATCH_C_SEXT_H, MASK_C_SEXT_H, match_opcode, INSN_ALIAS },
{"sext.h", 0, INSN_CLASS_ZBB, "d,s", MATCH_SEXT_H, MASK_SEXT_H, match_opcode, 0 },
-{"sext.h", 0, INSN_CLASS_I, "d,s", 0, (int) M_SEXTH, NULL, INSN_MACRO },
+{"sext.h", 0, INSN_CLASS_I, "d,s", 0, (int) M_EXTH, NULL, INSN_MACRO },
{"zext.h", 0, INSN_CLASS_ZCB_AND_ZBB, "Cs,Cw", MATCH_C_ZEXT_H, MASK_C_ZEXT_H, match_opcode, INSN_ALIAS },
{"zext.h", 32, INSN_CLASS_ZBB, "d,s", MATCH_PACK, MASK_PACK | MASK_RS2, match_opcode, 0 },
{"zext.h", 64, INSN_CLASS_ZBB, "d,s", MATCH_PACKW, MASK_PACKW | MASK_RS2, match_opcode, 0 },
-{"zext.h", 0, INSN_CLASS_I, "d,s", 0, (int) M_ZEXTH, NULL, INSN_MACRO },
+{"zext.h", 0, INSN_CLASS_I, "d,s", 0, (int) M_EXTH, NULL, INSN_MACRO },
{"orc.b", 0, INSN_CLASS_ZBB, "d,s", MATCH_GORCI | MATCH_SHAMT_ORC_B, MASK_GORCI | MASK_SHAMT, match_opcode, 0 },
{"clzw", 64, INSN_CLASS_ZBB, "d,s", MATCH_CLZW, MASK_CLZW, match_opcode, 0 },
{"ctzw", 64, INSN_CLASS_ZBB, "d,s", MATCH_CTZW, MASK_CTZW, match_opcode, 0 },
next prev parent reply other threads:[~2023-11-03 12:57 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-03 12:55 [PATCH 0/2] RISC-V: a little more macro insn handling adjusting Jan Beulich
2023-11-03 12:56 ` [PATCH 1/2] RISC-V: disallow x0 with certain macro-insns Jan Beulich
2023-11-24 8:59 ` Christoph Müllner
2023-11-24 9:10 ` Jan Beulich
2023-11-03 12:57 ` Jan Beulich [this message]
2023-11-17 10:18 ` [PATCH 0/2] RISC-V: a little more macro insn handling adjusting Jan Beulich
2023-11-22 0:26 ` Palmer Dabbelt
2023-11-22 0:39 ` Andrew Waterman
2023-11-22 7:59 ` Jan Beulich
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=b3b74bf8-da41-1016-2294-37d246d78ecb@suse.com \
--to=jbeulich@suse.com \
--cc=andrew@sifive.com \
--cc=binutils@sourceware.org \
--cc=jim.wilson.gcc@gmail.com \
--cc=nelson@rivosinc.com \
--cc=palmer@dabbelt.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).