summaryrefslogtreecommitdiff
path: root/libguile/integers.c
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2022-01-10 11:56:13 +0100
committerAndy Wingo <wingo@pobox.com>2022-01-13 09:37:17 +0100
commit9e5aa173c79b2f14c8a1ffe758a91a63f52cc3b7 (patch)
treebb582432b28e5545074d757f5ec095cff56fa916 /libguile/integers.c
parent6fe43301aa66f898f3b27d604c45c93da5286e12 (diff)
downloadguile-9e5aa173c79b2f14c8a1ffe758a91a63f52cc3b7.tar.gz
Optimize logand against a positive inum
* libguile/integers.c (scm_integer_logand_zi): Optimize.
Diffstat (limited to 'libguile/integers.c')
-rw-r--r--libguile/integers.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/libguile/integers.c b/libguile/integers.c
index a173d01f2..a1231a10d 100644
--- a/libguile/integers.c
+++ b/libguile/integers.c
@@ -2119,6 +2119,18 @@ scm_integer_logand_zi (struct scm_bignum *x, scm_t_inum y)
if (y == 0)
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_init (result);
alias_bignum_to_mpz (x, zx);