unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: "Paul A. Clarke" <pc@us.ibm.com>
To: libc-alpha@sourceware.org
Cc: tuliom@ascii.art.br, murphyp@linux.ibm.com
Subject: [PATCH v2 3/6] [powerpc] libc_feupdateenv_test: optimize FPSCR access
Date: Thu, 19 Sep 2019 13:46:47 -0500	[thread overview]
Message-ID: <1568918810-20393-4-git-send-email-pc@us.ibm.com> (raw)
In-Reply-To: <1568918810-20393-1-git-send-email-pc@us.ibm.com>

From: "Paul A. Clarke" <pc@us.ibm.com>

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>

2019-09-19  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.
---
v2:
- No changes, but respun after removing _FPU macros at the suggestion
  of Paul Murphy, to make it a bit easier to review.

 sysdeps/powerpc/fpu/fenv_libc.h    |  4 ++++
 sysdeps/powerpc/fpu/fenv_private.h | 16 ++++++++++++++--
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/sysdeps/powerpc/fpu/fenv_libc.h b/sysdeps/powerpc/fpu/fenv_libc.h
index 549defa..53de1c8 100644
--- a/sysdeps/powerpc/fpu/fenv_libc.h
+++ b/sysdeps/powerpc/fpu/fenv_libc.h
@@ -264,6 +264,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 30cbf30..9496026 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;
 }
-- 
1.8.3.1


  parent reply	other threads:[~2019-09-19 18:47 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-19 18:46 [PATCH v2 0/6] Various FPSCR-related changes Paul A. Clarke
2019-09-19 18:46 ` [PATCH v2 1/6] [powerpc] fenv_private.h clean up Paul A. Clarke
2019-09-20 15:36   ` Paul E Murphy
2019-09-22  5:11     ` Paul Clarke
2019-09-23 14:58       ` Paul E Murphy
2019-09-19 18:46 ` [PATCH v2 2/6] [powerpc] No need to enter "Ignore Exceptions Mode" Paul A. Clarke
2019-09-23 15:15   ` Paul E Murphy
2019-09-19 18:46 ` Paul A. Clarke [this message]
2019-09-23 15:39   ` [PATCH v2 3/6] [powerpc] libc_feupdateenv_test: optimize FPSCR access Paul E Murphy
2019-09-19 18:46 ` [PATCH v2 4/6] [powerpc] libc_feholdsetround_noex_ppc_ctx: optimize FPSCR write Paul A. Clarke
2019-09-23 15:54   ` Paul E Murphy
2019-09-23 17:54     ` Paul Clarke
2019-09-27 14:27       ` Paul E Murphy
2019-09-19 18:46 ` [PATCH v2 5/6] [powerpc] __fesetround_inline optimizations Paul A. Clarke
2019-09-23 16:08   ` Paul E Murphy
2019-09-19 18:46 ` [PATCH v2 6/6] [powerpc] Rename fegetenv_status to fegetenv_control Paul A. Clarke
2019-09-23 16:21   ` Paul E Murphy
2019-09-23 17:48     ` Paul Clarke
2019-09-19 19:14 ` [PATCH v2 7/6] [powerpc] Rename fesetenv_mode to fesetenv_control Paul A. Clarke
2019-09-23 16:24   ` Paul E Murphy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/libc/involved.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1568918810-20393-4-git-send-email-pc@us.ibm.com \
    --to=pc@us.ibm.com \
    --cc=libc-alpha@sourceware.org \
    --cc=murphyp@linux.ibm.com \
    --cc=tuliom@ascii.art.br \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).