This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Suspected bug lshift_value (expmed.c) and its patch


Hello,
Following my discussion with Dave Korn (http://gcc.gnu.org/ml/gcc/2009-03/msg00497.html), I believe I may find a bug in lshift_value(expmed.c).


static rtx
lshift_value (enum machine_mode mode, rtx value, int bitpos, int bitsize)
{
  unsigned HOST_WIDE_INT v = INTVAL (value);
  HOST_WIDE_INT low, high;

  if (bitsize < HOST_BITS_PER_WIDE_INT)
    v &= ~((HOST_WIDE_INT) -1 << bitsize);

  if (bitpos < HOST_BITS_PER_WIDE_INT)
    {
      low = v << bitpos;
      high = (bitpos > 0 ? (v >> (HOST_BITS_PER_WIDE_INT - bitpos)) : 0);   <---   high part is wrongly calculated
    }
  else
    {
      low = 0;
      high = v << (bitpos - HOST_BITS_PER_WIDE_INT);
    }

  return immed_double_const (low, high, mode);
}

For our target, HOST_WIDE_INT = 32.

example:  mode = Dimode, rtx value = (const_int -1 [0xffffffff]), bitpos = 0; bitsize = 33;
          return = (const_double -1 [0xffffffff] 0 [0x0] 0 [0x0] 0 [0x0] 0 [0x0] 0 [0x0])
          expected return =  (const_double -1 [0xffffffff] 1 [0x1] 0 [0x0] 0 [0x0] 0 [0x0] 0 [0x0])


The trouble is I cannot point out which target except our one (still private porting)
has the same error, which has HOST_BITS_PER_WIDE_INT = 32 and BITS_PER_WORD = 64.  
The following is a patch to fix it. I will run full test it x86-64_unknown-linux-gnu. 

Bingfeng Mei
Broadcom UK

Index: expmed.c
===================================================================
--- expmed.c    (revision 144836)
+++ expmed.c    (working copy)
@@ -1870,7 +1870,10 @@
   if (bitpos < HOST_BITS_PER_WIDE_INT)
     {
       low = v << bitpos;
-      high = (bitpos > 0 ? (v >> (HOST_BITS_PER_WIDE_INT - bitpos)) : 0);
+      /* Obtain value by shifting and set zeros for remaining part*/
+      if((bitpos + bitsize) > HOST_BITS_PER_WIDE_INT)
+        high =  (v >> (HOST_BITS_PER_WIDE_INT - bitpos))
+                & ((1 << (bitpos + bitsize - HOST_BITS_PER_WIDE_INT)) - 1);
     }
   else
     {


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]