dfa500
From 2ab6ce8252a14e6ef0cfb33046dd565ae15085c2 Mon Sep 17 00:00:00 2001
dfa500
From: Stefan Liebler <stli@linux.ibm.com>
dfa500
Date: Wed, 11 Dec 2019 15:09:32 +0100
dfa500
Subject: [PATCH 28/28] S390: Use libc_fe* macros in fe* functions.
dfa500
dfa500
This patch updates the s390 specific functions fegetround,
dfa500
fesetround, feholdexcept, fesetenv, feupdateenv, fegetexceptflag,
dfa500
fetestexcept, fesetexceptflag, fetestexceptflag.
dfa500
Now those functions are using the libc_fe* macros if possible.
dfa500
dfa500
Furthermore fegetexceptflag is now returning the exception from
dfa500
dxc field shifted to the usual exception-flags.
dfa500
Thus a special fetestexceptflag implementation is not needed anymore.
dfa500
dfa500
(cherry picked from commit 238adf59db85646ebae47876819bd896dae597bc)
dfa500
---
dfa500
 sysdeps/s390/fpu/fegetround.c       |  9 ++-------
dfa500
 sysdeps/s390/fpu/feholdexcpt.c      | 12 ++---------
dfa500
 sysdeps/s390/fpu/fesetenv.c         | 21 +++----------------
dfa500
 sysdeps/s390/fpu/fesetround.c       |  9 +++------
dfa500
 sysdeps/s390/fpu/fetestexceptflag.c | 31 -----------------------------
dfa500
 sysdeps/s390/fpu/feupdateenv.c      | 14 +++----------
dfa500
 sysdeps/s390/fpu/fgetexcptflg.c     | 16 ++-------------
dfa500
 sysdeps/s390/fpu/fsetexcptflg.c     | 23 ++++++++++-----------
dfa500
 sysdeps/s390/fpu/ftestexcept.c      | 16 ++-------------
dfa500
 9 files changed, 27 insertions(+), 124 deletions(-)
dfa500
 delete mode 100644 sysdeps/s390/fpu/fetestexceptflag.c
dfa500
dfa500
diff --git a/sysdeps/s390/fpu/fegetround.c b/sysdeps/s390/fpu/fegetround.c
dfa500
index 3c38bc9189..f1be1d12e1 100644
dfa500
--- a/sysdeps/s390/fpu/fegetround.c
dfa500
+++ b/sysdeps/s390/fpu/fegetround.c
dfa500
@@ -17,17 +17,12 @@
dfa500
    License along with the GNU C Library; if not, see
dfa500
    <http://www.gnu.org/licenses/>.  */
dfa500
 
dfa500
-#include <fenv_libc.h>
dfa500
-#include <fpu_control.h>
dfa500
+#include <get-rounding-mode.h>
dfa500
 
dfa500
 int
dfa500
 __fegetround (void)
dfa500
 {
dfa500
-  fexcept_t cw;
dfa500
-
dfa500
-  _FPU_GETCW (cw);
dfa500
-
dfa500
-  return cw & FPC_RM_MASK;
dfa500
+  return get_rounding_mode ();
dfa500
 }
dfa500
 libm_hidden_def (__fegetround)
dfa500
 weak_alias (__fegetround, fegetround)
dfa500
diff --git a/sysdeps/s390/fpu/feholdexcpt.c b/sysdeps/s390/fpu/feholdexcpt.c
dfa500
index 5daee5675d..48af7ff51b 100644
dfa500
--- a/sysdeps/s390/fpu/feholdexcpt.c
dfa500
+++ b/sysdeps/s390/fpu/feholdexcpt.c
dfa500
@@ -17,19 +17,11 @@
dfa500
    License along with the GNU C Library; if not, see
dfa500
    <http://www.gnu.org/licenses/>.  */
dfa500
 
dfa500
-#include <fenv_libc.h>
dfa500
-#include <fpu_control.h>
dfa500
+#include <fenv_private.h>
dfa500
 
dfa500
 int __feholdexcept (fenv_t *envp)
dfa500
 {
dfa500
-  fexcept_t fpc;
dfa500
-  /* Store the environment.  */
dfa500
-  __fegetenv (envp);
dfa500
-  /* Clear the current sticky bits as more than one exception
dfa500
-     may be generated.  */
dfa500
-  fpc = envp->__fpc & ~(FPC_FLAGS_MASK | FPC_DXC_MASK);
dfa500
-  /* Hold from generating fpu exceptions temporarily.  */
dfa500
-  _FPU_SETCW ((fpc & ~(FE_ALL_EXCEPT << FPC_EXCEPTION_MASK_SHIFT)));
dfa500
+  libc_feholdexcept_s390 (envp);
dfa500
   return 0;
dfa500
 }
