public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@ericsson.com>
To: <gdb-patches@sourceware.org>
Cc: Simon Marchi <simon.marchi@ericsson.com>
Subject: [PATCH 3/3] arm-tdep.c: Refactor arm_decode_media
Date: Wed, 10 Feb 2016 16:17:00 -0000	[thread overview]
Message-ID: <1455121027-27061-4-git-send-email-simon.marchi@ericsson.com> (raw)
In-Reply-To: <1455121027-27061-1-git-send-email-simon.marchi@ericsson.com>

Refactor arm_decode_media to make it more readable.  The new layout matches
very closely the description in the ARM Architecture Reference Manual.  It uses
the same order and same nomenclature.

gdb/ChangeLog:

	* arm-tdep.c (arm_decode_media): Refactor instruction decoding.
---
 gdb/arm-tdep.c | 30 ++++++++++++++++++++++--------
 1 file changed, 22 insertions(+), 8 deletions(-)

diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index e17a1a4..bf5bc49 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -6625,49 +6625,63 @@ static int
 arm_decode_media (struct gdbarch *gdbarch, uint32_t insn,
 		  struct displaced_step_closure *dsc)
 {
-  switch (bits (insn, 20, 24))
+  uint8_t op1 = bits (insn, 20, 24);
+  uint8_t rd = bits (insn, 12, 15);
+  uint8_t op2 = bits (insn, 5, 7);
+  uint8_t rn = bits (insn, 0, 3);
+
+  switch (op1)
     {
     case 0x00: case 0x01: case 0x02: case 0x03:
+      /* Parallel addition and subtraction, signed  */
       return arm_copy_unmodified (gdbarch, insn, "parallel add/sub signed", dsc);
 
     case 0x04: case 0x05: case 0x06: case 0x07:
+      /* Parallel addition and subtraction, unsigned  */
       return arm_copy_unmodified (gdbarch, insn, "parallel add/sub unsigned", dsc);
 
     case 0x08: case 0x09: case 0x0a: case 0x0b:
     case 0x0c: case 0x0d: case 0x0e: case 0x0f:
+      /* Packing, unpacking, saturation, and reversal  */
       return arm_copy_unmodified (gdbarch, insn,
 			      "decode/pack/unpack/saturate/reverse", dsc);
 
     case 0x18:
-      if (bits (insn, 5, 7) == 0)  /* op2.  */
+      if (op2 == 0)
 	 {
-	  if (bits (insn, 12, 15) == 0xf)
+	  if (rd == 0xf)
+	    /* USAD8  */
 	    return arm_copy_unmodified (gdbarch, insn, "usad8", dsc);
 	  else
+	    /* USADA8  */
 	    return arm_copy_unmodified (gdbarch, insn, "usada8", dsc);
 	}
       else
-	 return arm_copy_undef (gdbarch, insn, dsc);
+	return arm_copy_undef (gdbarch, insn, dsc);
 
     case 0x1a: case 0x1b:
-      if (bits (insn, 5, 6) == 0x2)  /* op2[1:0].  */
+      if ((op2 & 0x3) == 0x2)
+	/* SBFX  */
 	return arm_copy_unmodified (gdbarch, insn, "sbfx", dsc);
       else
 	return arm_copy_undef (gdbarch, insn, dsc);
 
     case 0x1c: case 0x1d:
-      if (bits (insn, 5, 6) == 0x0)  /* op2[1:0].  */
+      if ((op2 & 0x3) == 0x0)
 	 {
-	  if (bits (insn, 0, 3) == 0xf)
+	  if (rn == 0xf)
+	    /* BFC  */
 	    return arm_copy_unmodified (gdbarch, insn, "bfc", dsc);
 	  else
+	    /* BFI  */
 	    return arm_copy_unmodified (gdbarch, insn, "bfi", dsc);
 	}
       else
 	return arm_copy_undef (gdbarch, insn, dsc);
 
     case 0x1e: case 0x1f:
-      if (bits (insn, 5, 6) == 0x2)  /* op2[1:0].  */
+      if ((op2 & 0x3) == 0x2)
+	/* UBFX  */
 	return arm_copy_unmodified (gdbarch, insn, "ubfx", dsc);
       else
 	return arm_copy_undef (gdbarch, insn, dsc);
-- 
2.5.1

  reply	other threads:[~2016-02-10 16:17 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-10 16:17 [PATCH 0/3] Minor refactorings in arm-tdep.c instruction decoding Simon Marchi
2016-02-10 16:17 ` Simon Marchi [this message]
2016-02-11 11:58   ` [PATCH 3/3] arm-tdep.c: Refactor arm_decode_media Yao Qi
2016-02-10 16:17 ` [PATCH 2/3] arm-tdep.c: Refactor arm_decode_dp_misc Simon Marchi
2016-02-11 11:52   ` Yao Qi
2016-02-11 17:10     ` Yao Qi
2016-02-11 17:18     ` Simon Marchi
2016-02-10 16:17 ` [PATCH 1/3] arm-tdep.c: Refactor arm_process_displaced_insn Simon Marchi
2016-02-11 11:22   ` Yao Qi
2016-02-11 16:59     ` Simon Marchi
2016-02-12 16:56       ` Yao Qi
2016-02-11 11:17 ` [PATCH 0/3] Minor refactorings in arm-tdep.c instruction decoding Yao Qi
2016-02-16 15:26   ` Simon Marchi

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=1455121027-27061-4-git-send-email-simon.marchi@ericsson.com \
    --to=simon.marchi@ericsson.com \
    --cc=gdb-patches@sourceware.org \
    /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).