From 9ebe2e057d0ea0a16c255b8811825d2410ce158a Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 10 Jul 2024 10:23:31 +0200 Subject: [PATCH] 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. (cherry picked from commit abafc6ca01444de7aad9856b4901aa82a68dff32) --- 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.39.2