summaryrefslogtreecommitdiff
path: root/gmpxx.h
diff options
context:
space:
mode:
authorMarc Glisse <marc.glisse@inria.fr>2016-10-28 21:51:33 +0200
committerMarc Glisse <marc.glisse@inria.fr>2016-10-28 21:51:33 +0200
commit4225225d5de516221eb771aacf5cc0615da96787 (patch)
tree0675d96fd2620a29c76d0913286b2c2964079428 /gmpxx.h
parentffb534049ff90767cd30e562930d67a6529d1908 (diff)
downloadgmp-4225225d5de516221eb771aacf5cc0615da96787.tar.gz
Optimize 1/q to call mpq_inv.
Also handle (-1)/q and 0/q. We could test for l == 1 at runtime and not just with __builtin_constant_p, it might be worth it, especially for non-gcc compilers.
Diffstat (limited to 'gmpxx.h')
-rw-r--r--gmpxx.h29
1 files changed, 27 insertions, 2 deletions
diff --git a/gmpxx.h b/gmpxx.h
index 10b655add..389c0d424 100644
--- a/gmpxx.h
+++ b/gmpxx.h
@@ -689,7 +689,17 @@ struct __gmp_binary_divides
}
}
static void eval(mpq_ptr q, unsigned long int l, mpq_srcptr r)
- { __GMPXX_TMPQ_UI; mpq_div (q, temp, r); }
+ {
+ if (__GMPXX_CONSTANT_TRUE(l == 0))
+ mpq_set_ui(q, 0, 1);
+ else if (__GMPXX_CONSTANT_TRUE(l == 1))
+ mpq_inv(q, r);
+ else
+ {
+ __GMPXX_TMPQ_UI;
+ mpq_div (q, temp, r);
+ }
+ }
static void eval(mpq_ptr q, mpq_srcptr r, signed long int l)
{
if (__GMPXX_CONSTANT_TRUE(l >= 0))
@@ -706,7 +716,22 @@ struct __gmp_binary_divides
}
}
static void eval(mpq_ptr q, signed long int l, mpq_srcptr r)
- { __GMPXX_TMPQ_SI; mpq_div (q, temp, r); }
+ {
+ if (__GMPXX_CONSTANT_TRUE(l == 0))
+ mpq_set_ui(q, 0, 1);
+ else if (__GMPXX_CONSTANT_TRUE(l == 1))
+ mpq_inv(q, r);
+ else if (__GMPXX_CONSTANT_TRUE(l == -1))
+ {
+ mpq_inv(q, r);
+ mpq_neg(q, q);
+ }
+ else
+ {
+ __GMPXX_TMPQ_SI;
+ mpq_div (q, temp, r);
+ }
+ }
static void eval(mpq_ptr q, mpq_srcptr r, double d)
{ __GMPXX_TMPQ_D; mpq_div (q, r, temp); }
static void eval(mpq_ptr q, double d, mpq_srcptr r)