]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
Optimize x86/x86-64 disassembler a bit.
authorUlrich Drepper <drepper@redhat.com>
Wed, 31 Dec 2008 18:15:30 +0000 (10:15 -0800)
committerUlrich Drepper <drepper@redhat.com>
Wed, 31 Dec 2008 18:15:30 +0000 (10:15 -0800)
libcpu/ChangeLog
libcpu/i386_disasm.c
libcpu/i386_parse.y

index 90c2e588c4b97830fef0cbcd08d9886f2ac59b07..041123e13752be1d70db63fd705a3d88f5e60a0e 100644 (file)
@@ -1,5 +1,12 @@
 2008-12-31  Ulrich Drepper  <drepper@redhat.com>
 
+       * i386_disasm.c (i386_disasm): Minor optimizations.
+
+       * i386_parse.y (instrtable_out): No need to emit index, the reader can
+       keep track.
+       * i386_disasm.c (i386_disasm): The index is not emitted anymore, no
+       need to skip it.
+
        * i386_disasm.c (amd3dnow): Mark as const.
 
        * defs/i386: Add blendvpd and blendvps opcodes.
index 759363564a3acba7629cc8db34909277e1d3d730..9961e4d9fd2abd26ca02674f0a0a861036e1a2b2 100644 (file)
@@ -393,17 +393,16 @@ i386_disasm (const uint8_t **startp, const uint8_t *end, GElf_Addr addr,
       bufcnt = 0;
 
       size_t cnt = 0;
+    next_match:
       while (curr < match_end)
        {
-         const uint8_t *start = curr;
-
          uint_fast8_t len = *curr++;
+         const uint8_t *start = curr;
 
          assert (len > 0);
-         assert (curr + 2 * len + 2 <= match_end);
+         assert (curr + 2 * len <= match_end);
 
          const uint8_t *codep = data;
-         size_t avail = len;
          int correct_prefix = 0;
          int opoff = 0;
 
@@ -411,8 +410,6 @@ i386_disasm (const uint8_t **startp, const uint8_t *end, GElf_Addr addr,
            {
              /* We match a prefix byte.  This is exactly one byte and
                 is matched exactly, without a mask.  */
-             --avail;
-
              --len;
              start += 2;
              opoff = 8;
@@ -423,25 +420,23 @@ i386_disasm (const uint8_t **startp, const uint8_t *end, GElf_Addr addr,
              correct_prefix = last_prefix_bit;
            }
 
+         size_t avail = len;
          while (avail > 0)
            {
              uint_fast8_t masked = *codep++ & *curr++;
              if (masked != *curr++)
-               break;
+               {
+               not:
+                 curr = start + 2 * len;
+                 ++cnt;
+                 goto next_match;
+               }
 
              --avail;
              if (codep == end && avail > 0)
                goto do_ret;
            }
 
-         if (avail != 0)
-           {
-           not:
-             curr = start + 1 + 2 * len + 2;
-             ++cnt;
-             continue;
-           }
-
          if (len > end - data)
            /* There is not enough data for the entire instruction.  The
               caller can figure this out by looking at the pointer into
index ceeb12ad0e78fc6d0ac18939021691b381d33827..6297d5d947649271ee98f3abc85ea7902e952f06 100644 (file)
@@ -1296,7 +1296,7 @@ instrtable_out (void)
          b = b->next;
        }
 
-      fprintf (outfile, " %#zx, %#zx,\n", cnt & 0xff, cnt >> 8);
+      fputc_unlocked ('\n', outfile);
     }
   fputs ("};\n", outfile);
 }