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]

Re: Patch: Regression Fail: Alpha 32 -O>0, 930529-1.c execution.


On Mon, Apr 26, 1999 at 11:48:44AM -0600, Donn Terry wrote:
> -			| (HOST_WIDE_INT) k[WORDS_BIG_ENDIAN]);
> +			| (unsigned) (HOST_WIDE_INT) k[WORDS_BIG_ENDIAN]);

Ug.  This is just as bad as the original.

Try this instead.


r~

	* emit-rtl.c (operand_subword): Religiously mask and sign-extend
	from 32-bits to HOST_WIDE_INT.

Index: emit-rtl.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/emit-rtl.c,v
retrieving revision 1.57
diff -c -p -d -r1.57 emit-rtl.c
*** emit-rtl.c	1999/04/17 17:14:46	1.57
--- emit-rtl.c	1999/04/26 22:26:00
*************** operand_subword (op, i, validate_address
*** 1273,1296 ****
  
        /* We handle 32-bit and >= 64-bit words here.  Note that the order in
  	 which the words are written depends on the word endianness.
- 
  	 ??? This is a potential portability problem and should
! 	 be fixed at some point.  */
        if (BITS_PER_WORD == 32)
! 	return GEN_INT ((HOST_WIDE_INT) k[i]);
! #if HOST_BITS_PER_WIDE_INT > 32
        else if (BITS_PER_WORD >= 64 && i == 0)
! 	return GEN_INT ((((HOST_WIDE_INT) k[! WORDS_BIG_ENDIAN]) << 32)
! 			| (HOST_WIDE_INT) k[WORDS_BIG_ENDIAN]);
  #endif
        else if (BITS_PER_WORD == 16)
  	{
! 	  long value;
! 	  value = k[i >> 1];
! 	  if ((i & 0x1) == !WORDS_BIG_ENDIAN)
! 	    value >>= 16;
! 	  value &= 0xffff;
! 	  return GEN_INT ((HOST_WIDE_INT) value);
  	}
        else
  	abort ();
--- 1273,1307 ----
  
        /* We handle 32-bit and >= 64-bit words here.  Note that the order in
  	 which the words are written depends on the word endianness.
  	 ??? This is a potential portability problem and should
! 	 be fixed at some point.
! 
! 	 We must excercise caution with the sign bit.  By definition there
! 	 are 32 significant bits in K; there may be more in a HOST_WIDE_INT.
! 	 Consider a host with a 32-bit long and a 64-bit HOST_WIDE_INT.
! 	 So we explicitly mask and sign-extend as necessary.  */
        if (BITS_PER_WORD == 32)
! 	{
! 	  val = k[i];
! 	  val = ((val & 0xffffffff) ^ 0x80000000) - 0x80000000;
! 	  return GEN_INT (val);
! 	}
! #if HOST_BITS_PER_WIDE_INT >= 64
        else if (BITS_PER_WORD >= 64 && i == 0)
! 	{
! 	  val = k[! WORDS_BIG_ENDIAN];
! 	  val = (((val & 0xffffffff) ^ 0x80000000) - 0x80000000) << 32;
! 	  val |= (HOST_WIDE_INT) k[WORDS_BIG_ENDIAN] & 0xffffffff;
! 	  return GEN_INT (val);
! 	}
  #endif
        else if (BITS_PER_WORD == 16)
  	{
! 	  val = k[i >> 1];
! 	  if ((i & 1) == !WORDS_BIG_ENDIAN)
! 	    val >>= 16;
! 	  val &= 0xffff;
! 	  return GEN_INT (val);
  	}
        else
  	abort ();
*************** operand_subword (op, i, validate_address
*** 1307,1313 ****
      REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k);
  
      if (BITS_PER_WORD == 32)
!       return GEN_INT ((HOST_WIDE_INT) k[i]);
    }
  #else /* no REAL_ARITHMETIC */
    if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
--- 1318,1330 ----
      REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k);
  
      if (BITS_PER_WORD == 32)
!       {
! 	val = k[i];
! 	val = ((val & 0xffffffff) ^ 0x80000000) - 0x80000000;
! 	return GEN_INT (val);
!       }
!     else
!       abort ();
    }
  #else /* no REAL_ARITHMETIC */
    if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
*************** operand_subword (op, i, validate_address
*** 1344,1369 ****
  
        REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
        REAL_VALUE_TO_TARGET_SINGLE (rv, l);
- 
-       /* If 32 bits is an entire word for the target, but not for the host,
- 	 then sign-extend on the host so that the number will look the same
- 	 way on the host that it would on the target.  See for instance
- 	 simplify_unary_operation.  The #if is needed to avoid compiler
- 	 warnings.  */
  
! #if HOST_BITS_PER_LONG > 32
!       if (BITS_PER_WORD < HOST_BITS_PER_LONG && BITS_PER_WORD == 32
! 	  && (l & ((long) 1 << 31)))
! 	l |= ((long) (-1) << 32);
! #endif
  
        if (BITS_PER_WORD == 16)
  	{
! 	  if ((i & 0x1) == !WORDS_BIG_ENDIAN)
! 	    l >>= 16;
! 	  l &= 0xffff;
  	}
!       return GEN_INT ((HOST_WIDE_INT) l);
      }
  #else
    if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
--- 1361,1379 ----
  
        REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
        REAL_VALUE_TO_TARGET_SINGLE (rv, l);
  
!       /* Sign extend from known 32-bit value to HOST_WIDE_INT.  */
!       val = l;
!       val = ((val & 0xffffffff) ^ 0x80000000) - 0x80000000;
  
        if (BITS_PER_WORD == 16)
  	{
! 	  if ((i & 1) == !WORDS_BIG_ENDIAN)
! 	    val >>= 16;
! 	  val &= 0xffff;
  	}
! 
!       return GEN_INT (val);
      }
  #else
    if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT


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