This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[PATCH 4/6] S/390: Simplify opcode search loop in disassembler
- From: Andreas Arnez <arnez at linux dot vnet dot ibm dot com>
- To: binutils at sourceware dot org
- Cc: Martin Schwidefsky <schwidefsky at de dot ibm dot com>, Andreas Krebbel <krebbel at linux dot vnet dot ibm dot com>
- Date: Fri, 25 Jul 2014 19:01:51 +0200
- Subject: [PATCH 4/6] S/390: Simplify opcode search loop in disassembler
- Authentication-results: sourceware.org; auth=none
- References: <1406307713-7926-1-git-send-email-arnez at linux dot vnet dot ibm dot com>
opcodes/
* s390-dis.c (print_insn_s390): Simplify the opcode search loop.
Check architecture mask against all searched opcodes, not just the
first matching one.
---
opcodes/s390-dis.c | 52 +++++++++++++++++++---------------------------------
1 file changed, 19 insertions(+), 33 deletions(-)
diff --git a/opcodes/s390-dis.c b/opcodes/s390-dis.c
index e6b0ee5..029f9f1 100644
--- a/opcodes/s390-dis.c
+++ b/opcodes/s390-dis.c
@@ -229,8 +229,7 @@ int
print_insn_s390 (bfd_vma memaddr, struct disassemble_info *info)
{
bfd_byte buffer[6];
- const struct s390_opcode *opcode;
- const struct s390_opcode *opcode_end;
+ const struct s390_opcode *opcode = NULL;
unsigned int value;
int status, opsize, bufsize;
@@ -266,41 +265,28 @@ print_insn_s390 (bfd_vma memaddr, struct disassemble_info *info)
{
const struct s390_opcode *op;
- /* Find the first match in the opcode table. */
- opcode_end = s390_opcodes + s390_num_opcodes;
- for (opcode = s390_opcodes + opc_index[(int) buffer[0]];
- (opcode < opcode_end) && (buffer[0] == opcode->opcode[0]);
- opcode++)
+ /* Find the "best match" in the opcode table. */
+ for (op = s390_opcodes + opc_index[buffer[0]];
+ op != s390_opcodes + s390_num_opcodes
+ && op->opcode[0] == buffer[0];
+ op++)
{
- /* Check architecture. */
- if (!(opcode->modes & current_arch_mask))
- continue;
-
- if (!s390_insn_matches_opcode (buffer, opcode))
- continue;
-
- /* Advance to an opcode with a more specific mask. */
- for (op = opcode + 1; op < opcode_end; op++)
- {
- if ((buffer[0] & op->mask[0]) != op->opcode[0])
- break;
-
- if (!s390_insn_matches_opcode (buffer, op))
- continue;
-
- if (opcode_mask_more_specific (op, opcode))
- opcode = op;
- }
-
- /* The instruction is valid. */
- s390_print_insn_with_opcode (memaddr, info, buffer, opcode);
-
- /* Found instruction, printed it, return its size. */
- return opsize;
+ if ((op->modes & current_arch_mask)
+ && s390_insn_matches_opcode (buffer, op)
+ && (opcode == NULL
+ || opcode_mask_more_specific (op, opcode)))
+ opcode = op;
}
- /* No matching instruction found, fall through to hex print. */
}
+ if (opcode != NULL)
+ {
+ /* The instruction is valid. Print it and return its size. */
+ s390_print_insn_with_opcode (memaddr, info, buffer, opcode);
+ return opsize;
+ }
+
+ /* Fall back to hex print. */
if (bufsize >= 4)
{
value = (unsigned int) buffer[0];
--
1.8.4.2