From 9bf8799c8f4e0ad294bcf6f214c718925e298d20 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Sat, 15 Apr 2017 15:05:58 +0200 Subject: [PATCH] imath backend: use tailored isl_int_fdiv_q_ui In particular, simply convert the unsigned long argument to an mpz_t and call impz_fdiv_q. impz_fdiv_q_ui does essentially the same, but it computes the integer division twice, once to get the quotient and once to get the remainder. The remainder is needed because impz_fdiv_q_ui is meant to mimic gmp's mpz_fdiv_q_ui, which returns this remainder. However, there is no need for the isl_int_fdiv_q_ui macro to return this remainder. This change is unlikely to result in any measurable performance improvement, but it still feels better to only compute the integer division once. Signed-off-by: Sven Verdoolaege --- imath_wrap/wrap.h | 1 - isl_imath.c | 14 ++++++++++++++ isl_imath.h | 1 + isl_int_imath.h | 2 +- 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/imath_wrap/wrap.h b/imath_wrap/wrap.h index f68e50d2..a2ea88f8 100644 --- a/imath_wrap/wrap.h +++ b/imath_wrap/wrap.h @@ -39,7 +39,6 @@ #define impz_divisible_p isl_impz_divisible_p #define impz_export isl_impz_export #define impz_fdiv_q isl_impz_fdiv_q -#define impz_fdiv_q_ui isl_impz_fdiv_q_ui #define impz_fdiv_r isl_impz_fdiv_r #define impz_gcd isl_impz_gcd #define impz_get_si isl_impz_get_si diff --git a/isl_imath.c b/isl_imath.c index cffd79a1..3a5e1acc 100644 --- a/isl_imath.c +++ b/isl_imath.c @@ -53,3 +53,17 @@ void isl_imath_submul_ui(mp_int rop, mp_int op1, unsigned long op2) mp_int_clear(&temp); } + +/* Compute the division of lhs by a rhs of type unsigned long, rounding towards + * negative infinity (Floor). + */ +void isl_imath_fdiv_q_ui(mp_int rop, mp_int lhs, unsigned long rhs) +{ + mpz_t temp; + mp_int_init(&temp); + + mp_int_set_uvalue(&temp, rhs); + impz_fdiv_q(rop, lhs, &temp); + + mp_int_clear(&temp); +} diff --git a/isl_imath.h b/isl_imath.h index d51e03cb..24149906 100644 --- a/isl_imath.h +++ b/isl_imath.h @@ -6,3 +6,4 @@ int isl_imath_fits_ulong_p(mp_int op); int isl_imath_fits_slong_p(mp_int op); void isl_imath_addmul_ui(mp_int rop, mp_int op1, unsigned long op2); void isl_imath_submul_ui(mp_int rop, mp_int op1, unsigned long op2); +void isl_imath_fdiv_q_ui(mp_int rop, mp_int op1, unsigned long op2); diff --git a/isl_int_imath.h b/isl_int_imath.h index e5b7186b..902edf89 100644 --- a/isl_int_imath.h +++ b/isl_int_imath.h @@ -47,7 +47,7 @@ typedef mp_int isl_int; #define isl_int_cdiv_q(r,i,j) impz_cdiv_q(r,i,j) #define isl_int_fdiv_q(r,i,j) impz_fdiv_q(r,i,j) #define isl_int_fdiv_r(r,i,j) impz_fdiv_r(r,i,j) -#define isl_int_fdiv_q_ui(r,i,j) impz_fdiv_q_ui(r,i,j) +#define isl_int_fdiv_q_ui(r,i,j) isl_imath_fdiv_q_ui(r,i,j) #define isl_int_read(r,s) impz_set_str(r,s,10) #define isl_int_sgn(i) impz_sgn(i) -- 2.11.4.GIT