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