mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-04-30 20:00:19 +02:00
Optimize logand against a positive inum
* libguile/integers.c (scm_integer_logand_zi): Optimize.
This commit is contained in:
parent
6fe43301aa
commit
9e5aa173c7
1 changed files with 12 additions and 0 deletions
|
@ -2119,6 +2119,18 @@ scm_integer_logand_zi (struct scm_bignum *x, scm_t_inum y)
|
||||||
if (y == 0)
|
if (y == 0)
|
||||||
return SCM_INUM0;
|
return SCM_INUM0;
|
||||||
|
|
||||||
|
if (y > 0)
|
||||||
|
{
|
||||||
|
mp_limb_t rd = bignum_limbs (x)[0];
|
||||||
|
mp_limb_t yd = y;
|
||||||
|
if (bignum_is_negative (x))
|
||||||
|
rd = ~rd + 1;
|
||||||
|
scm_remember_upto_here_1 (x);
|
||||||
|
rd &= yd;
|
||||||
|
// Result must be a positive inum.
|
||||||
|
return SCM_I_MAKINUM (rd);
|
||||||
|
}
|
||||||
|
|
||||||
mpz_t result, zx, zy;
|
mpz_t result, zx, zy;
|
||||||
mpz_init (result);
|
mpz_init (result);
|
||||||
alias_bignum_to_mpz (x, zx);
|
alias_bignum_to_mpz (x, zx);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue