summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2008-05-20 17:07:57 -0700
committerH. Peter Anvin <hpa@zytor.com>2008-05-20 17:07:57 -0700
commit0ab96a17d59fa59cc23f05c989a5e0d569d7f328 (patch)
tree8802c9d5614d82c3fb7c0dc60173f9155c921e94
parentf99359c03ac96c1feb27e6e84cf8872892c8ca16 (diff)
downloadnasm-0ab96a17d59fa59cc23f05c989a5e0d569d7f328.tar.gz
ndisasm: simple compare for conditional opcodes, no loop
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.
-rw-r--r--disasm.c21
-rw-r--r--insns.pl4
2 files changed, 11 insertions, 14 deletions
diff --git a/disasm.c b/disasm.c
index 5cdb0ec6..378596a9 100644
--- 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++) {
diff --git a/insns.pl b/insns.pl
index 604f6cf4..fbdb7999 100644
--- 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;