This is the mail archive of the
glibc-cvs@sourceware.org
mailing list for the glibc project.
[glibc/ibm/2.30/master] [powerpc] libc_feupdateenv_test: optimize FPSCR access
- From: Paul Clarke <pc at sourceware dot org>
- To: glibc-cvs at sourceware dot org
- Date: 14 Nov 2019 01:50:52 -0000
- Subject: [glibc/ibm/2.30/master] [powerpc] libc_feupdateenv_test: optimize FPSCR access
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=11c0fd3ab34a06dd0faf401daecd07911414eb24
commit 11c0fd3ab34a06dd0faf401daecd07911414eb24
Author: Paul A. Clarke <pc@us.ibm.com>
Date: Thu Sep 19 11:18:33 2019 -0500
[powerpc] libc_feupdateenv_test: optimize FPSCR access
ROUND_TO_ODD and a couple of other places use libc_feupdateenv_test to
restore the rounding mode and exception enables, preserve exception flags,
and test whether given exception(s) were generated.
If the exception flags haven't changed, then it is sufficient and a bit
more efficient to just restore the rounding mode and enables, rather than
writing the full Floating-Point Status and Control Register (FPSCR).
Reviewed-by: Paul E. Murphy <murphyp@linux.ibm.com>
Diff:
---
ChangeLog | 6 ++++++
sysdeps/powerpc/fpu/fenv_libc.h | 4 ++++
sysdeps/powerpc/fpu/fenv_private.h | 16 ++++++++++++++--
3 files changed, 24 insertions(+), 2 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 7a633d7..5fde58a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
2019-09-27 Paul A. Clarke <pc@us.ibm.com>
+ * sysdeps/powerpc/fpu/fenv_libc.h (FPSCR_EXCEPTIONS_MASK): New.
+ * sysdeps/powerpc/fpu/fenv_private.h (__libc_femergeenv_ppc): Optimize
+ to write FPSCR control only, if exceptions have not changed.
+
+2019-09-27 Paul A. Clarke <pc@us.ibm.com>
+
* sysdeps/powerpc/fpu/fenv_libc.h:
(__TEST_AND_ENTER_NON_STOP): New.
(__TEST_AND_EXIT_NON_STOP): New.
diff --git a/sysdeps/powerpc/fpu/fenv_libc.h b/sysdeps/powerpc/fpu/fenv_libc.h
index 9163fb6..38ab6cd 100644
--- a/sysdeps/powerpc/fpu/fenv_libc.h
+++ b/sysdeps/powerpc/fpu/fenv_libc.h
@@ -256,6 +256,10 @@ enum {
(FPSCR_VE_MASK|FPSCR_OE_MASK|FPSCR_UE_MASK|FPSCR_ZE_MASK|FPSCR_XE_MASK)
#define FPSCR_BASIC_EXCEPTIONS_MASK \
(FPSCR_VX_MASK|FPSCR_OX_MASK|FPSCR_UX_MASK|FPSCR_ZX_MASK|FPSCR_XX_MASK)
+#define FPSCR_EXCEPTIONS_MASK (FPSCR_BASIC_EXCEPTIONS_MASK| \
+ FPSCR_VXSNAN_MASK|FPSCR_VXISI_MASK|FPSCR_VXIDI_MASK|FPSCR_VXZDZ_MASK| \
+ FPSCR_VXIMZ_MASK|FPSCR_VXVC_MASK|FPSCR_VXSOFT_MASK|FPSCR_VXSQRT_MASK| \
+ FPSCR_VXCVI_MASK)
#define FPSCR_FPRF_MASK \
(FPSCR_FPRF_C_MASK|FPSCR_FPRF_FL_MASK|FPSCR_FPRF_FG_MASK| \
FPSCR_FPRF_FE_MASK|FPSCR_FPRF_FU_MASK)
diff --git a/sysdeps/powerpc/fpu/fenv_private.h b/sysdeps/powerpc/fpu/fenv_private.h
index 0036cca..d080553 100644
--- a/sysdeps/powerpc/fpu/fenv_private.h
+++ b/sysdeps/powerpc/fpu/fenv_private.h
@@ -52,8 +52,20 @@ __libc_femergeenv_ppc (const fenv_t *envp, unsigned long long old_mask,
__TEST_AND_EXIT_NON_STOP (old.l, new.l);
__TEST_AND_ENTER_NON_STOP (old.l, new.l);
- /* Atomically enable and raise (if appropriate) exceptions set in `new'. */
- fesetenv_register (new.fenv);
+ /* If requesting to keep status, replace control, and merge exceptions,
+ and exceptions haven't changed, we can just set new control instead
+ of the whole FPSCR. */
+ if ((old_mask & (FPSCR_CONTROL_MASK|FPSCR_STATUS_MASK|FPSCR_EXCEPTIONS_MASK))
+ == (FPSCR_STATUS_MASK|FPSCR_EXCEPTIONS_MASK) &&
+ (new_mask & (FPSCR_CONTROL_MASK|FPSCR_STATUS_MASK|FPSCR_EXCEPTIONS_MASK))
+ == (FPSCR_CONTROL_MASK|FPSCR_EXCEPTIONS_MASK) &&
+ (old.l & FPSCR_EXCEPTIONS_MASK) == (new.l & FPSCR_EXCEPTIONS_MASK))
+ {
+ fesetenv_mode (new.fenv);
+ }
+ else
+ /* Atomically enable and raise (if appropriate) exceptions set in `new'. */
+ fesetenv_register (new.fenv);
return old.l;
}