[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 75/85: Start to optimize scm_integer_sub_iz
From: |
Andy Wingo |
Subject: |
[Guile-commits] 75/85: Start to optimize scm_integer_sub_iz |
Date: |
Thu, 13 Jan 2022 03:40:26 -0500 (EST) |
wingo pushed a commit to branch main
in repository guile.
commit cae8b30163835c96b3ed268a24ae19c414dc42ac
Author: Andy Wingo <wingo@pobox.com>
AuthorDate: Sun Jan 9 21:10:14 2022 +0100
Start to optimize scm_integer_sub_iz
* libguile/integers.c (scm_integer_sub_iz): Avoid cloning bignum.
---
libguile/integers.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/libguile/integers.c b/libguile/integers.c
index b368f52db..64fed6362 100644
--- a/libguile/integers.c
+++ b/libguile/integers.c
@@ -2869,7 +2869,19 @@ scm_integer_sub_ii (scm_t_inum x, scm_t_inum y)
SCM
scm_integer_sub_iz (scm_t_inum x, struct scm_bignum *y)
{
- return scm_integer_add_zi (negate_bignum (clone_bignum (y)), x);
+ if (x == 0)
+ return scm_integer_negate_z (y);
+
+ mpz_t result, zx, zy;
+ mpz_init (result);
+ mpz_init_set_si (zx, x);
+ alias_bignum_to_mpz (y, zy);
+ mpz_sub (result, zx, zy);
+ scm_remember_upto_here_1 (y);
+ mpz_clear (zx);
+ // FIXME: We know that if X is negative, no need to check if
+ // result is fixable.
+ return take_mpz (result);
}
SCM
- [Guile-commits] 82/85: Simplify scm_abs for the real case, (continued)
- [Guile-commits] 82/85: Simplify scm_abs for the real case, Andy Wingo, 2022/01/13
- [Guile-commits] 09/85: Implement ceiling-divide with new integer lib, Andy Wingo, 2022/01/13
- [Guile-commits] 08/85: Implement ceiling-remainder with new integer lib, Andy Wingo, 2022/01/13
- [Guile-commits] 11/85: Implement truncate-remainder with new integer lib, Andy Wingo, 2022/01/13
- [Guile-commits] 49/85: Reimplement scm_from_int8 etc, Andy Wingo, 2022/01/13
- [Guile-commits] 55/85: Reimplement exact-integer-sqrt with integers.[ch], Andy Wingo, 2022/01/13
- [Guile-commits] 56/85: Refactor scm_sqrt in terms of integers.[ch], Andy Wingo, 2022/01/13
- [Guile-commits] 62/85: Simplify magnitude, angle, Andy Wingo, 2022/01/13
- [Guile-commits] 65/85: Start porting srfi-60 off the bad bignum interfaces, Andy Wingo, 2022/01/13
- [Guile-commits] 72/85: Optimize scm_integer_mul_zi, Andy Wingo, 2022/01/13
- [Guile-commits] 75/85: Start to optimize scm_integer_sub_iz,
Andy Wingo <=
- [Guile-commits] 77/85: Optimize bignum add to avoid temporary allocations, Andy Wingo, 2022/01/13