[PATCH v3 6/6] x86: generate template sets data at build time
Jan Beulich
jbeulich@suse.com
Mon Nov 28 11:33:37 GMT 2022
Speed up gas startup by avoiding runtime allocation of the instances of
type "templates". At the same time cut the memory requirement to just
very little over half (not even accounting for any overhead
notes_alloc() may incur) by reusing the "end" slot of a preceding entry
for the "start" slot of the subsequent one.
---
v3: New.
--- a/gas/config/tc-i386.c
+++ b/gas/config/tc-i386.c
@@ -2977,21 +2977,16 @@ md_begin (void)
op_hash = str_htab_create ();
{
- const insn_template *optab = i386_optab;
- const insn_template *end = optab + ARRAY_SIZE (i386_optab);
+ const insn_template *const *sets = i386_op_sets;
+ const insn_template *const *end = sets + ARRAY_SIZE (i386_op_sets) - 1;
- while (optab < end)
- {
- templates *core_optab = notes_alloc (sizeof (*core_optab));
-
- core_optab->start = optab;
- while (++optab < end)
- if (strcmp (optab->name, optab[-1].name) != 0)
- break;
- core_optab->end = optab;
- if (str_hash_insert (op_hash, optab[-1].name, core_optab, 0))
- as_fatal (_("duplicate %s"), optab[-1].name);
- }
+ /* Type checks to compensate for the conversion through void * which
+ occurs during hash table insertion / lookup. */
+ (void)(sets == ¤t_templates->start);
+ (void)(end == ¤t_templates->end);
+ for (; sets < end; ++sets)
+ if (str_hash_insert (op_hash, (*sets)->name, sets, 0))
+ as_fatal (_("duplicate %s"), (*sets)->name);
}
/* Initialize reg_hash hash table. */
--- a/opcodes/i386-gen.c
+++ b/opcodes/i386-gen.c
@@ -1800,7 +1800,7 @@ process_i386_opcodes (FILE *table)
{
FILE *fp;
char buf[2048];
- unsigned int i, j;
+ unsigned int i, j, nr;
char *str, *p, *last, *name;
htab_t opcode_hash_table;
struct opcode_hash_entry **opcode_array = NULL;
@@ -1916,6 +1916,26 @@ process_i386_opcodes (FILE *table)
fclose (fp);
fprintf (table, "};\n");
+
+ /* Generate opcode sets array. */
+ fprintf (table, "\n/* i386 opcode sets table. */\n\n");
+ fprintf (table, "static const insn_template *i386_op_sets[] =\n{\n");
+ fprintf (table, " i386_optab,\n");
+
+ for (nr = j = 0; j < i; j++)
+ {
+ struct opcode_hash_entry *next = opcode_array[j];
+
+ do
+ {
+ ++nr;
+ next = next->next;
+ }
+ while (next);
+ fprintf (table, " i386_optab + %u,\n", nr);
+ }
+
+ fprintf (table, "};\n");
}
static void
More information about the Binutils
mailing list