From: Jan Beulich <jbeulich@suse.com>
To: Binutils <binutils@sourceware.org>
Cc: "H.J. Lu" <hjl.tools@gmail.com>
Subject: [PATCH 4/8] x86: absorb allocation in i386-gen
Date: Fri, 13 Jan 2023 12:07:46 +0100 [thread overview]
Message-ID: <8f43bf06-9323-8838-bcdc-bfbf9a850ae2@suse.com> (raw)
In-Reply-To: <beeaf9c6-7d1e-bcc6-624a-918c4a6c293e@suse.com>
When generating the mnemonic string table we already set up an
identifier for the following entry in a number of cases. Re-use that on
the next loop iteration rather than re-doing allocation and conversion.
---
Could also be folded directly into "x86: re-use insn mnemonic strings as
much as possible"; separate for now to keep the earlier change a little
more simple.
--- a/opcodes/i386-gen.c
+++ b/opcodes/i386-gen.c
@@ -1750,13 +1750,15 @@ process_i386_opcodes (FILE *table)
fprintf (table, "const char i386_mnemonics[] =\n");
fprintf (fp, "\nextern const char i386_mnemonics[];\n\n");
+ str = NULL;
for (l = strlen (opcode_array[offs = j = 0]->name); j < i; j++)
{
const char *next = NULL;
size_t l1 = j + 1 < i ? strlen(next = opcode_array[j + 1]->name) : 0;
name = opcode_array[j]->name;
- str = mkident (name);
+ if (str == NULL)
+ str = mkident (name);
if (l < l1 && !strcmp(name, next + l1 - l))
{
fprintf (fp, "#define MN_%s ", str);
@@ -1769,8 +1771,9 @@ process_i386_opcodes (FILE *table)
fprintf (table, " \"\\0\"\"%s\"\n", name);
fprintf (fp, "#define MN_%s %#x\n", str, offs + 1);
offs += strlen (name) + 1;
+ free (str);
+ str = NULL;
}
- free (str);
l = l1;
}
next prev parent reply other threads:[~2023-01-13 11:07 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 ` Jan Beulich [this message]
2023-01-13 11:08 ` [PATCH 5/8] x86: avoid strcmp() in a few places Jan Beulich
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=8f43bf06-9323-8838-bcdc-bfbf9a850ae2@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).