ce426f
From aea6303d6c5fa276ea10887dab968ee0f3c79328 Mon Sep 17 00:00:00 2001
ce426f
From: Stefan Liebler <stli@linux.vnet.ibm.com>
ce426f
Date: Thu, 8 Oct 2015 10:30:00 +0200
ce426f
Subject: [PATCH 04/30] S390: Fix handling of DXC-byte in FPC-register.
ce426f
MIME-Version: 1.0
ce426f
Content-Type: text/plain; charset=UTF-8
ce426f
Content-Transfer-Encoding: 8bit
ce426f
ce426f
upstream-commit-id: 5d96fe8c0dc3450bafe6c2aae2dabc76819df3e0
ce426f
https://www.sourceware.org/ml/libc-alpha/2015-07/msg00074.html
ce426f
ce426f
On s390, the DXC(data-exception-code)-byte in FPC(floating-point-control)-
ce426f
register contains a code of the last occured exception.
ce426f
If bits 6 and 7 of DXC-byte are zero, the bits 0-5 correspond to the
ce426f
ieee-exception flag bits.
ce426f
The current implementation always uses these bits as ieee-exception flag bits.
ce426f
fetestexcept() reports any exception after the first usage of a
ce426f
vector-instruction in a process, because it raises an "vector instruction
ce426f
exception" with DXC-code 0xFE.
ce426f
This patch fixes the handling of the DXC-byte. The DXC-Byte is only handled
ce426f
if bits 6 and 7 are zero.
ce426f
ce426f
The #define _FPU_RESERVED is extended by the DXC-Byte.
ce426f
Otherwise the tests math/test-fpucw-static and math/test-fpucw-ieee-static
ce426f
fails, because DXC-Byte contains the vector instruction exception when reaching
ce426f
main(). This exception was triggered by strrchr() call in __init_misc().
ce426f
__init_misc() is called after __setfpucw () in __libc_init_first().
ce426f
ce426f
The field __ieee_instruction_pointer in struct fenv_t is renamed to __unused
ce426f
because it is a relict from commit "Remove PTRACE_PEEKUSER"
ce426f
(87b9b50f0d4b92248905e95a06a13c513dc45e59) and isn´t used anymore.
ce426f
ce426f
ChangeLog:
ce426f
ce426f
	[BZ #18610]
ce426f
	* sysdeps/s390/fpu/bits/fenv.h (fenv_t): Rename
ce426f
	__ieee_instruction_pointer to __unused.
ce426f
	* sysdeps/s390/fpu/fesetenv.c (__fesetenv): Remove usage of
ce426f
	__ieee_instruction_pointer.
ce426f
	* sysdeps/s390/fpu/fclrexcpt.c (feclearexcept): Fix dxc-field handling.
ce426f
	* sysdeps/s390/fpu/fgetexcptflg.c (fegetexceptflag): Likewise.
ce426f
	* sysdeps/s390/fpu/fsetexcptflg.c (fesetexceptflag): Likewise.
ce426f
	* sysdeps/s390/fpu/ftestexcept.c (fetestexcept): Likewise.
ce426f
	* sysdeps/s390/fpu/fpu_control.h (_FPU_RESERVED):
ce426f
	Mark dxc-field as reserved.
ce426f
---
ce426f
 sysdeps/s390/fpu/bits/fenv.h    |  6 ++++--
ce426f
 sysdeps/s390/fpu/fclrexcpt.c    |  7 ++++++-
ce426f
 sysdeps/s390/fpu/fesetenv.c     |  2 --
ce426f
 sysdeps/s390/fpu/fgetexcptflg.c |  8 +++++++-
ce426f
 sysdeps/s390/fpu/fpu_control.h  |  6 +++---
ce426f
 sysdeps/s390/fpu/fsetexcptflg.c | 15 ++++++++++++---
ce426f
 sysdeps/s390/fpu/ftestexcept.c  | 12 +++++++++---
ce426f
 7 files changed, 41 insertions(+), 15 deletions(-)
ce426f
ce426f
diff --git a/sysdeps/s390/fpu/bits/fenv.h b/sysdeps/s390/fpu/bits/fenv.h
ce426f
index 88c6f7a..93177dc 100644
ce426f
--- a/sysdeps/s390/fpu/bits/fenv.h
ce426f
+++ b/sysdeps/s390/fpu/bits/fenv.h
ce426f
@@ -77,8 +77,10 @@ typedef unsigned int fexcept_t; /* size of fpc */
ce426f
 typedef struct
ce426f
 {
ce426f
   fexcept_t __fpc;
ce426f
-  void *__ieee_instruction_pointer;
ce426f
-  /* failing instruction for ieee exceptions */
ce426f
+  void *__unused;
ce426f
+  /* The field __unused (formerly __ieee_instruction_pointer) is a relict from
ce426f
+     commit "Remove PTRACE_PEEKUSER" (87b9b50f0d4b92248905e95a06a13c513dc45e59)
ce426f
+     and isn´t used anymore.  */
ce426f
 } fenv_t;
ce426f
 
ce426f
 /* If the default argument is used we use this value.  */
ce426f
diff --git a/sysdeps/s390/fpu/fclrexcpt.c b/sysdeps/s390/fpu/fclrexcpt.c
ce426f
index 3e8d9bb..c2647ba 100644
ce426f
--- a/sysdeps/s390/fpu/fclrexcpt.c
ce426f
+++ b/sysdeps/s390/fpu/fclrexcpt.c
ce426f
@@ -29,7 +29,12 @@ feclearexcept (int excepts)
ce426f
 
ce426f
   _FPU_GETCW (temp);
ce426f
   /* Clear the relevant bits.  */
ce426f
-  temp &= ~((excepts << FPC_DXC_SHIFT)|(excepts << FPC_FLAGS_SHIFT));
ce426f
+  temp &= ~(excepts << FPC_FLAGS_SHIFT);
ce426f
+  if ((temp & FPC_NOT_FPU_EXCEPTION) == 0)
ce426f
+    /* Bits 6, 7 of dxc-byte are zero,
ce426f
+       thus bits 0-5 of dxc-byte correspond to the flag-bits.
ce426f
+       Clear the relevant bits in flags and dxc-field.  */
ce426f
+    temp &= ~(excepts << FPC_DXC_SHIFT);
ce426f
 
ce426f
   /* Put the new data in effect.  */
ce426f
   _FPU_SETCW (temp);
ce426f
diff --git a/sysdeps/s390/fpu/fesetenv.c b/sysdeps/s390/fpu/fesetenv.c
ce426f
index b534205..a4a0bb5 100644
ce426f
--- a/sysdeps/s390/fpu/fesetenv.c
ce426f
+++ b/sysdeps/s390/fpu/fesetenv.c
ce426f
@@ -32,12 +32,10 @@ fesetenv (const fenv_t *envp)
ce426f
   if (envp == FE_DFL_ENV)
ce426f
     {
ce426f
       env.__fpc = _FPU_DEFAULT;
ce426f
-      env.__ieee_instruction_pointer = 0;
ce426f
     }
ce426f
   else if (envp == FE_NOMASK_ENV)
ce426f
     {
ce426f
       env.__fpc = FPC_EXCEPTION_MASK;
ce426f
-      env.__ieee_instruction_pointer = 0;
ce426f
     }
ce426f
   else
ce426f
     env = (*envp);
ce426f
diff --git a/sysdeps/s390/fpu/fgetexcptflg.c b/sysdeps/s390/fpu/fgetexcptflg.c
ce426f
index 7457678..7941904 100644
ce426f
--- a/sysdeps/s390/fpu/fgetexcptflg.c
ce426f
+++ b/sysdeps/s390/fpu/fgetexcptflg.c
ce426f
@@ -27,7 +27,13 @@ fegetexceptflag (fexcept_t *flagp, int excepts)
ce426f
 
ce426f
   /* Get the current exceptions.  */
ce426f
   _FPU_GETCW (temp);
ce426f
-  newexcepts = (excepts << FPC_DXC_SHIFT) | (excepts << FPC_FLAGS_SHIFT);
ce426f
+  newexcepts = excepts << FPC_FLAGS_SHIFT;
ce426f
+  if ((temp & FPC_NOT_FPU_EXCEPTION) == 0)
ce426f
+    /* Bits 6, 7 of dxc-byte are zero,
ce426f
+       thus bits 0-5 of dxc-byte correspond to the flag-bits.
ce426f
+       Evaluate flags and last dxc-exception-code.  */
ce426f
+    newexcepts |= excepts << FPC_DXC_SHIFT;
ce426f
+
ce426f
   *flagp = temp & newexcepts;
ce426f
 
ce426f
   /* Success.  */
ce426f
diff --git a/sysdeps/s390/fpu/fpu_control.h b/sysdeps/s390/fpu/fpu_control.h
ce426f
index af81bc2..dba904d 100644
ce426f
--- a/sysdeps/s390/fpu/fpu_control.h
ce426f
+++ b/sysdeps/s390/fpu/fpu_control.h
ce426f
@@ -19,12 +19,12 @@
ce426f
    <http://www.gnu.org/licenses/>.  */
ce426f
 
ce426f
 #ifndef _FPU_CONTROL_H
ce426f
-# define _FPU_CONTROL_H
ce426f
+#define _FPU_CONTROL_H
ce426f
 
ce426f
-# include <features.h>
ce426f
+#include <features.h>
ce426f
 
ce426f
 /* These bits are reserved are not changed.  */
ce426f
-# define _FPU_RESERVED 0x070700FC
ce426f
+#define _FPU_RESERVED 0x0707FFFC
ce426f
 
ce426f
 /* The fdlibm code requires no interrupts for exceptions.  Don't
ce426f
    change the rounding mode, it would break long double I/O!  */
ce426f
diff --git a/sysdeps/s390/fpu/fsetexcptflg.c b/sysdeps/s390/fpu/fsetexcptflg.c
ce426f
index aada675..85c68e8 100644
ce426f
--- a/sysdeps/s390/fpu/fsetexcptflg.c
ce426f
+++ b/sysdeps/s390/fpu/fsetexcptflg.c
ce426f
@@ -24,16 +24,25 @@
ce426f
 int
ce426f
 fesetexceptflag (const fexcept_t *flagp, int excepts)
ce426f
 {
ce426f
-  fexcept_t temp,newexcepts;
ce426f
+  fexcept_t temp, newexcepts;
ce426f
 
ce426f
   /* Get the current environment.  We have to do this since we cannot
ce426f
      separately set the status word.  */
ce426f
   _FPU_GETCW (temp);
ce426f
   /* Install the new exception bits in the Accrued Exception Byte.  */
ce426f
   excepts = excepts & FE_ALL_EXCEPT;
ce426f
-  newexcepts = (excepts << FPC_DXC_SHIFT) | (excepts << FPC_FLAGS_SHIFT);
ce426f
+  newexcepts = excepts << FPC_FLAGS_SHIFT;
ce426f
   temp &= ~newexcepts;
ce426f
-  temp |= *flagp & newexcepts;
ce426f
+  if ((temp & FPC_NOT_FPU_EXCEPTION) == 0)
ce426f
+    /* Bits 6, 7 of dxc-byte are zero,
ce426f
+       thus bits 0-5 of dxc-byte correspond to the flag-bits.
ce426f
+       Clear given exceptions in dxc-field.  */
ce426f
+    temp &= ~(excepts << FPC_DXC_SHIFT);
ce426f
+
ce426f
+  /* Integrate dxc-byte of flagp into flags. The dxc-byte of flagp contains
ce426f
+     either an ieee-exception or 0 (see fegetexceptflag).  */
ce426f
+  temp |= (*flagp | ((*flagp >> FPC_DXC_SHIFT) << FPC_FLAGS_SHIFT))
ce426f
+    & newexcepts;
ce426f
 
ce426f
   /* Store the new status word (along with the rest of the environment.
ce426f
      Possibly new exceptions are set but they won't get executed unless
ce426f
diff --git a/sysdeps/s390/fpu/ftestexcept.c b/sysdeps/s390/fpu/ftestexcept.c
ce426f
index 5594994..c36aefd 100644
ce426f
--- a/sysdeps/s390/fpu/ftestexcept.c
ce426f
+++ b/sysdeps/s390/fpu/ftestexcept.c
ce426f
@@ -23,11 +23,17 @@
ce426f
 int
ce426f
 fetestexcept (int excepts)
ce426f
 {
ce426f
-  fexcept_t temp;
ce426f
+  fexcept_t temp, res;
ce426f
 
ce426f
   /* Get current exceptions.  */
ce426f
   _FPU_GETCW (temp);
ce426f
-  temp = (temp >> FPC_DXC_SHIFT) | (temp >> FPC_FLAGS_SHIFT);
ce426f
-  return temp & excepts & FE_ALL_EXCEPT;
ce426f
+  res = temp >> FPC_FLAGS_SHIFT;
ce426f
+  if ((temp & FPC_NOT_FPU_EXCEPTION) == 0)
ce426f
+    /* Bits 6, 7 of dxc-byte are zero,
ce426f
+       thus bits 0-5 of dxc-byte correspond to the flag-bits.
ce426f
+       Evaluate flags and last dxc-exception-code.  */
ce426f
+    res |= temp >> FPC_DXC_SHIFT;
ce426f
+
ce426f
+  return res & excepts & FE_ALL_EXCEPT;
ce426f
 }
ce426f
 libm_hidden_def (fetestexcept)
ce426f
-- 
ce426f
2.3.0
ce426f