Blame SOURCES/glibc-rh1268008-4.patch

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