[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gawk-diffs] [SCM] gawk branch, master, updated. gawk-4.1.0-2410-g2da83e
From: |
Andrew J. Schorr |
Subject: |
[gawk-diffs] [SCM] gawk branch, master, updated. gawk-4.1.0-2410-g2da83e9 |
Date: |
Sun, 22 Jan 2017 21:11:23 +0000 (UTC) |
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "gawk".
The branch, master has been updated
via 2da83e944e432692f5576ce4baa9831dce13eb77 (commit)
from ae02ce389bfd1bcb2797fe64d73a91ef73705688 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://git.sv.gnu.org/cgit/gawk.git/commit/?id=2da83e944e432692f5576ce4baa9831dce13eb77
commit 2da83e944e432692f5576ce4baa9831dce13eb77
Author: Andrew J. Schorr <address@hidden>
Date: Sun Jan 22 16:10:43 2017 -0500
Minor performance optimization for numeric operations.
diff --git a/ChangeLog b/ChangeLog
index 44aa730..944b26e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2017-01-22 Andrew J. Schorr <address@hidden>
+
+ * awk.h (numtype_choose): New backend macro used to implement
+ various macros whose calculations depend on how a number is
+ actually represented. This improves readability and should give
+ a small performance improvement when not using extended precision.
+ (get_number_ui, get_number_si, get_number_d, get_number_uj, iszero):
+ Rewrite using new numtype_choose macro.
+
2017-01-04 Arnold Robbins <address@hidden>
Trade space for time for programs that toggle IGNORECASE a lot.
diff --git a/awk.h b/awk.h
index d5c88fd..34c0e07 100644
--- a/awk.h
+++ b/awk.h
@@ -1251,23 +1251,34 @@ DEREF(NODE *r)
/* ------------------------- Pseudo-functions ------------------------- */
#ifdef HAVE_MPFR
+
+#if 0
+
+/*
+ * In principle, there is no need to have both the MPFN and MPZN flags,
+ * since we are using 2 bits to encode 1 bit of information. But
+ * there may be some minor performance advantages from testing only the
+ * node flag bits without needing also to access the global do_mpfr flag bit.
+ */
+#define numtype_choose(n, mpfrval, mpzval, dblval) \
+ (!do_mpfr ? (dblval) : (((n)->flags & MPFN) ? (mpfrval) : (mpzval)))
+
+#endif
+
+/* N.B. This implementation seems to give the fastest results. */
+#define numtype_choose(n, mpfrval, mpzval, dblval) \
+ (!((n)->flags & (MPFN|MPZN)) ? (dblval) : (((n)->flags & MPFN) ? (mpfrval) :
(mpzval)))
+
/* conversion to C types */
-#define get_number_ui(n) (((n)->flags & MPFN) ?
mpfr_get_ui((n)->mpg_numbr, ROUND_MODE) \
- : ((n)->flags & MPZN) ? mpz_get_ui((n)->mpg_i) \
- : (unsigned long) (n)->numbr)
-#define get_number_si(n) (((n)->flags & MPFN) ?
mpfr_get_si((n)->mpg_numbr, ROUND_MODE) \
- : ((n)->flags & MPZN) ? mpz_get_si((n)->mpg_i) \
- : (long) (n)->numbr)
-#define get_number_d(n) (((n)->flags & MPFN) ?
mpfr_get_d((n)->mpg_numbr, ROUND_MODE) \
- : ((n)->flags & MPZN) ? mpz_get_d((n)->mpg_i) \
- : (double) (n)->numbr)
-#define get_number_uj(n) (((n)->flags & MPFN) ?
mpfr_get_uj((n)->mpg_numbr, ROUND_MODE) \
- : ((n)->flags & MPZN) ? (uintmax_t)
mpz_get_d((n)->mpg_i) \
- : (uintmax_t) (n)->numbr)
-
-#define iszero(n) (((n)->flags & MPFN) ?
mpfr_zero_p((n)->mpg_numbr) \
- : ((n)->flags & MPZN) ? (mpz_sgn((n)->mpg_i) ==
0) \
- : ((n)->numbr == 0.0))
+#define get_number_ui(n) numtype_choose((n), mpfr_get_ui((n)->mpg_numbr,
ROUND_MODE), mpz_get_ui((n)->mpg_i), (unsigned long) (n)->numbr)
+
+#define get_number_si(n) numtype_choose((n), mpfr_get_si((n)->mpg_numbr,
ROUND_MODE), mpz_get_si((n)->mpg_i), (long) (n)->numbr)
+
+#define get_number_d(n) numtype_choose((n),
mpfr_get_d((n)->mpg_numbr, ROUND_MODE), mpz_get_d((n)->mpg_i), (double)
(n)->numbr)
+
+#define get_number_uj(n) numtype_choose((n), mpfr_get_uj((n)->mpg_numbr,
ROUND_MODE), (uintmax_t) mpz_get_d((n)->mpg_i), (uintmax_t) (n)->numbr)
+
+#define iszero(n) numtype_choose((n),
mpfr_zero_p((n)->mpg_numbr), (mpz_sgn((n)->mpg_i) == 0), ((n)->numbr == 0.0))
#define IEEE_FMT(r, t) (void) (do_ieee_fmt && format_ieee(r, t))
-----------------------------------------------------------------------
Summary of changes:
ChangeLog | 9 +++++++++
awk.h | 43 +++++++++++++++++++++++++++----------------
2 files changed, 36 insertions(+), 16 deletions(-)
hooks/post-receive
--
gawk
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gawk-diffs] [SCM] gawk branch, master, updated. gawk-4.1.0-2410-g2da83e9,
Andrew J. Schorr <=