aboutsummaryrefslogtreecommitdiff
path: root/gcc/explow.c
diff options
context:
space:
mode:
authorAlexandre Oliva <aoliva@redhat.com>2001-02-13 06:39:45 +0000
committerAlexandre Oliva <aoliva@gcc.gnu.org>2001-02-13 06:39:45 +0000
commit5b0d91c39237f6a45dcb229620bbf5c144b29c62 (patch)
tree7b015877b972e243b2a4efd84b3be03b3d775a5f /gcc/explow.c
parent4b01cd8fbf7e5bd516fbebaf4a86910cc88e8566 (diff)
downloadgcc-5b0d91c39237f6a45dcb229620bbf5c144b29c62.zip
gcc-5b0d91c39237f6a45dcb229620bbf5c144b29c62.tar.gz
gcc-5b0d91c39237f6a45dcb229620bbf5c144b29c62.tar.bz2
* explow.c (trunc_int_for_mode): Sign-extend value to mode.
From-SVN: r39615
Diffstat (limited to 'gcc/explow.c')
-rw-r--r--gcc/explow.c32
1 files changed, 10 insertions, 22 deletions
diff --git a/gcc/explow.c b/gcc/explow.c
index b7c0bb9..719421f 100644
--- a/gcc/explow.c
+++ b/gcc/explow.c
@@ -56,28 +56,16 @@ trunc_int_for_mode (c, mode)
if (mode == BImode)
return c & 1 ? STORE_FLAG_VALUE : 0;
- /* We clear out all bits that don't belong in MODE, unless they and our
- sign bit are all one. So we get either a reasonable negative
- value or a reasonable unsigned value. */
-
- if (width < HOST_BITS_PER_WIDE_INT
- && ((c & ((HOST_WIDE_INT) (-1) << (width - 1)))
- != ((HOST_WIDE_INT) (-1) << (width - 1))))
- c &= ((HOST_WIDE_INT) 1 << width) - 1;
-
- /* If this would be an entire word for the target, but is 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.
-
- For example, when building a 64 bit alpha hosted 32 bit sparc
- targeted compiler, then we want the 32 bit unsigned value -1 to be
- represented as a 64 bit value -1, and not as 0x00000000ffffffff.
- The later confuses the sparc backend. */
-
- if (BITS_PER_WORD < HOST_BITS_PER_WIDE_INT
- && BITS_PER_WORD == width
- && (c & ((HOST_WIDE_INT) 1 << (width - 1))))
- c |= ((HOST_WIDE_INT) (-1) << width);
+ /* Sign-extend for the requested mode. */
+
+ if (width < HOST_BITS_PER_WIDE_INT)
+ {
+ HOST_WIDE_INT sign = 1;
+ sign <<= width - 1;
+ c &= (sign << 1) - 1;
+ c ^= sign;
+ c -= sign;
+ }
return c;
}