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 v2 4/4] x86: drop sentinel from i386_optab[]
Date: Fri, 18 Nov 2022 10:14:05 +0100	[thread overview]
Message-ID: <e3d67085-1385-d576-8656-30454f9e4474@suse.com> (raw)
In-Reply-To: <7a1ee76a-5b54-32a6-6301-a1741b5c1883@suse.com>

Now that the table is local to gas, ARRAY_SIZE() can be used to
determine the end of the table. Re-arrange the processing loop in
md_begin() accordingly, at the same time folding the two calls to
notes_alloc() into just one.
---
v2: New.
---
We may want to consider having i386-gen also produce a table of type
"templates[]", which we could then iterate through without needing to
do any allocations (and with fewer overall iterations).

--- a/gas/config/tc-i386.c
+++ b/gas/config/tc-i386.c
@@ -2981,31 +2981,20 @@ md_begin (void)
   op_hash = str_htab_create ();
 
   {
-    const insn_template *optab;
-    templates *core_optab;
+    const insn_template *optab = i386_optab;
+    const insn_template *end = optab + ARRAY_SIZE (i386_optab);
 
-    /* Setup for loop.  */
-    optab = i386_optab;
-    core_optab = notes_alloc (sizeof (*core_optab));
-    core_optab->start = optab;
-
-    while (1)
+    while (optab < end)
       {
-	++optab;
-	if (optab->name == NULL
-	    || strcmp (optab->name, (optab - 1)->name) != 0)
-	  {
-	    /* different name --> ship out current template list;
-	       add to hash table; & begin anew.  */
-	    core_optab->end = optab;
-	    if (str_hash_insert (op_hash, (optab - 1)->name, core_optab, 0))
-	      as_fatal (_("duplicate %s"), (optab - 1)->name);
+	templates *core_optab = notes_alloc (sizeof (*core_optab));
 
-	    if (optab->name == NULL)
-	      break;
-	    core_optab = notes_alloc (sizeof (*core_optab));
-	    core_optab->start = 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);
       }
   }
 
--- a/opcodes/i386-gen.c
+++ b/opcodes/i386-gen.c
@@ -1916,16 +1916,6 @@ process_i386_opcodes (FILE *table)
 
   fclose (fp);
 
-  fprintf (table, "  { NULL, 0, 0, 0,\n");
-
-  process_i386_opcode_modifier (table, "0", 0, 0, NULL, -1);
-
-  process_i386_cpu_flag (table, "0", 0, ",", "    ", -1);
-
-  fprintf (table, "    { ");
-  process_i386_operand_type (table, "0", stage_opcodes, "\t  ", -1);
-  fprintf (table, " } }\n");
-
   fprintf (table, "};\n");
 }
 


      parent reply	other threads:[~2022-11-18  9:14 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-18  9:10 [PATCH v2 0/4] x86: break gas dependency on libopcodes Jan Beulich
2022-11-18  9:12 ` [PATCH v2 1/4] x86: instantiate i386_{op,reg}tab[] in gas instead of in libopcodes Jan Beulich
2022-11-18  9:13 ` [PATCH v2 2/4] x86: remove i386-opc.c Jan Beulich
2022-11-18  9:13 ` [PATCH v2 3/4] x86: break gas dependency on libopcodes Jan Beulich
2022-11-21 16:26   ` H.J. Lu
2022-11-21 16:32     ` Jan Beulich
2022-11-21 16:43       ` H.J. Lu
2022-11-21 16:52         ` Jan Beulich
2022-11-21 17:04           ` H.J. Lu
2022-11-22  7:15             ` Jan Beulich
2022-11-22 16:38               ` H.J. Lu
2022-11-22 17:05                 ` Jan Beulich
2022-11-22 18:21                   ` H.J. Lu
2022-11-18  9:14 ` 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=e3d67085-1385-d576-8656-30454f9e4474@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).