Commit b7398e72 by Tobias Schlüter Committed by Paul Brook

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
parent bf737879
2004-10-30 Tobias Schlueter <tobias.schlueter@physik.uni-muenchen.de> 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 * trans.c (gfc_trans_code): Set global locus after recursing. Fix
comment typo. comment typo.
......
...@@ -146,19 +146,17 @@ static void ...@@ -146,19 +146,17 @@ static void
twos_complement (mpz_t x, int bitsize) twos_complement (mpz_t x, int bitsize)
{ {
mpz_t mask; mpz_t mask;
char mask_s[bitsize + 1];
if (mpz_tstbit (x, bitsize - 1) == 1) if (mpz_tstbit (x, bitsize - 1) == 1)
{ {
/* The mpz_init_set_{u|s}i functions take a long argument, but mpz_init_set_ui(mask, 1);
the widest integer the target supports might be wider, so we mpz_mul_2exp(mask, mask, bitsize);
have to go via an intermediate string. */ mpz_sub_ui(mask, mask, 1);
memset (mask_s, '1', bitsize);
mask_s[bitsize] = '\0';
mpz_init_set_str (mask, mask_s, 2);
/* We negate the number by hand, zeroing the high bits, and then /* We negate the number by hand, zeroing the high bits, that is
have it negated by GMP. */ 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_com (x, x);
mpz_add_ui (x, x, 1); mpz_add_ui (x, x, 1);
mpz_and (x, x, mask); mpz_and (x, x, mask);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment