gas/
authorAlan Modra <amodra@gmail.com>
Mon, 27 Feb 2012 06:37:40 +0000 (06:37 +0000)
committerAlan Modra <amodra@gmail.com>
Mon, 27 Feb 2012 06:37:40 +0000 (06:37 +0000)
* config/tc-crx.c: Include bfd_stdint.h.
(getconstant): Remove irrelevant comment.  Don't fail due to
sign-extension of int mask.
(check_range): Rewrite using unsigned arithmetic throughout.
opcodes/
* crx-dis.c (print_arg): Mask constant to 32 bits.
* crx-opc.c (cst4_map): Use int array.
include/opcode/
* crx.h (cst4_map): Update declaration.

gas/ChangeLog
gas/config/tc-crx.c
include/opcode/ChangeLog
include/opcode/crx.h
opcodes/ChangeLog
opcodes/crx-dis.c
opcodes/crx-opc.c

index 6e6f70a5bae04a93dccea7da2ac7acccf024a3a5..dbbfcdbb704c89871186c19533c4e7d3b3db2cbf 100644 (file)
@@ -1,3 +1,10 @@
+2012-02-27  Alan Modra  <amodra@gmail.com>
+
+       * config/tc-crx.c: Include bfd_stdint.h.
+       (getconstant): Remove irrelevant comment.  Don't fail due to
+       sign-extension of int mask.
+       (check_range): Rewrite using unsigned arithmetic throughout.
+
 2012-02-25  Walter Lee  <walt@tilera.com>
 
        * tc-tilepro.c (emit_tilepro_instruction): Check if symbol is
index b347d8b828a16d582aed192daea37b8af38e7b0a..775781bf3f70ca185613bb5b7a27222d2171b1e4 100644 (file)
@@ -1,5 +1,5 @@
 /* tc-crx.c -- Assembler code for the CRX CPU core.
-   Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010
+   Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012
    Free Software Foundation, Inc.
 
    Contributed by Tomer Levi, NSC, Israel.
@@ -24,6 +24,7 @@
    MA 02110-1301, USA.  */
 
 #include "as.h"
+#include "bfd_stdint.h"
 #include "safe-ctype.h"
 #include "dwarf2dbg.h"
 #include "opcode/crx.h"
@@ -1173,9 +1174,7 @@ getreg_image (reg r)
 static long
 getconstant (long x, int nbits)
 {
-  /* The following expression avoids overflow if
-     'nbits' is the number of bits in 'bfd_vma'.  */
-  return (x & ((((1 << (nbits - 1)) - 1) << 1) | 1));
+  return x & ((((1U << (nbits - 1)) - 1) << 1) | 1);
 }
 
 /* Print a constant value to 'output_opcode':
@@ -1326,17 +1325,14 @@ get_number_of_operands (void)
 static op_err
 check_range (long *num, int bits, int unsigned flags, int update)
 {
-  long min, max;
+  uint32_t max;
   int retval = OP_LEGAL;
   int bin;
-  long upper_64kb = 0xFFFF0000;
-  long value = *num;
+  uint32_t upper_64kb = 0xffff0000;
+  uint32_t value = *num;
 
-  /* For hosts witah longs bigger than 32-bits make sure that the top 
-     bits of a 32-bit negative value read in by the parser are set,
-     so that the correct comparisons are made.  */
-  if (value & 0x80000000)
-    value |= (-1L << 31);
+  /* Trim all values to 32 bits.  uint32_t can be more than 32 bits.  */
+  value &= 0xffffffff;
 
   /* Verify operand value is even.  */
   if (flags & OP_EVEN)
@@ -1360,7 +1356,12 @@ check_range (long *num, int bits, int unsigned flags, int update)
 
   if (flags & OP_SHIFT)
     {
+      /* All OP_SHIFT args are also OP_SIGNED, so we want to keep the
+        sign.  However, right shift of a signed type with a negative
+        value is implementation defined.  See ISO C 6.5.7.  So we use
+        an unsigned type and sign extend afterwards.  */
       value >>= 1;
+      value = ((value ^ 0x40000000) - 0x40000000) & 0xffffffff;
       if (update)
        *num = value;
     }
