From: Jan Beulich <jbeulich@suse.com>
To: Binutils <binutils@sourceware.org>
Cc: "H.J. Lu" <hjl.tools@gmail.com>
Subject: [PATCH 5/8] x86: avoid strcmp() in a few places
Date: Fri, 13 Jan 2023 12:08:33 +0100 [thread overview]
Message-ID: <c60483a9-14fc-f2f4-0185-80c2510e45a5@suse.com> (raw)
In-Reply-To: <beeaf9c6-7d1e-bcc6-624a-918c4a6c293e@suse.com>
Now that we have identifiers for the mnemonic strings we can avoid
strcmp() in a number of places, comparing the offsets into the mnemonic
string table instead. While doing this also
- convert a leftover strncmp() to startswith() (apparently an oversight
when rebasing the original patch introducing the startswith() uses),
- use the new shorthand for current_templates->start also elsewhere in
md_assemble() (valid up to the point where match_template() is
called).
---
There are likely further opportunities for improvement, in particular
when currently comparing opcode space + opcode: E.g. in want_disp32()
we could instead compare against MN_lea, at once improving readability.
Thoughts?
--- a/gas/config/tc-i386.c
+++ b/gas/config/tc-i386.c
@@ -4550,7 +4550,7 @@ load_insn_p (void)
return 0;
/* pop. */
- if (strcmp (insn_name (&i.tm), "pop") == 0)
+ if (i.tm.mnem_off == MN_pop)
return 1;
}
@@ -4919,7 +4919,8 @@ md_assemble (char *line)
}
return;
}
- if (may_need_pass2 (current_templates->start))
+ t = current_templates->start;
+ if (may_need_pass2 (t))
{
/* Make a copy of the full line in case we need to retry. */
copy = xstrdup (line);
@@ -4946,14 +4947,14 @@ md_assemble (char *line)
AT&T modes. */
if (intel_syntax
&& i.operands > 1
- && (strcmp (mnemonic, "bound") != 0)
- && (strncmp (mnemonic, "invlpg", 6) != 0)
+ && (t->mnem_off != MN_bound)
+ && !startswith (mnemonic, "invlpg")
&& !startswith (mnemonic, "monitor")
&& !startswith (mnemonic, "mwait")
- && (strcmp (mnemonic, "pvalidate") != 0)
+ && (t->mnem_off != MN_pvalidate)
&& !startswith (mnemonic, "rmp")
- && (strcmp (mnemonic, "tpause") != 0)
- && (strcmp (mnemonic, "umwait") != 0)
+ && (t->mnem_off != MN_tpause)
+ && (t->mnem_off != MN_umwait)
&& !(i.operands == 2
&& operand_type_check (i.types[0], imm)
&& operand_type_check (i.types[1], imm)))
@@ -4962,15 +4963,14 @@ md_assemble (char *line)
/* The order of the immediates should be reversed
for 2 immediates extrq and insertq instructions */
if (i.imm_operands == 2
- && (strcmp (mnemonic, "extrq") == 0
- || strcmp (mnemonic, "insertq") == 0))
+ && (t->mnem_off == MN_extrq || t->mnem_off == MN_insertq))
swap_2_operands (0, 1);
if (i.imm_operands)
optimize_imm ();
- if (i.disp_operands && !want_disp32 (current_templates->start)
- && (!current_templates->start->opcode_modifier.jump
+ if (i.disp_operands && !want_disp32 (t)
+ && (!t->opcode_modifier.jump
|| i.jumpabsolute || i.types[0].bitfield.baseindex))
{
for (j = 0; j < i.operands; ++j)
next prev parent reply other threads:[~2023-01-13 11:08 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-13 11:04 [PATCH 0/8] x86: mnemonic and register string literals Jan Beulich
2023-01-13 11:05 ` [PATCH 1/8] x86: abstract out obtaining of a template's mnemonic Jan Beulich
2023-01-13 11:06 ` [PATCH 1/8] x86: move insn mnemonics to a separate table Jan Beulich
2023-01-13 11:12 ` Jan Beulich
2023-01-13 11:07 ` [PATCH 3/8] x86: re-use insn mnemonic strings as much as possible Jan Beulich
2023-01-13 11:07 ` [PATCH 4/8] x86: absorb allocation in i386-gen Jan Beulich
2023-01-13 11:08 ` Jan Beulich [this message]
2023-01-13 11:10 ` [PATCH 6/8] x86: embed register names in reg_entry Jan Beulich
2023-01-13 11:11 ` [PATCH 7/8] x86: embed register and alike names in disassembler Jan Beulich
2023-01-13 11:11 ` [PATCH 8/8] x86: split i386-gen's opcode hash entry struct 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=c60483a9-14fc-f2f4-0185-80c2510e45a5@suse.com \
--to=jbeulich@suse.com \
--cc=binutils@sourceware.org \
--cc=hjl.tools@gmail.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).