[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 74/85: Less pessimal scm_integer_sub_zi
From: |
Andy Wingo |
Subject: |
[Guile-commits] 74/85: Less pessimal scm_integer_sub_zi |
Date: |
Thu, 13 Jan 2022 03:40:25 -0500 (EST) |
wingo pushed a commit to branch main
in repository guile.
commit 27235137129be7fb35a114e939a9709ede4f164d
Author: Andy Wingo <wingo@pobox.com>
AuthorDate: Sun Jan 9 20:48:45 2022 +0100
Less pessimal scm_integer_sub_zi
* libguile/integers.c (scm_integer_sub_zi): Only delegate to
scm_integer_add_ii if y is negative.
---
libguile/integers.c | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)
diff --git a/libguile/integers.c b/libguile/integers.c
index 60c0fd34a..b368f52db 100644
--- a/libguile/integers.c
+++ b/libguile/integers.c
@@ -2875,10 +2875,22 @@ scm_integer_sub_iz (scm_t_inum x, struct scm_bignum *y)
SCM
scm_integer_sub_zi (struct scm_bignum *x, scm_t_inum y)
{
- // Assumes that -INUM_MIN can fit in a scm_t_inum, even if that
- // scm_t_inum is not fixable, and that scm_integer_add_ii can handle
- // scm_t_inum inputs outside the fixable range.
- return scm_integer_add_zi (x, -y);
+ if (y == 0)
+ return scm_from_bignum (x);
+ if (y < 0)
+ // Assumes that -INUM_MIN can fit in a scm_t_inum, even if that
+ // scm_t_inum is not fixable, and that scm_integer_add_ii can handle
+ // scm_t_inum inputs outside the fixable range.
+ return scm_integer_add_zi (x, -y);
+
+ mpz_t result, zx;
+ mpz_init (result);
+ alias_bignum_to_mpz (x, zx);
+ mpz_sub_ui (result, zx, y);
+ scm_remember_upto_here_1 (x);
+ // FIXME: We know that if X is negative, no need to check if
+ // result is fixable.
+ return take_mpz (result);
}
SCM
- [Guile-commits] 45/85: Clean up scm_divide, (continued)
- [Guile-commits] 45/85: Clean up scm_divide, Andy Wingo, 2022/01/13
- [Guile-commits] 46/85: Fix deprecated bit-count* when counting 0 bits, Andy Wingo, 2022/01/13
- [Guile-commits] 48/85: Reimplement scm_is_{un, }signed_integer for bignums, Andy Wingo, 2022/01/13
- [Guile-commits] 54/85: scm_to_mpz uses integer lib, Andy Wingo, 2022/01/13
- [Guile-commits] 51/85: Reimplement scm_{to,from}_{int64,uint64}, Andy Wingo, 2022/01/13
- [Guile-commits] 52/85: Implement scm_{to,from}_wchar inline, Andy Wingo, 2022/01/13
- [Guile-commits] 58/85: Remove dead bignum frexp code from numbers.c, Andy Wingo, 2022/01/13
- [Guile-commits] 53/85: Remove unused conv-{u,}integer.i.c, Andy Wingo, 2022/01/13
- [Guile-commits] 63/85: Use scm_integer_to_double_z in numbers.c instead of big2dbl, Andy Wingo, 2022/01/13
- [Guile-commits] 66/85: Finish srfi-60 port off old scm mpz API, Andy Wingo, 2022/01/13
- [Guile-commits] 74/85: Less pessimal scm_integer_sub_zi,
Andy Wingo <=
- [Guile-commits] 76/85: Avoid bignum clone in scm_integer_sub_zz, Andy Wingo, 2022/01/13
- [Guile-commits] 79/85: Optimize scm_integer_mul_ii, Andy Wingo, 2022/01/13
- [Guile-commits] 80/85: Optimize integer-expt for fixnums, Andy Wingo, 2022/01/13
- [Guile-commits] 81/85: Optimize logand against a positive inum, Andy Wingo, 2022/01/13
- [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