From: Andreas Arnez <arnez@linux.vnet.ibm.com>
To: binutils@sourceware.org
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>,
Andreas Krebbel <krebbel@linux.vnet.ibm.com>
Subject: [PATCH 4/6] S/390: Simplify opcode search loop in disassembler
Date: Fri, 25 Jul 2014 17:02:00 -0000 [thread overview]
Message-ID: <1406307713-7926-5-git-send-email-arnez@linux.vnet.ibm.com> (raw)
In-Reply-To: <1406307713-7926-1-git-send-email-arnez@linux.vnet.ibm.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
next prev parent reply other threads:[~2014-07-25 17:02 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-25 17:02 [PATCH 0/6] S/390: Some disassembler cleanup Andreas Arnez
2014-07-25 17:02 ` [PATCH 2/6] S/390: Fix disassembler's treatment of signed/unsigned operands Andreas Arnez
2014-07-25 17:02 ` [PATCH 5/6] S/390: Drop function pointer dereferences in disassembler Andreas Arnez
2014-07-25 17:02 ` Andreas Arnez [this message]
2014-07-25 17:02 ` [PATCH 3/6] S/390: Fix off-by-one error in disassembler initialization Andreas Arnez
2014-07-25 17:02 ` [PATCH 6/6] S/390: Various minor simplifications in disassembler Andreas Arnez
2014-07-25 17:02 ` [PATCH 1/6] S/390: Split disassembler routine into smaller functions Andreas Arnez
2014-08-19 14:43 ` [PATCH 0/6] S/390: Some disassembler cleanup Nicholas Clifton
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=1406307713-7926-5-git-send-email-arnez@linux.vnet.ibm.com \
--to=arnez@linux.vnet.ibm.com \
--cc=binutils@sourceware.org \
--cc=krebbel@linux.vnet.ibm.com \
--cc=schwidefsky@de.ibm.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).