From 4823ebd9ec3a5160f95aade0ec87d0218d1f19f3 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 10 Jul 2024 10:23:31 +0200 Subject: [PATCH 09/17] In timefns, prefer ui mul and div * src/timefns.c (ticks_hz_hz_ticks): If the multiplier is a fixnum that fits in unsigned long, use mpz_mul_ui instead of the more-expensive mpz_mul. Similarly, if the divisor is a fixnum that fits in unsigned long, use mpz_fdiv_q_ui instead of mpz_fdiv_q. --- src/timefns.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/timefns.c b/src/timefns.c index 0a34bda28c7..0df7d1f4363 100644 --- a/src/timefns.c +++ b/src/timefns.c @@ -796,10 +796,15 @@ ticks_hz_hz_ticks (struct ticks_hz t, Lisp_Object hz) invalid_hz (hz); /* Fall back on bignum arithmetic. */ - mpz_mul (mpz[0], - *bignum_integer (&mpz[0], t.ticks), - *bignum_integer (&mpz[1], hz)); - mpz_fdiv_q (mpz[0], mpz[0], *bignum_integer (&mpz[1], t.hz)); + mpz_t const *zticks = bignum_integer (&mpz[0], t.ticks); + if (FASTER_TIMEFNS && FIXNUMP (hz) && XFIXNUM (hz) <= ULONG_MAX) + mpz_mul_ui (mpz[0], *zticks, XFIXNUM (hz)); + else + mpz_mul (mpz[0], *zticks, *bignum_integer (&mpz[1], hz)); + if (FASTER_TIMEFNS && FIXNUMP (t.hz) && XFIXNUM (t.hz) <= ULONG_MAX) + mpz_fdiv_q_ui (mpz[0], mpz[0], XFIXNUM (t.hz)); + else + mpz_fdiv_q (mpz[0], mpz[0], *bignum_integer (&mpz[1], t.hz)); return make_integer_mpz (); } -- 2.34.1