@@ -1382,13 +1383,14 @@ check_range (long *num, int bits, int unsigned flags, int update)
     {
       int is_dispu4 = 0;
 
-      int mul = (instruction->flags & DISPUB4) ? 1 
-               : (instruction->flags & DISPUW4) ? 2
-               : (instruction->flags & DISPUD4) ? 4 : 0;
+      uint32_t mul = (instruction->flags & DISPUB4 ? 1 
+                     : instruction->flags & DISPUW4 ? 2
+                     : instruction->flags & DISPUD4 ? 4
+                     : 0);
       
       for (bin = 0; bin < cst4_maps; bin++)
        {
-         if (value == (mul * bin))
+         if (value == mul * bin)
            {
              is_dispu4 = 1;
              if (update)
@@ -1405,7 +1407,7 @@ check_range (long *num, int bits, int unsigned flags, int update)
 
       for (bin = 0; bin < cst4_maps; bin++)
        {
-         if (value == cst4_map[bin])
+         if (value == ((uint32_t) cst4_map[bin] & 0xffffffff))
            {
              is_cst4 = 1;
              if (update)
@@ -1418,17 +1420,19 @@ check_range (long *num, int bits, int unsigned flags, int update)
     }
   else if (flags & OP_SIGNED)
     {
-      max = (1 << (bits - 1)) - 1;
-      min = - (1 << (bits - 1));
-      if ((value > max) || (value < min))
+      max = 1;
+      max = max << (bits - 1);
+      value += max;
+      max = ((max - 1) << 1) | 1;
+      if (value > max)
        retval = OP_OUT_OF_RANGE;
     }
   else if (flags & OP_UNSIGNED)
     {
-      max = ((((1 << (bits - 1)) - 1) << 1) | 1);
-      min = 0;
-      if (((unsigned long) value > (unsigned long) max) 
-           || ((unsigned long) value < (unsigned long) min))
+      max = 1;
+      max = max << (bits - 1);
+      max = ((max - 1) << 1) | 1;
+      if (value > max)
        retval = OP_OUT_OF_RANGE;
     }
   return retval;
index 5241b37312b93c9d3e5900d5e6ac583e0fa357ef..71018b0890d71a5106a7dcabe99b4232941a881b 100644 (file)
@@ -1,3 +1,7 @@
+2012-02-27  Alan Modra  <amodra@gmail.com>
+
+       * crx.h (cst4_map): Update declaration.
+
 2012-02-25  Walter Lee  <walt@tilera.com>
 
        * tilegx.h (tilegx_mnemonic): Add TILEGX_OPC_LD4S_TLS,
index 5c484bf26bcafe5d73572ddaa0dd8ad4b7e8320f..6081ea3548d0fbdbc2b3cf75e0d31a338b6d86a0 100644 (file)
@@ -1,5 +1,5 @@
 /* crx.h -- Header file for CRX opcode and register tables.
-   Copyright 2004, 2010 Free Software Foundation, Inc.
+   Copyright 2004, 2010, 2012 Free Software Foundation, Inc.
    Contributed by Tomer Levi, NSC, Israel.
    Originally written for GAS 2.12 by Tomer Levi, NSC, Israel.
    Updates, BFDizing, GNUifying and ELF support by Tomer Levi.
@@ -384,7 +384,7 @@ extern const int crx_num_traps;
 #define NUMTRAPS crx_num_traps
 
 /* cst4 operand mapping.  */
-extern const long cst4_map[];
+extern const int cst4_map[];
 extern const int cst4_maps;
 
 /* Table of instructions with no operands.  */
index cc0af8e420a2c71962888abc5707e42c7d90e609..81b4e64434b1c2858ab974b0676c652afe18906c 100644 (file)
@@ -1,3 +1,8 @@
+2012-02-27  Alan Modra  <amodra@gmail.com>
+
+       * crx-dis.c (print_arg): Mask constant to 32 bits.
+       * crx-opc.c (cst4_map): Use int array.
+
 2012-02-27  Alan Modra  <amodra@gmail.com>
 
        * arc-dis.c (BITS): Don't use shifts to mask off bits.
index f909897444dddc027580ce168f24fb2afb4a5ab4..35168bc97d4da0ad65a32480bcd84976670a9330 100644 (file)
@@ -1,5 +1,5 @@
 /* Disassembler code for CRX.
-   Copyright 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
+   Copyright 2004, 2005, 2006, 2007, 2012 Free Software Foundation, Inc.
    Contributed by Tomer Levi, NSC, Israel.
    Written by Tomer Levi.
 
@@ -548,7 +548,7 @@ print_arg (argument *a, bfd_vma memaddr, struct disassemble_info *info)
                    func (stream, "%s", string);
                  }
                else
-                 func (stream, "$0x%lx", a->constant);
+                 func (stream, "$0x%lx", a->constant & 0xffffffff);
            }
          else
             {
@@ -557,12 +557,12 @@ print_arg (argument *a, bfd_vma memaddr, struct disassemble_info *info)
             }
         }
       else
-       func (stream, "$0x%lx", a->constant);
+       func (stream, "$0x%lx", a->constant & 0xffffffff);
       break;
 
     case arg_idxr:
-      func (stream, "0x%lx(%s,%s,%d)", a->constant, getregname (a->r),
-           getregname (a->i_r), powerof2 (a->scale));
+      func (stream, "0x%lx(%s,%s,%d)", a->constant & 0xffffffff,
+           getregname (a->r), getregname (a->i_r), powerof2 (a->scale));
       break;
 
     case arg_rbase:
@@ -570,7 +570,7 @@ print_arg (argument *a, bfd_vma memaddr, struct disassemble_info *info)
       break;
 
     case arg_cr:
-      func (stream, "0x%lx(%s)", a->constant, getregname (a->r));
+      func (stream, "0x%lx(%s)", a->constant & 0xffffffff, getregname (a->r));
 
       if (IS_INSN_TYPE (LD_STOR_INS_INC))
        func (stream, "+");
index b046c913e33f33aae594e7d589d025b573e40a5d..65e2e86cf77cdf48308ed2cce7ca099931fd68c1 100644 (file)
@@ -1,5 +1,5 @@
 /* crx-opc.c -- Table of opcodes for the CRX processor.
-   Copyright 2004, 2005, 2007 Free Software Foundation, Inc.
+   Copyright 2004, 2005, 2007, 2012 Free Software Foundation, Inc.
    Contributed by Tomer Levi NSC, Israel.
    Originally written for GAS 2.12 by Tomer Levi.
 
@@ -701,7 +701,7 @@ The value in entry <N> is mapped to the value <N>
 Example (for N=5):
 
     cst4_map[5]=-4  -->>       5               */
-const long cst4_map[] =
+const int cst4_map[] =
 {
   0, 1, 2, 3, 4, -4, -1, 7, 8, 16, 32, 20, 12, 48
 };
This page took 0.0302 seconds and 4 git commands to generate.