simplify.c (twos_complement): Calculate mask in GMP arithmetic.
authorTobias Schlüter <tobias.schlueter@physik.uni-muenchen.de>
Sat, 30 Oct 2004 14:42:22 +0000 (14:42 +0000)
committerPaul Brook <pbrook@gcc.gnu.org>
Sat, 30 Oct 2004 14:42:22 +0000 (14:42 +0000)
2004-10-30  Tobias Schlueter  <tobias.schlueter@physik.uni-muenchen.de>

* simplify.c (twos_complement): Calculate mask in GMP arithmetic.

From-SVN: r89888

gcc/fortran/ChangeLog
gcc/fortran/simplify.c

index b66bc3ed8d1717e7f525fd845a531931fac4c260..8c81b0bbe14657eace14a08e29837819bce56db1 100644 (file)
@@ -1,3 +1,7 @@
+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
index 253f68677a12367e636dc8c49a79ef95f2767b1e..5004b83acc9485a3ee10b21f2cb814177d937a77 100644 (file)
@@ -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);