From patchwork Tue Mar 25 18:46:03 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wilco Dijkstra X-Patchwork-Id: 281 Return-Path: X-Original-To: siddhesh@wilcox.dreamhost.com Delivered-To: siddhesh@wilcox.dreamhost.com Received: from homiemail-mx21.g.dreamhost.com (caibbdcaaahb.dreamhost.com [208.113.200.71]) by wilcox.dreamhost.com (Postfix) with ESMTP id 52C183600A9 for ; Tue, 25 Mar 2014 11:46:00 -0700 (PDT) Received: by homiemail-mx21.g.dreamhost.com (Postfix, from userid 14307373) id DAC2DCB8434; Tue, 25 Mar 2014 11:45:59 -0700 (PDT) X-Original-To: glibc@patchwork.siddhesh.in Delivered-To: x14307373@homiemail-mx21.g.dreamhost.com Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by homiemail-mx21.g.dreamhost.com (Postfix) with ESMTPS id B35FCCB5A1C for ; Tue, 25 Mar 2014 11:45:59 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:mime-version :content-type:content-transfer-encoding; q=dns; s=default; b=rUu RHC7/yumiwXzl6f3RXtqEEYovCRr8zgjuIRAqkjV2JaT6kVju/IjIhWiI4ubIv2t WsXXRB4LkaHdM/SfoPdlw8G3oPnFwxfvTbO124cFupHcxRSyymo+pdk50DPz1Dlc UhnF9v5D6cAZcraPZiCfRE3A+msmnGeUx0FzIJoY= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:mime-version :content-type:content-transfer-encoding; s=default; bh=3TK18OZHh t/M0Na/orEr73ovxfA=; b=hkTN+p2ZWuIy/1MG89nfDpVsji8DLGAsiaIxEPxHY Zir1S0dbDRSVMus8r8SyzwQRhJELcZ2fDFTl9ZNw320r75jL3u2flcMfqve6uioR ercPtxqyeLukZya+icqovcHKpRe2ExMMYEya5uDtYT0dU8VxdLnlSIIM1CGJ921S Ws= Received: (qmail 21870 invoked by alias); 25 Mar 2014 18:45:57 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 21858 invoked by uid 89); 25 Mar 2014 18:45:57 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: service87.mimecast.com From: "Wilco" To: Subject: [PATCH 2/2] ARM: Improve fenv implementation Date: Tue, 25 Mar 2014 18:46:03 -0000 Message-ID: <000601cf485a$798aa6a0$6c9ff3e0$@com> MIME-Version: 1.0 X-MC-Unique: 114032518455200301 X-DH-Original-To: glibc@patchwork.siddhesh.in Hi, The second patch improves the fenv implementation by using the inline functions from fenv_private where possible rather than duplicating functionality. The remaining functions are optimized in a similar way to avoid unnecessary FPSCR writes. OK for commit? Wilco --- sysdeps/arm/fclrexcpt.c | 12 ++++++------ sysdeps/arm/fedisblxcpt.c | 4 +++- sysdeps/arm/feenablxcpt.c | 10 +++++----- sysdeps/arm/fegetround.c | 14 ++------------ sysdeps/arm/feholdexcpt.c | 16 ++-------------- sysdeps/arm/fesetenv.c | 44 ++++++++++++++++++++++---------------------- sysdeps/arm/fesetround.c | 10 ++-------- sysdeps/arm/feupdateenv.c | 26 +++++++++++++++++--------- sysdeps/arm/fgetexcptflg.c | 9 ++------- sysdeps/arm/fsetexcptflg.c | 13 ++++++++----- sysdeps/arm/ftestexcept.c | 11 +++-------- sysdeps/arm/setfpucw.c | 11 ++++++----- 12 files changed, 78 insertions(+), 102 deletions(-) diff --git a/sysdeps/arm/fclrexcpt.c b/sysdeps/arm/fclrexcpt.c index 1453192..824145e 100644 --- a/sysdeps/arm/fclrexcpt.c +++ b/sysdeps/arm/fclrexcpt.c @@ -24,19 +24,19 @@ int __feclearexcept (int excepts) { - fpu_control_t fpscr; + fpu_control_t fpscr, new_fpscr; /* Fail if a VFP unit isn't present unless nothing needs to be done. */ if (!ARM_HAVE_VFP) - return (excepts != 0); + return (excepts != 0); _FPU_GETCW (fpscr); excepts &= FE_ALL_EXCEPT; + new_fpscr = fpscr & ~excepts; - /* Clear the relevant bits. */ - fpscr = (fpscr & ~FE_ALL_EXCEPT) | (fpscr & FE_ALL_EXCEPT & ~excepts); - - _FPU_SETCW (fpscr); + /* Write new exception flags if changed. */ + if (new_fpscr != fpscr) + _FPU_SETCW (new_fpscr); return 0; } diff --git a/sysdeps/arm/fedisblxcpt.c b/sysdeps/arm/fedisblxcpt.c index f2956cd..80f5a44 100644 --- a/sysdeps/arm/fedisblxcpt.c +++ b/sysdeps/arm/fedisblxcpt.c @@ -35,7 +35,9 @@ fedisableexcept (int excepts) excepts &= FE_ALL_EXCEPT; new_fpscr = fpscr & ~(excepts << FE_EXCEPT_SHIFT); - _FPU_SETCW (new_fpscr); + /* Write new exceptions if changed. */ + if (__glibc_unlikely (new_fpscr != fpscr)) + _FPU_SETCW (new_fpscr); return (fpscr >> FE_EXCEPT_SHIFT) & FE_ALL_EXCEPT; } diff --git a/sysdeps/arm/feenablxcpt.c b/sysdeps/arm/feenablxcpt.c index afd8943..e649b2f 100644 --- a/sysdeps/arm/feenablxcpt.c +++ b/sysdeps/arm/feenablxcpt.c @@ -35,15 +35,15 @@ feenableexcept (int excepts) excepts &= FE_ALL_EXCEPT; new_fpscr = fpscr | (excepts << FE_EXCEPT_SHIFT); - _FPU_SETCW (new_fpscr); - - if (excepts != 0) + if (new_fpscr != fpscr) { + _FPU_SETCW (new_fpscr); + /* Not all VFP architectures support trapping exceptions, so test whether the relevant bits were set and fail if not. */ _FPU_GETCW (new_fpscr); - if ((new_fpscr & (excepts << FE_EXCEPT_SHIFT)) - != (excepts << FE_EXCEPT_SHIFT)) + + if (((new_fpscr >> FE_EXCEPT_SHIFT) & excepts) != excepts) return -1; } diff --git a/sysdeps/arm/fegetround.c b/sysdeps/arm/fegetround.c index 1c9c151..fbad0b3 100644 --- a/sysdeps/arm/fegetround.c +++ b/sysdeps/arm/fegetround.c @@ -16,22 +16,12 @@ License along with the GNU C Library. If not, see . */ -#include -#include -#include +#include int fegetround (void) { - fpu_control_t fpscr; - - /* FE_TONEAREST is the only supported rounding mode - if a VFP unit isn't present. */ - if (!ARM_HAVE_VFP) - return FE_TONEAREST; - - _FPU_GETCW (fpscr); - return fpscr & FE_TOWARDZERO; + return get_rounding_mode (); } libm_hidden_def (fegetround) diff --git a/sysdeps/arm/feholdexcpt.c b/sysdeps/arm/feholdexcpt.c index 258ba66..2d79e0c 100644 --- a/sysdeps/arm/feholdexcpt.c +++ b/sysdeps/arm/feholdexcpt.c @@ -16,30 +16,18 @@ License along with the GNU C Library. If not, see . */ -#include -#include +#include #include int feholdexcept (fenv_t *envp) { - fpu_control_t fpscr; - /* Fail if a VFP unit isn't present. */ if (!ARM_HAVE_VFP) return 1; - _FPU_GETCW (fpscr); - envp->__cw = fpscr; - - /* Now set all exceptions to non-stop. */ - fpscr &= ~(FE_ALL_EXCEPT << FE_EXCEPT_SHIFT); - - /* And clear all exception flags. */ - fpscr &= ~FE_ALL_EXCEPT; - - _FPU_SETCW (fpscr); + libc_feholdexcept_vfp (envp); return 0; } diff --git a/sysdeps/arm/fesetenv.c b/sysdeps/arm/fesetenv.c index 43b9b47..de95182 100644 --- a/sysdeps/arm/fesetenv.c +++ b/sysdeps/arm/fesetenv.c @@ -16,43 +16,43 @@ License along with the GNU C Library. If not, see . */ -#include -#include +#include #include int __fesetenv (const fenv_t *envp) { - fpu_control_t fpscr; - /* Fail if a VFP unit isn't present. */ if (!ARM_HAVE_VFP) - return 1; + return 1; + + if (__glibc_unlikely ((envp == FE_DFL_ENV) || (envp == FE_NOMASK_ENV))) + { + fpu_control_t fpscr, new_fpscr; - _FPU_GETCW (fpscr); + _FPU_GETCW (fpscr); - /* Preserve the reserved FPSCR flags. */ - fpscr &= _FPU_RESERVED; + /* Preserve the reserved FPSCR flags. */ + new_fpscr = fpscr & _FPU_RESERVED; - if (envp == FE_DFL_ENV) - fpscr |= _FPU_DEFAULT; - else if (envp == FE_NOMASK_ENV) - fpscr |= _FPU_IEEE; - else - fpscr |= envp->__cw & ~_FPU_RESERVED; + if (envp == FE_DFL_ENV) + _FPU_SETCW (new_fpscr | _FPU_DEFAULT); + else + { + _FPU_SETCW (new_fpscr | _FPU_IEEE); + /* Not all VFP architectures support trapping exceptions, so + test whether the relevant bits were set and fail if not. */ + _FPU_GETCW (fpscr); - _FPU_SETCW (fpscr); + if ((fpscr & _FPU_IEEE) != _FPU_IEEE) + return 1; + } - if (envp == FE_NOMASK_ENV) - { - /* Not all VFP architectures support trapping exceptions, so - test whether the relevant bits were set and fail if not. */ - _FPU_GETCW (fpscr); - if ((fpscr & _FPU_IEEE) != _FPU_IEEE) - return 1; + return 0; } + libc_fesetenv_vfp (envp); return 0; } diff --git a/sysdeps/arm/fesetround.c b/sysdeps/arm/fesetround.c index d1b92dc..f52c50a 100644 --- a/sysdeps/arm/fesetround.c +++ b/sysdeps/arm/fesetround.c @@ -16,28 +16,22 @@ License along with the GNU C Library. If not, see . */ -#include -#include +#include #include int fesetround (int round) { - fpu_control_t fpscr; - /* FE_TONEAREST is the only supported rounding mode if a VFP unit isn't present. */ if (!ARM_HAVE_VFP) return (round == FE_TONEAREST) ? 0 : 1; - /* Fail if the rounding mode is not valid. */ if (round & ~FE_TOWARDZERO) return 1; - _FPU_GETCW (fpscr); - fpscr = (fpscr & ~FE_TOWARDZERO) | round; - _FPU_SETCW (fpscr); + libc_fesetround_vfp (round); return 0; } diff --git a/sysdeps/arm/feupdateenv.c b/sysdeps/arm/feupdateenv.c index 7cf6206..9c42dea 100644 --- a/sysdeps/arm/feupdateenv.c +++ b/sysdeps/arm/feupdateenv.c @@ -17,27 +17,35 @@ License along with the GNU C Library. If not, see . */ -#include -#include +#include #include int __feupdateenv (const fenv_t *envp) { - fpu_control_t fpscr; + fenv_t fenv; /* Fail if a VFP unit isn't present. */ if (!ARM_HAVE_VFP) - return 1; + return 1; - _FPU_GETCW (fpscr); + if (__glibc_unlikely ((envp == FE_DFL_ENV) || (envp == FE_NOMASK_ENV))) + { + fpu_control_t fpscr; - /* Install new environment. */ - fesetenv (envp); + _FPU_GETCW (fpscr); - /* Raise the saved exceptions. */ - feraiseexcept (fpscr & FE_ALL_EXCEPT); + /* Preserve the reserved FPSCR flags. */ + fpscr &= _FPU_RESERVED; + fpscr |= (envp == FE_DFL_ENV) ? _FPU_DEFAULT : _FPU_IEEE; + + /* Create a valid fenv to pass to libc_feupdateenv_vfp. */ + fenv.__cw = fpscr; + envp = &fenv; + } + + libc_feupdateenv_vfp (envp); return 0; } diff --git a/sysdeps/arm/fgetexcptflg.c b/sysdeps/arm/fgetexcptflg.c index e1eb420..19c8b6d 100644 --- a/sysdeps/arm/fgetexcptflg.c +++ b/sysdeps/arm/fgetexcptflg.c @@ -17,23 +17,18 @@ License along with the GNU C Library. If not, see . */ -#include -#include +#include #include int __fegetexceptflag (fexcept_t *flagp, int excepts) { - fpu_control_t fpscr; - /* Fail if a VFP unit isn't present. */ if (!ARM_HAVE_VFP) return 1; - _FPU_GETCW (fpscr); - - *flagp = fpscr & excepts & FE_ALL_EXCEPT; + *flagp = libc_fetestexcept_vfp (excepts); return 0; } diff --git a/sysdeps/arm/fsetexcptflg.c b/sysdeps/arm/fsetexcptflg.c index a594e15..c1a6c1a 100644 --- a/sysdeps/arm/fsetexcptflg.c +++ b/sysdeps/arm/fsetexcptflg.c @@ -25,20 +25,23 @@ int __fesetexceptflag (const fexcept_t *flagp, int excepts) { - fpu_control_t fpscr; + fpu_control_t fpscr, new_fpscr; /* Fail if a VFP unit isn't present unless nothing needs to be done. */ if (!ARM_HAVE_VFP) return (excepts != 0); _FPU_GETCW (fpscr); + excepts &= FE_ALL_EXCEPT; /* Set the desired exception mask. */ - fpscr &= ~(excepts & FE_ALL_EXCEPT); - fpscr |= (*flagp & excepts & FE_ALL_EXCEPT); + new_fpscr = fpscr & ~excepts; + new_fpscr |= *flagp & excepts; + + /* Write new exception flags if changed. */ + if (new_fpscr != fpscr) + _FPU_SETCW (new_fpscr); - /* Save state back to the FPU. */ - _FPU_SETCW (fpscr); return 0; } diff --git a/sysdeps/arm/ftestexcept.c b/sysdeps/arm/ftestexcept.c index de082b2..6c5d3a8 100644 --- a/sysdeps/arm/ftestexcept.c +++ b/sysdeps/arm/ftestexcept.c @@ -16,23 +16,18 @@ License along with the GNU C Library. If not, see . */ -#include -#include +#include #include int fetestexcept (int excepts) { - fpu_control_t fpscr; - /* Return no exception flags if a VFP unit isn't present. */ if (!ARM_HAVE_VFP) return 0; - /* Get current exceptions. */ - _FPU_GETCW (fpscr); - - return fpscr & excepts & FE_ALL_EXCEPT; + return libc_fetestexcept_vfp (excepts); } + libm_hidden_def (fetestexcept) diff --git a/sysdeps/arm/setfpucw.c b/sysdeps/arm/setfpucw.c index 7416377..259b020 100644 --- a/sysdeps/arm/setfpucw.c +++ b/sysdeps/arm/setfpucw.c @@ -24,19 +24,20 @@ void __setfpucw (fpu_control_t set) { - fpu_control_t fpscr; + fpu_control_t fpscr, new_fpscr; /* Do nothing if a VFP unit isn't present. */ if (!ARM_HAVE_VFP) return; - /* Fetch the current control word. */ _FPU_GETCW (fpscr); /* Preserve the reserved bits, and set the rest as the user specified (or the default, if the user gave zero). */ - fpscr &= _FPU_RESERVED; - fpscr |= set & ~_FPU_RESERVED; + new_fpscr = fpscr & _FPU_RESERVED; + new_fpscr |= set & ~_FPU_RESERVED; - _FPU_SETCW (fpscr); + /* Write FPSCR if changed. */ + if (new_fpscr != fpscr) + _FPU_SETCW (fpscr); }