ndisasm: simple compare for conditional opcodes, no loop
authorH. Peter Anvin <hpa@zytor.com>
Wed, 21 May 2008 00:07:57 +0000 (17:07 -0700)
committerH. Peter Anvin <hpa@zytor.com>
Wed, 21 May 2008 00:07:57 +0000 (17:07 -0700)
We had a completely unnecessary loop to test for conditional opcodes.
Since we always put the conditional opcodes at the end, we might as
well just remember where that list starts and compare against it.

disasm.c
insns.pl

index 5cdb0ec..378596a 100644 (file)
--- a/disasm.c
+++ b/disasm.c
@@ -1208,18 +1208,15 @@ int32_t disasm(uint8_t *data, char *output, int outbufsize, int segsize,
            break;
         }
 
-    for (i = 0; i < NCOND_OPCODES; i++)
-        if ((*p)->opcode == nasm_cond_insn_opcodes[i]) {
-            slen +=
-                snprintf(output + slen, outbufsize - slen, "%s%s",
-                        nasm_cond_insn_names[i],
-                         condition_name[ins.condition]);
-            break;
-        }
-    if (i >= NCOND_OPCODES)
-        slen +=
-            snprintf(output + slen, outbufsize - slen, "%s",
-                     nasm_insn_names[(*p)->opcode]);
+    i = (*p)->opcode;
+    if (i >= FIRST_COND_OPCODE) {
+       slen += snprintf(output + slen, outbufsize - slen, "%s%s",
+                        nasm_cond_insn_names[i-FIRST_COND_OPCODE],
+                        condition_name[ins.condition]);
+    } else {
+        slen += snprintf(output + slen, outbufsize - slen, "%s",
+                        nasm_insn_names[i]);
+    }
     colon = false;
     length += data - origdata;  /* fix up for prefixes */
     for (i = 0; i < (*p)->operands; i++) {
index 604f6cf..fbdb799 100644 (file)
--- a/insns.pl
+++ b/insns.pl
@@ -230,8 +230,8 @@ if ( !defined($output) || $output eq 'i' ) {
     }
     print I "\tI_none = -1\n";
     print I "\n};\n\n";
-    print I "#define MAX_INSLEN ", $maxlen, "\n\n";
-    print I "#define NCOND_OPCODES ", scalar @opcodes_cc, "\n\n";
+    print I "#define MAX_INSLEN ", $maxlen, "\n";
+    print I "#define FIRST_COND_OPCODE I_", $opcodes_cc[0], "\n\n";
     print I "#endif /* NASM_INSNSI_H */\n";
 
     close I;