aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorTobias Schlüter <tobias.schlueter@physik.uni-muenchen.de>2004-10-30 14:42:22 +0000
committerPaul Brook <pbrook@gcc.gnu.org>2004-10-30 14:42:22 +0000
commitb7398e72283f52174a54dcc7e988b48f8131a9d2 (patch)
tree9fdf66a2787567031f0f0ee0ba547ba40751b7a7 /gcc
parentbf737879fa82bd9797ad559518dfab1ce9e1f4d6 (diff)
downloadgcc-b7398e72283f52174a54dcc7e988b48f8131a9d2.zip
gcc-b7398e72283f52174a54dcc7e988b48f8131a9d2.tar.gz
gcc-b7398e72283f52174a54dcc7e988b48f8131a9d2.tar.bz2
simplify.c (twos_complement): Calculate mask in GMP arithmetic.
2004-10-30 Tobias Schlueter <tobias.schlueter@physik.uni-muenchen.de> * simplify.c (twos_complement): Calculate mask in GMP arithmetic. From-SVN: r89888
Diffstat (limited to 'gcc')
-rw-r--r--gcc/fortran/ChangeLog4
-rw-r--r--gcc/fortran/simplify.c16
2 files changed, 11 insertions, 9 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index b66bc3ed..8c81b0b 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,5 +1,9 @@
2004-10-30 Tobias Schlueter <tobias.schlueter@physik.uni-muenchen.de>
+ * simplify.c (twos_complement): Calculate mask in GMP arithmetic.
+
+2004-10-30 Tobias Schlueter <tobias.schlueter@physik.uni-muenchen.de>
+
* trans.c (gfc_trans_code): Set global locus after recursing. Fix
comment typo.
diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c
index 253f686..5004b83 100644
--- a/gcc/fortran/simplify.c
+++ b/gcc/fortran/simplify.c
@@ -146,19 +146,17 @@ static void
twos_complement (mpz_t x, int bitsize)
{
mpz_t mask;
- char mask_s[bitsize + 1];
if (mpz_tstbit (x, bitsize - 1) == 1)
{
- /* The mpz_init_set_{u|s}i functions take a long argument, but
- the widest integer the target supports might be wider, so we
- have to go via an intermediate string. */
- memset (mask_s, '1', bitsize);
- mask_s[bitsize] = '\0';
- mpz_init_set_str (mask, mask_s, 2);
+ mpz_init_set_ui(mask, 1);
+ mpz_mul_2exp(mask, mask, bitsize);
+ mpz_sub_ui(mask, mask, 1);
- /* We negate the number by hand, zeroing the high bits, and then
- have it negated by GMP. */
+ /* We negate the number by hand, zeroing the high bits, that is
+ make it the corresponding positive number, and then have it
+ negated by GMP, giving the correct representation of the
+ negative number. */
mpz_com (x, x);
mpz_add_ui (x, x, 1);
mpz_and (x, x, mask);