public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Jan Beulich <jbeulich@suse.com>
To: Binutils <binutils@sourceware.org>
Cc: "H.J. Lu" <hjl.tools@gmail.com>
Subject: [PATCH v3 6/6] x86: generate template sets data at build time
Date: Mon, 28 Nov 2022 12:33:37 +0100	[thread overview]
Message-ID: <0387160b-8925-7515-e287-e1f240f93523@suse.com> (raw)
In-Reply-To: <8f385c36-cfe5-1b0a-45b6-ea6c008b20c8@suse.com>

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 == &current_templates->start);
+    (void)(end == &current_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


      parent reply	other threads:[~2022-11-28 11:33 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-28 11:29 [PATCH v3 0/6] x86: break gas dependency on libopcodes Jan Beulich
2022-11-28 11:30 ` [PATCH v3 1/6] x86: instantiate i386_{op,reg}tab[] in gas instead of in libopcodes Jan Beulich
2022-11-28 11:31 ` [PATCH v3 2/6] x86: remove i386-opc.c Jan Beulich
2022-11-28 11:31 ` [PATCH v3 3/6] x86: break gas dependency on libopcodes Jan Beulich
2022-11-28 11:32 ` [PATCH v3 4/6] x86: add generated tables dependency check to gas Jan Beulich
2022-11-28 11:32 ` [PATCH v3 5/6] x86: drop sentinel from i386_optab[] Jan Beulich
2022-11-28 11:33 ` Jan Beulich [this message]

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=0387160b-8925-7515-e287-e1f240f93523@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).