diff options
author | Andy Wingo <wingo@pobox.com> | 2022-01-30 21:15:58 +0100 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2022-02-01 19:57:14 +0100 |
commit | 62fc44e6ee6165253fa33dc6f8897c7bde620a05 (patch) | |
tree | 47a47e344c069263a14257249a60a6fca35a19a3 | |
parent | 54bbe0b2846c5b1aa366c91d679ba724869c8cda (diff) | |
download | guile-62fc44e6ee6165253fa33dc6f8897c7bde620a05.tar.gz |
Slight bignum-fixnum multiplication optimization
* libguile/integers.c (scm_integer_mul_zi): Use mpn_mul_1.
-rw-r--r-- | libguile/integers.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/libguile/integers.c b/libguile/integers.c index adf1c401e..168593da5 100644 --- a/libguile/integers.c +++ b/libguile/integers.c @@ -3094,13 +3094,17 @@ scm_integer_mul_zi (struct scm_bignum *x, scm_t_inum y) return SCM_INUM0; struct scm_bignum *result = allocate_bignum (xn + 1); + mp_limb_t *rd = bignum_limbs (result); const mp_limb_t *xd = bignum_limbs (x); - mp_limb_t yd[1] = { long_magnitude (y) }; + mp_limb_t yd = long_magnitude (y); int negate = bignum_is_negative (x) != (y < 0); - mpn_mul (bignum_limbs (result), xd, xn, yd, 1); + mp_limb_t hi = mpn_mul_1 (rd, xd, xn, yd); + if (hi) + rd[xn] = hi; + else + result->u.z.size--; scm_remember_upto_here_1 (x); - return normalize_bignum - (bignum_negate_if (negate, (bignum_trim1 (result)))); + return normalize_bignum (bignum_negate_if (negate, (result))); } } } |