aboutsummaryrefslogtreecommitdiff
path: root/opcodes/v850-opc.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2012-02-27 06:55:39 +0000
committerAlan Modra <amodra@gmail.com>2012-02-27 06:55:39 +0000
commit3f26eb3af95d6f59c98b1df1de4342bfd6523bfa (patch)
tree01f6937e3819ce623e9878b92fdcd3810d006886 /opcodes/v850-opc.c
parentb9fcee797cc69e256f174c6665e88125e4ecc06b (diff)
downloadgdb-3f26eb3af95d6f59c98b1df1de4342bfd6523bfa.zip
gdb-3f26eb3af95d6f59c98b1df1de4342bfd6523bfa.tar.gz
gdb-3f26eb3af95d6f59c98b1df1de4342bfd6523bfa.tar.bz2
* v850-opc.c (extract_v8): Rearrange to make it obvious this
is the inverse of corresponding insert function. (extract_d22, extract_u9, extract_r4): Likewise. (extract_d9): Correct sign extension. (extract_d16_15): Don't assume "long" is 32 bits, and don't rely on implementation defined behaviour for shift right of signed types. (extract_d16_16, extract_d17_16, extract_i9): Likewise. (extract_d23): Likewise, and correct mask.
Diffstat (limited to 'opcodes/v850-opc.c')
-rw-r--r--opcodes/v850-opc.c56
1 files changed, 24 insertions, 32 deletions
diff --git a/opcodes/v850-opc.c b/opcodes/v850-opc.c
index 67ba562..4ba20d3 100644
--- a/opcodes/v850-opc.c
+++ b/opcodes/v850-opc.c
@@ -1,6 +1,6 @@
/* Assemble V850 instructions.
- Copyright 1996, 1997, 1998, 2000, 2001, 2002, 2003, 2005, 2007, 2010
- Free Software Foundation, Inc.
+ Copyright 1996, 1997, 1998, 2000, 2001, 2002, 2003, 2005, 2007, 2010,
+ 2012 Free Software Foundation, Inc.
This file is part of the GNU opcodes library.
@@ -259,7 +259,7 @@ insert_v8 (unsigned long insn, long value, const char ** errmsg)
static unsigned long
extract_v8 (unsigned long insn, int * invalid)
{
- unsigned long ret = (insn & 0x1f) | ((insn & 0x38000000) >> (27-5));
+ unsigned long ret = (insn & 0x1f) | ((insn >> (27-5)) & 0xe0);
if (invalid != 0)
*invalid = 0;
@@ -285,10 +285,9 @@ insert_d9 (unsigned long insn, long value, const char ** errmsg)
static unsigned long
extract_d9 (unsigned long insn, int * invalid)
{
- unsigned long ret = ((insn & 0xf800) >> 7) | ((insn & 0x0070) >> 3);
+ signed long ret = ((insn >> 7) & 0x1f0) | ((insn >> 3) & 0x0e);
- if ((insn & 0x8000) != 0)
- ret -= 0x0200;
+ ret = (ret ^ 0x100) - 0x100;
if (invalid != 0)
*invalid = 0;
@@ -341,8 +340,9 @@ insert_d16_15 (unsigned long insn, long value, const char ** errmsg)
static unsigned long
extract_d16_15 (unsigned long insn, int * invalid)
{
- signed long ret = (insn & 0xfffe0000);
- ret >>= 16;
+ signed long ret = (insn >> 16) & 0xfffe;
+
+ ret = (ret ^ 0x8000) - 0x8000;
if (invalid != 0)
*invalid = 0;
@@ -361,9 +361,9 @@ insert_d16_16 (unsigned long insn, signed long value, const char ** errmsg)
static unsigned long
extract_d16_16 (unsigned long insn, int * invalid)
{
- signed long ret = insn & 0xfffe0000;
- ret >>= 16;
- ret |= ((insn & 0x20) >> 5);
+ signed long ret = ((insn >> 16) & 0xfffe) | ((insn >> 5) & 1);
+
+ ret = (ret ^ 0x8000) - 0x8000;
if (invalid != 0)
*invalid = 0;
@@ -382,9 +382,9 @@ insert_d17_16 (unsigned long insn, long value, const char ** errmsg)
static unsigned long
extract_d17_16 (unsigned long insn, int * invalid)
{
- signed long ret = (insn >> 16) & 0xfffe;
- ret |= (insn << (16 - 4)) & 0x10000;
- ret = (ret << ((sizeof ret)*8 - 17)) >> ((sizeof ret)*8 - 17);
+ signed long ret = ((insn >> 16) & 0xfffe) | ((insn << (16 - 4)) & 0x10000);
+
+ ret = (ret ^ 0x10000) - 0x10000;
if (invalid != 0)
*invalid = 0;
@@ -410,9 +410,9 @@ insert_d22 (unsigned long insn, long value, const char ** errmsg)
static unsigned long
extract_d22 (unsigned long insn, int * invalid)
{
- signed long ret = ((insn & 0xfffe0000) >> 16) | ((insn & 0x3f) << 16);
+ signed long ret = ((insn >> 16) & 0xfffe) | ((insn << 16) & 0x3f0000);
- ret = (ret << ((sizeof ret)*8 - 22)) >> ((sizeof ret)*8 - 22);
+ ret = (ret ^ 0x200000) - 0x200000;
if (invalid != 0)
*invalid = 0;
@@ -423,7 +423,7 @@ static unsigned long
insert_d23 (unsigned long insn, long value, const char ** errmsg)
{
if (value > 0x3fffff || value < -0x400000)
- * errmsg = out_of_range;
+ * errmsg = out_of_range;
return insn | ((value & 0x7f) << 4) | ((value & 0x7fff80) << (16-7));
}
@@ -431,9 +431,9 @@ insert_d23 (unsigned long insn, long value, const char ** errmsg)
static unsigned long
extract_d23 (unsigned long insn, int * invalid)
{
- signed long ret = ((insn >> 4) & 0x7f) | ((insn >> (16-7)) & 0x7fffff80);
+ signed long ret = ((insn >> 4) & 0x7f) | ((insn >> (16-7)) & 0x7fff80);
- ret = ((ret << ((sizeof ret)*8 - 23)) >> ((sizeof ret)*8 - 23));
+ ret = (ret ^ 0x400000) - 0x400000;
if (invalid != 0)
*invalid = 0;
@@ -452,11 +452,9 @@ insert_i9 (unsigned long insn, signed long value, const char ** errmsg)
static unsigned long
extract_i9 (unsigned long insn, int * invalid)
{
- signed long ret = insn & 0x003c0000;
+ signed long ret = ((insn >> 13) & 0x1e0) | (insn & 0x1f);
- ret <<= 10;
- ret >>= 23;
- ret |= (insn & 0x1f);
+ ret = (ret ^ 0x100) - 0x100;
if (invalid != 0)
*invalid = 0;
@@ -477,11 +475,7 @@ insert_u9 (unsigned long insn, long v, const char ** errmsg)
static unsigned long
extract_u9 (unsigned long insn, int * invalid)
{
- unsigned long ret = insn & 0x003c0000;
-
- ret >>= 13;
-
- ret |= (insn & 0x1f);
+ unsigned long ret = ((insn >> 13) & 0x1e0) | (insn & 0x1f);
if (invalid != 0)
*invalid = 0;
@@ -496,7 +490,7 @@ insert_spe (unsigned long insn, long v, const char ** errmsg)
if (value != 3)
* errmsg = _("invalid register for stack adjustment");
- return insn & (~ 0x180000);
+ return insn & ~0x180000;
}
static unsigned long
@@ -524,9 +518,7 @@ insert_r4 (unsigned long insn, long v, const char ** errmsg)
static unsigned long
extract_r4 (unsigned long insn, int * invalid)
{
- unsigned long ret;
- ret = (insn >> 17) & 0xf;
- ret |= (insn >> (23-4)) & 0x10;
+ unsigned long ret = ((insn >> (23-4)) & 0x10) | ((insn >> 17) & 0x0f);
if (invalid != 0)
*invalid = 0;