[Gmp-commit] /var/hg/gmp: 2 new changesets
mercurial at gmplib.org
mercurial at gmplib.org
Sun Feb 17 18:02:10 CET 2013
details: /var/hg/gmp/rev/2525f523f5fc
changeset: 15451:2525f523f5fc
user: Marco Bodrato <bodrato at mail.dm.unipi.it>
date: Sun Feb 17 17:56:47 2013 +0100
description:
gmpxx.h (mpq_class, mpf_class): Some more SI->UI optimisations.
details: /var/hg/gmp/rev/7d5b3f42ed8e
changeset: 15452:7d5b3f42ed8e
user: Marco Bodrato <bodrato at mail.dm.unipi.it>
date: Sun Feb 17 18:00:40 2013 +0100
description:
ChangeLog
diffstat:
ChangeLog | 6 ++++++
gmpxx.h | 51 +++++++++++++++++++++++++++++++++------------------
2 files changed, 39 insertions(+), 18 deletions(-)
diffs (98 lines):
diff -r 6de9702a1bc7 -r 7d5b3f42ed8e ChangeLog
--- a/ChangeLog Sun Feb 17 11:15:11 2013 +0100
+++ b/ChangeLog Sun Feb 17 18:00:40 2013 +0100
@@ -1,3 +1,9 @@
+2013-02-17 Marco Bodrato <bodrato at mail.dm.unipi.it>
+
+ * gmpxx.h (mpq_class, mpf_class) [init_ui, init_si, assign_si]:
+ Optimise _si using _ui for positive arguments.
+ (__gmp_hypot_function): Use _mul_ui to square an ui, abs for si.
+
2013-02-17 Marc Glisse <marc.glisse at inria.fr>
* cxx/osdoprnti.cc: Use <stdarg.h> and <string.h> rather than <cstdarg>
diff -r 6de9702a1bc7 -r 7d5b3f42ed8e gmpxx.h
--- a/gmpxx.h Sun Feb 17 11:15:11 2013 +0100
+++ b/gmpxx.h Sun Feb 17 18:00:40 2013 +0100
@@ -1072,24 +1072,15 @@
mpf_init2(temp, mpf_get_prec(f));
mpf_mul(temp, g, g);
mpf_set_ui(f, l);
- mpf_mul(f, f, f);
+ mpf_mul_ui(f, f, l);
mpf_add(f, f, temp);
+ mpf_clear(temp);
mpf_sqrt(f, f);
- mpf_clear(temp);
}
static void eval(mpf_ptr f, unsigned long int l, mpf_srcptr g)
{ eval(f, g, l); }
static void eval(mpf_ptr f, mpf_srcptr g, signed long int l)
- {
- mpf_t temp;
- mpf_init2(temp, mpf_get_prec(f));
- mpf_mul(temp, g, g);
- mpf_set_si(f, l);
- mpf_mul(f, f, f);
- mpf_add(f, f, temp);
- mpf_sqrt(f, f);
- mpf_clear(temp);
- }
+ { eval(f, g, __gmpxx_abs_ui(l)); }
static void eval(mpf_ptr f, signed long int l, mpf_srcptr g)
{ eval(f, g, l); }
static void eval(mpf_ptr f, mpf_srcptr g, double d)
@@ -1613,11 +1604,17 @@
// Helper functions used for all arithmetic types
void assign_ui(unsigned long l) { mpq_set_ui(mp, l, 1); }
- void assign_si(signed long l) { mpq_set_si(mp, l, 1); }
+ void assign_si(signed long l)
+ {
+ if (__GMPXX_CONSTANT_TRUE(l >= 0))
+ assign_ui(l);
+ else
+ mpq_set_si(mp, l, 1);
+ }
void assign_d (double d) { mpq_set_d (mp, d); }
- void init_ui(unsigned long l) { mpq_init(mp); assign_ui(l); }
- void init_si(signed long l) { mpq_init(mp); assign_si(l); }
+ void init_ui(unsigned long l) { mpq_init(mp); get_num() = l; }
+ void init_si(signed long l) { mpq_init(mp); get_num() = l; }
void init_d (double d) { mpq_init(mp); assign_d (d); }
public:
@@ -1785,11 +1782,29 @@
// Helper functions used for all arithmetic types
void assign_ui(unsigned long l) { mpf_set_ui(mp, l); }
- void assign_si(signed long l) { mpf_set_si(mp, l); }
+ void assign_si(signed long l)
+ {
+ if (__GMPXX_CONSTANT_TRUE(l >= 0))
+ assign_ui(l);
+ else
+ mpf_set_si(mp, l);
+ }
void assign_d (double d) { mpf_set_d (mp, d); }
- void init_ui(unsigned long l) { mpf_init_set_ui(mp, l); }
- void init_si(signed long l) { mpf_init_set_si(mp, l); }
+ void init_ui(unsigned long l)
+ {
+ if (__GMPXX_CONSTANT_TRUE(l == 0))
+ mpf_init(mp);
+ else
+ mpf_init_set_ui(mp, l);
+ }
+ void init_si(signed long l)
+ {
+ if (__GMPXX_CONSTANT_TRUE(l >= 0))
+ init_ui(l);
+ else
+ mpf_init_set_si(mp, l);
+ }
void init_d (double d) { mpf_init_set_d (mp, d); }
public:
More information about the gmp-commit
mailing list