dfa500
 libm_hidden_def (__feholdexcept)
dfa500
diff --git a/sysdeps/s390/fpu/fesetenv.c b/sysdeps/s390/fpu/fesetenv.c
dfa500
index c6c275d79d..54ba2aa94a 100644
dfa500
--- a/sysdeps/s390/fpu/fesetenv.c
dfa500
+++ b/sysdeps/s390/fpu/fesetenv.c
dfa500
@@ -17,28 +17,13 @@
dfa500
    License along with the GNU C Library; if not, see
dfa500
    <http://www.gnu.org/licenses/>.  */
dfa500
 
dfa500
-#include <fenv_libc.h>
dfa500
-#include <fpu_control.h>
dfa500
-#include <stddef.h>
dfa500
-#include <unistd.h>
dfa500
+#include <fenv_private.h>
dfa500
 
dfa500
 int
dfa500
 __fesetenv (const fenv_t *envp)
dfa500
 {
dfa500
-  fenv_t env;
dfa500
-
dfa500
-  if (envp == FE_DFL_ENV)
dfa500
-    {
dfa500
-      env.__fpc = _FPU_DEFAULT;
dfa500
-    }
dfa500
-  else if (envp == FE_NOMASK_ENV)
dfa500
-    {
dfa500
-      env.__fpc = FPC_EXCEPTION_MASK;
dfa500
-    }
dfa500
-  else
dfa500
-    env = (*envp);
dfa500
-
dfa500
-  _FPU_SETCW (env.__fpc);
dfa500
+  fenv_t env = libc_handle_user_fenv_s390 (envp);
dfa500
+  libc_fesetenv_s390 (&env;;
dfa500
 
dfa500
   /* Success.  */
dfa500
   return 0;
dfa500
diff --git a/sysdeps/s390/fpu/fesetround.c b/sysdeps/s390/fpu/fesetround.c
dfa500
index d8a84d2c96..0a7fe2635b 100644
dfa500
--- a/sysdeps/s390/fpu/fesetround.c
dfa500
+++ b/sysdeps/s390/fpu/fesetround.c
dfa500
@@ -17,21 +17,18 @@
dfa500
    License along with the GNU C Library; if not, see
dfa500
    <http://www.gnu.org/licenses/>.  */
dfa500
 
dfa500
-#include <fenv_libc.h>
dfa500
-#include <fpu_control.h>
dfa500
+#include <fenv_private.h>
dfa500
 
dfa500
 int
dfa500
 __fesetround (int round)
dfa500
 {
dfa500
-  if ((round|FPC_RM_MASK) != FPC_RM_MASK)
dfa500
+  if ((round | FPC_RM_MASK) != FPC_RM_MASK)
dfa500
     {
dfa500
       /* ROUND is not a valid rounding mode.  */
dfa500
       return 1;
dfa500
     }
dfa500
-  __asm__ __volatile__ ("srnm 0(%0)"
dfa500
-			:
dfa500
-			: "a" (round));
dfa500
 
dfa500
+  libc_fesetround_s390 (round);
dfa500
   return 0;
dfa500
 }
dfa500
 libm_hidden_def (__fesetround)
dfa500
diff --git a/sysdeps/s390/fpu/fetestexceptflag.c b/sysdeps/s390/fpu/fetestexceptflag.c
dfa500
deleted file mode 100644
dfa500
index 784d356f7b..0000000000
dfa500
--- a/sysdeps/s390/fpu/fetestexceptflag.c
dfa500
+++ /dev/null
dfa500
@@ -1,31 +0,0 @@
dfa500
-/* Test exception in saved exception state.  S/390 version.
dfa500
-   Copyright (C) 2016-2018 Free Software Foundation, Inc.
dfa500
-   This file is part of the GNU C Library.
dfa500
-
dfa500
-   The GNU C Library is free software; you can redistribute it and/or
dfa500
-   modify it under the terms of the GNU Lesser General Public
dfa500
-   License as published by the Free Software Foundation; either
dfa500
-   version 2.1 of the License, or (at your option) any later version.
dfa500
-
dfa500
-   The GNU C Library is distributed in the hope that it will be useful,
dfa500
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
dfa500
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
dfa500
-   Lesser General Public License for more details.
dfa500
-
dfa500
-   You should have received a copy of the GNU Lesser General Public
dfa500
-   License along with the GNU C Library; if not, see
dfa500
-   <http://www.gnu.org/licenses/>.  */
dfa500
-
dfa500
-#include <fenv.h>
dfa500
-#include <fenv_libc.h>
dfa500
-
dfa500
-int
dfa500
-fetestexceptflag (const fexcept_t *flagp, int excepts)
dfa500
-{
dfa500
-  /* As *flagp is obtained by an earlier call of fegetexceptflag the
dfa500
-     bits 0-5 of dxc-byte are either zero or correspond to the
dfa500
-     flag-bits.  Evaluate flags and last dxc-exception-code.  */
dfa500
-  return (((*flagp >> FPC_FLAGS_SHIFT) | (*flagp >> FPC_DXC_SHIFT))
dfa500
-	  & excepts
dfa500
-	  & FE_ALL_EXCEPT);
dfa500
-}
dfa500
diff --git a/sysdeps/s390/fpu/feupdateenv.c b/sysdeps/s390/fpu/feupdateenv.c
dfa500
index 4888e1a864..f6b3d7d2de 100644
dfa500
--- a/sysdeps/s390/fpu/feupdateenv.c
dfa500
+++ b/sysdeps/s390/fpu/feupdateenv.c
dfa500
@@ -18,21 +18,13 @@
dfa500
    <http://www.gnu.org/licenses/>.  */
dfa500
 
dfa500
 
dfa500
-#include <fenv_libc.h>
dfa500
-#include <fpu_control.h>
dfa500
+#include <fenv_private.h>
dfa500
 
dfa500
 int
dfa500
 __feupdateenv (const fenv_t *envp)
dfa500
 {
dfa500
-  fexcept_t temp;
dfa500
-
dfa500
-  _FPU_GETCW (temp);
dfa500
-  temp = (temp & FPC_FLAGS_MASK) >> FPC_FLAGS_SHIFT;
dfa500
-
dfa500
-  /* Raise the exceptions since the last call to feholdenv  */
dfa500
-  /* re install saved environment.  */
dfa500
-  __fesetenv (envp);
dfa500
-  __feraiseexcept ((int) temp);
dfa500
+  fenv_t env = libc_handle_user_fenv_s390 (envp);
dfa500
+  libc_feupdateenv_s390 (&env;;
dfa500
 
dfa500
   /* Success.  */
dfa500
   return 0;
dfa500
diff --git a/sysdeps/s390/fpu/fgetexcptflg.c b/sysdeps/s390/fpu/fgetexcptflg.c
dfa500
index 2a0f6dc77c..1985b396c9 100644
dfa500
--- a/sysdeps/s390/fpu/fgetexcptflg.c
dfa500
+++ b/sysdeps/s390/fpu/fgetexcptflg.c
dfa500
@@ -17,24 +17,12 @@
dfa500
    License along with the GNU C Library; if not, see
dfa500
    <http://www.gnu.org/licenses/>.  */
dfa500
 
dfa500
-#include <fenv_libc.h>
dfa500
-#include <fpu_control.h>
dfa500
+#include <fenv_private.h>
dfa500
 
dfa500
 int
dfa500
 fegetexceptflag (fexcept_t *flagp, int excepts)
dfa500
 {
dfa500
-  fexcept_t temp, newexcepts;
dfa500
-
dfa500
-  /* Get the current exceptions.  */
dfa500
-  _FPU_GETCW (temp);
dfa500
-  newexcepts = excepts << FPC_FLAGS_SHIFT;
dfa500
-  if ((temp & FPC_NOT_FPU_EXCEPTION) == 0)
dfa500
-    /* Bits 6, 7 of dxc-byte are zero,
dfa500
-       thus bits 0-5 of dxc-byte correspond to the flag-bits.
dfa500
-       Evaluate flags and last dxc-exception-code.  */
dfa500
-    newexcepts |= excepts << FPC_DXC_SHIFT;
dfa500
-
dfa500
-  *flagp = temp & newexcepts;
dfa500
+  *flagp = libc_fetestexcept_s390 (excepts);
dfa500
 
dfa500
   /* Success.  */
dfa500
   return 0;
dfa500
diff --git a/sysdeps/s390/fpu/fsetexcptflg.c b/sysdeps/s390/fpu/fsetexcptflg.c
dfa500
index e50684c574..51d258cf17 100644
dfa500
--- a/sysdeps/s390/fpu/fsetexcptflg.c
dfa500
+++ b/sysdeps/s390/fpu/fsetexcptflg.c
dfa500
@@ -24,29 +24,26 @@
dfa500
 int
dfa500
 fesetexceptflag (const fexcept_t *flagp, int excepts)
dfa500
 {
dfa500
-  fexcept_t temp, newexcepts;
dfa500
+  fexcept_t fpc, fpc_new;
dfa500
 
dfa500
   /* Get the current environment.  We have to do this since we cannot
dfa500
      separately set the status word.  */
dfa500
-  _FPU_GETCW (temp);
dfa500
-  /* Install the new exception bits in the Accrued Exception Byte.  */
dfa500
-  excepts = excepts & FE_ALL_EXCEPT;
dfa500
-  newexcepts = excepts << FPC_FLAGS_SHIFT;
dfa500
-  temp &= ~newexcepts;
dfa500
-  if ((temp & FPC_NOT_FPU_EXCEPTION) == 0)
dfa500
+  _FPU_GETCW (fpc);
dfa500
+
dfa500
+  /* Clear the current exception bits.  */
dfa500
+  fpc_new = fpc & ~((excepts & FE_ALL_EXCEPT) << FPC_FLAGS_SHIFT);
dfa500
+  if ((fpc & FPC_NOT_FPU_EXCEPTION) == 0)
dfa500
     /* Bits 6, 7 of dxc-byte are zero,
dfa500
        thus bits 0-5 of dxc-byte correspond to the flag-bits.
dfa500
        Clear given exceptions in dxc-field.  */
dfa500
-    temp &= ~(excepts << FPC_DXC_SHIFT);
dfa500
+    fpc_new &= ~((excepts & FE_ALL_EXCEPT) << FPC_DXC_SHIFT);
dfa500
 
dfa500
-  /* Integrate dxc-byte of flagp into flags. The dxc-byte of flagp contains
dfa500
-     either an ieee-exception or 0 (see fegetexceptflag).  */
dfa500
-  temp |= (*flagp | ((*flagp >> FPC_DXC_SHIFT) << FPC_FLAGS_SHIFT))
dfa500
-    & newexcepts;
dfa500
+  /* Set exceptions from flagp in flags-field.  */
dfa500
+  fpc_new |= (*flagp & excepts & FE_ALL_EXCEPT) << FPC_FLAGS_SHIFT;
dfa500
 
dfa500
   /* Store the new status word (along with the rest of the environment.
dfa500
      Possibly new exceptions are set but they won't get executed.  */
dfa500
-  _FPU_SETCW (temp);
dfa500
+  _FPU_SETCW (fpc_new);
dfa500
 
dfa500
   /* Success.  */
dfa500
   return 0;
dfa500
diff --git a/sysdeps/s390/fpu/ftestexcept.c b/sysdeps/s390/fpu/ftestexcept.c
dfa500
index 727b9b342d..f2acecc1af 100644
dfa500
--- a/sysdeps/s390/fpu/ftestexcept.c
dfa500
+++ b/sysdeps/s390/fpu/ftestexcept.c
dfa500
@@ -17,23 +17,11 @@
dfa500
    License along with the GNU C Library; if not, see
dfa500
    <http://www.gnu.org/licenses/>.  */
dfa500
 
dfa500
-#include <fenv_libc.h>
dfa500
-#include <fpu_control.h>
dfa500
+#include <fenv_private.h>
dfa500
 
dfa500
 int
dfa500
 fetestexcept (int excepts)
dfa500
 {
dfa500
-  fexcept_t temp, res;
dfa500
-
dfa500
-  /* Get current exceptions.  */
dfa500
-  _FPU_GETCW (temp);
dfa500
-  res = temp >> FPC_FLAGS_SHIFT;
dfa500
-  if ((temp & FPC_NOT_FPU_EXCEPTION) == 0)
dfa500
-    /* Bits 6, 7 of dxc-byte are zero,
dfa500
-       thus bits 0-5 of dxc-byte correspond to the flag-bits.
dfa500
-       Evaluate flags and last dxc-exception-code.  */
dfa500
-    res |= temp >> FPC_DXC_SHIFT;
dfa500
-
dfa500
-  return res & excepts & FE_ALL_EXCEPT;
dfa500
+  return libc_fetestexcept_s390 (excepts);
dfa500
 }
dfa500
 libm_hidden_def (fetestexcept)
dfa500
-- 
dfa500
2.18.2
dfa500