|
|
a2cf7d |
From 8e5e36d7ba097b8e110ab45794659156af182f54 Mon Sep 17 00:00:00 2001
|
|
|
a2cf7d |
From: Stefan Liebler <stli@linux.ibm.com>
|
|
|
a2cf7d |
Date: Wed, 11 Dec 2019 15:09:31 +0100
|
|
|
a2cf7d |
Subject: [PATCH 27/28] S390: Implement libc_fe* macros.
|
|
|
a2cf7d |
|
|
|
a2cf7d |
This patch provides the s390 specific implementation for
|
|
|
a2cf7d |
libc_feholdexcept, libc_fesetround, libc_feholdexcept_setround,
|
|
|
a2cf7d |
libc_fetestexcept, libc_fesetenv, libc_feupdateenv_test,
|
|
|
a2cf7d |
libc_feupdateenv, libc_feholdsetround_ctx, libc_feresetround_ctx,
|
|
|
a2cf7d |
libc_feholdsetround_noex_ctx and libc_feresetround_noex_ctx.
|
|
|
a2cf7d |
|
|
|
a2cf7d |
(cherry picked from commit 7c94d036c17dfd352d11e9bf98e5d84122c1f95e)
|
|
|
a2cf7d |
Note: glibc-2.28 does not have a generic fenv_private.h.
|
|
|
a2cf7d |
Therefore include_next does not work. Instead fenv_private.h needs to
|
|
|
a2cf7d |
be included in the s390 specific mathp_private.h just before including
|
|
|
a2cf7d |
the generic math_private.h.
|
|
|
a2cf7d |
As the s390 specific math_private.h is introduced with the backport of
|
|
|
a2cf7d |
commit "S390: Implement roundtoint and converttoint and define TOINT_INTRINSICS.",
|
|
|
a2cf7d |
the order of cherry-picking was changed compared to upstream!
|
|
|
a2cf7d |
---
|
|
|
a2cf7d |
sysdeps/s390/fpu/fenv_private.h | 248 ++++++++++++++++++++++++++++++++
|
|
|
a2cf7d |
sysdeps/s390/fpu/math_private.h | 1 +
|
|
|
a2cf7d |
2 files changed, 249 insertions(+)
|
|
|
a2cf7d |
create mode 100644 sysdeps/s390/fpu/fenv_private.h
|
|
|
a2cf7d |
|
|
|
a2cf7d |
diff --git a/sysdeps/s390/fpu/fenv_private.h b/sysdeps/s390/fpu/fenv_private.h
|
|
|
a2cf7d |
new file mode 100644
|
|
|
a2cf7d |
index 0000000000..8899f8f434
|
|
|
a2cf7d |
--- /dev/null
|
|
|
a2cf7d |
+++ b/sysdeps/s390/fpu/fenv_private.h
|
|
|
a2cf7d |
@@ -0,0 +1,248 @@
|
|
|
a2cf7d |
+/* Private floating point rounding and exceptions handling. 390/s390x version.
|
|
|
a2cf7d |
+ Copyright (C) 2019 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 |
+ <https://www.gnu.org/licenses/>. */
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+#ifndef S390_FENV_PRIVATE_H
|
|
|
a2cf7d |
+#define S390_FENV_PRIVATE_H 1
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+#include <fenv.h>
|
|
|
a2cf7d |
+#include <fenv_libc.h>
|
|
|
a2cf7d |
+#include <fpu_control.h>
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+static __always_inline void
|
|
|
a2cf7d |
+libc_feholdexcept_s390 (fenv_t *envp)
|
|
|
a2cf7d |
+{
|
|
|
a2cf7d |
+ fpu_control_t fpc, fpc_new;
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+ /* Store the environment. */
|
|
|
a2cf7d |
+ _FPU_GETCW (fpc);
|
|
|
a2cf7d |
+ envp->__fpc = fpc;
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+ /* Clear the current exception flags and dxc field.
|
|
|
a2cf7d |
+ Hold from generating fpu exceptions temporarily. */
|
|
|
a2cf7d |
+ fpc_new = fpc & ~(FPC_FLAGS_MASK | FPC_DXC_MASK | FPC_EXCEPTION_MASK);
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+ /* Only set new environment if it has changed. */
|
|
|
a2cf7d |
+ if (fpc_new != fpc)
|
|
|
a2cf7d |
+ _FPU_SETCW (fpc_new);
|
|
|
a2cf7d |
+}
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+#define libc_feholdexcept libc_feholdexcept_s390
|
|
|
a2cf7d |
+#define libc_feholdexceptf libc_feholdexcept_s390
|
|
|
a2cf7d |
+#define libc_feholdexceptl libc_feholdexcept_s390
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+static __always_inline void
|
|
|
a2cf7d |
+libc_fesetround_s390 (int round)
|
|
|
a2cf7d |
+{
|
|
|
a2cf7d |
+ __asm__ __volatile__ ("srnm 0(%0)" : : "a" (round));
|
|
|
a2cf7d |
+}
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+#define libc_fesetround libc_fesetround_s390
|
|
|
a2cf7d |
+#define libc_fesetroundf libc_fesetround_s390
|
|
|
a2cf7d |
+#define libc_fesetroundl libc_fesetround_s390
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+static __always_inline void
|
|
|
a2cf7d |
+libc_feholdexcept_setround_s390 (fenv_t *envp, int r)
|
|
|
a2cf7d |
+{
|
|
|
a2cf7d |
+ fpu_control_t fpc, fpc_new;
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+ _FPU_GETCW (fpc);
|
|
|
a2cf7d |
+ envp->__fpc = fpc;
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+ /* Clear the current exception flags and dxc field.
|
|
|
a2cf7d |
+ Hold from generating fpu exceptions temporarily.
|
|
|
a2cf7d |
+ Reset rounding mode bits. */
|
|
|
a2cf7d |
+ fpc_new = fpc & ~(FPC_FLAGS_MASK | FPC_DXC_MASK | FPC_EXCEPTION_MASK
|
|
|
a2cf7d |
+ | FPC_RM_MASK);
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+ /* Set new rounding mode. */
|
|
|
a2cf7d |
+ fpc_new |= (r & FPC_RM_MASK);
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+ /* Only set new environment if it has changed. */
|
|
|
a2cf7d |
+ if (fpc_new != fpc)
|
|
|
a2cf7d |
+ _FPU_SETCW (fpc_new);
|
|
|
a2cf7d |
+}
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+#define libc_feholdexcept_setround libc_feholdexcept_setround_s390
|
|
|
a2cf7d |
+#define libc_feholdexcept_setroundf libc_feholdexcept_setround_s390
|
|
|
a2cf7d |
+#define libc_feholdexcept_setroundl libc_feholdexcept_setround_s390
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+static __always_inline int
|
|
|
a2cf7d |
+libc_fetestexcept_s390 (int excepts)
|
|
|
a2cf7d |
+{
|
|
|
a2cf7d |
+ int res;
|
|
|
a2cf7d |
+ fexcept_t fpc;
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+ _FPU_GETCW (fpc);
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+ /* Get current exceptions. */
|
|
|
a2cf7d |
+ res = (fpc >> FPC_FLAGS_SHIFT) & FE_ALL_EXCEPT;
|
|
|
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 |
+ Evaluate flags and last dxc-exception-code. */
|
|
|
a2cf7d |
+ res |= (fpc >> FPC_DXC_SHIFT) & FE_ALL_EXCEPT;
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+ return res & excepts;
|
|
|
a2cf7d |
+}
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+#define libc_fetestexcept libc_fetestexcept_s390
|
|
|
a2cf7d |
+#define libc_fetestexceptf libc_fetestexcept_s390
|
|
|
a2cf7d |
+#define libc_fetestexceptl libc_fetestexcept_s390
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+static __always_inline void
|
|
|
a2cf7d |
+libc_fesetenv_s390 (const fenv_t *envp)
|
|
|
a2cf7d |
+{
|
|
|
a2cf7d |
+ _FPU_SETCW (envp->__fpc);
|
|
|
a2cf7d |
+}
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+#define libc_fesetenv libc_fesetenv_s390
|
|
|
a2cf7d |
+#define libc_fesetenvf libc_fesetenv_s390
|
|
|
a2cf7d |
+#define libc_fesetenvl libc_fesetenv_s390
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+static __always_inline int
|
|
|
a2cf7d |
+libc_feupdateenv_test_s390 (const fenv_t *envp, int ex)
|
|
|
a2cf7d |
+{
|
|
|
a2cf7d |
+ /* Get the currently raised exceptions. */
|
|
|
a2cf7d |
+ int excepts;
|
|
|
a2cf7d |
+ fexcept_t fpc_old;
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+ _FPU_GETCW (fpc_old);
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+ /* Get current exceptions. */
|
|
|
a2cf7d |
+ excepts = (fpc_old >> FPC_FLAGS_SHIFT) & FE_ALL_EXCEPT;
|
|
|
a2cf7d |
+ if ((fpc_old & 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 |
+ excepts |= (fpc_old >> FPC_DXC_SHIFT) & FE_ALL_EXCEPT;
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+ /* Merge the currently raised exceptions with those in envp. */
|
|
|
a2cf7d |
+ fpu_control_t fpc_new = envp->__fpc;
|
|
|
a2cf7d |
+ fpc_new |= excepts << FPC_FLAGS_SHIFT;
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+ /* Install the new fpc from envp. */
|
|
|
a2cf7d |
+ if (fpc_new != fpc_old)
|
|
|
a2cf7d |
+ _FPU_SETCW (fpc_new);
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+ /* Raise the exceptions if enabled in new fpc. */
|
|
|
a2cf7d |
+ if (__glibc_unlikely ((fpc_new >> FPC_EXCEPTION_MASK_SHIFT) & excepts))
|
|
|
a2cf7d |
+ __feraiseexcept (excepts);
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+ return excepts & ex;
|
|
|
a2cf7d |
+}
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+#define libc_feupdateenv_test libc_feupdateenv_test_s390
|
|
|
a2cf7d |
+#define libc_feupdateenv_testf libc_feupdateenv_test_s390
|
|
|
a2cf7d |
+#define libc_feupdateenv_testl libc_feupdateenv_test_s390
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+static __always_inline void
|
|
|
a2cf7d |
+libc_feupdateenv_s390 (const fenv_t *envp)
|
|
|
a2cf7d |
+{
|
|
|
a2cf7d |
+ libc_feupdateenv_test_s390 (envp, 0);
|
|
|
a2cf7d |
+}
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+#define libc_feupdateenv libc_feupdateenv_s390
|
|
|
a2cf7d |
+#define libc_feupdateenvf libc_feupdateenv_s390
|
|
|
a2cf7d |
+#define libc_feupdateenvl libc_feupdateenv_s390
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+static __always_inline fenv_t
|
|
|
a2cf7d |
+libc_handle_user_fenv_s390 (const fenv_t *envp)
|
|
|
a2cf7d |
+{
|
|
|
a2cf7d |
+ fenv_t env;
|
|
|
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 |
+ return env;
|
|
|
a2cf7d |
+}
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+/* We have support for rounding mode context. */
|
|
|
a2cf7d |
+#define HAVE_RM_CTX 1
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+static __always_inline void
|
|
|
a2cf7d |
+libc_feholdsetround_s390_ctx (struct rm_ctx *ctx, int r)
|
|
|
a2cf7d |
+{
|
|
|
a2cf7d |
+ fpu_control_t fpc;
|
|
|
a2cf7d |
+ int round;
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+ _FPU_GETCW (fpc);
|
|
|
a2cf7d |
+ ctx->env.__fpc = fpc;
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+ /* Check whether rounding modes are different. */
|
|
|
a2cf7d |
+ round = fpc & FPC_RM_MASK;
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+ /* Set the rounding mode if changed. */
|
|
|
a2cf7d |
+ if (__glibc_unlikely (round != r))
|
|
|
a2cf7d |
+ {
|
|
|
a2cf7d |
+ ctx->updated_status = true;
|
|
|
a2cf7d |
+ libc_fesetround_s390 (r);
|
|
|
a2cf7d |
+ }
|
|
|
a2cf7d |
+ else
|
|
|
a2cf7d |
+ ctx->updated_status = false;
|
|
|
a2cf7d |
+}
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+#define libc_feholdsetround_ctx libc_feholdsetround_s390_ctx
|
|
|
a2cf7d |
+#define libc_feholdsetroundf_ctx libc_feholdsetround_s390_ctx
|
|
|
a2cf7d |
+#define libc_feholdsetroundl_ctx libc_feholdsetround_s390_ctx
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+static __always_inline void
|
|
|
a2cf7d |
+libc_feresetround_s390_ctx (struct rm_ctx *ctx)
|
|
|
a2cf7d |
+{
|
|
|
a2cf7d |
+ /* Restore the rounding mode if updated. */
|
|
|
a2cf7d |
+ if (__glibc_unlikely (ctx->updated_status))
|
|
|
a2cf7d |
+ {
|
|
|
a2cf7d |
+ fpu_control_t fpc;
|
|
|
a2cf7d |
+ _FPU_GETCW (fpc);
|
|
|
a2cf7d |
+ fpc = ctx->env.__fpc | (fpc & FPC_FLAGS_MASK);
|
|
|
a2cf7d |
+ _FPU_SETCW (fpc);
|
|
|
a2cf7d |
+ }
|
|
|
a2cf7d |
+}
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+#define libc_feresetround_ctx libc_feresetround_s390_ctx
|
|
|
a2cf7d |
+#define libc_feresetroundf_ctx libc_feresetround_s390_ctx
|
|
|
a2cf7d |
+#define libc_feresetroundl_ctx libc_feresetround_s390_ctx
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+static __always_inline void
|
|
|
a2cf7d |
+libc_feholdsetround_noex_s390_ctx (struct rm_ctx *ctx, int r)
|
|
|
a2cf7d |
+{
|
|
|
a2cf7d |
+ libc_feholdexcept_setround_s390 (&ctx->env, r);
|
|
|
a2cf7d |
+}
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+#define libc_feholdsetround_noex_ctx libc_feholdsetround_noex_s390_ctx
|
|
|
a2cf7d |
+#define libc_feholdsetround_noexf_ctx libc_feholdsetround_noex_s390_ctx
|
|
|
a2cf7d |
+#define libc_feholdsetround_noexl_ctx libc_feholdsetround_noex_s390_ctx
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+static __always_inline void
|
|
|
a2cf7d |
+libc_feresetround_noex_s390_ctx (struct rm_ctx *ctx)
|
|
|
a2cf7d |
+{
|
|
|
a2cf7d |
+ /* Restore exception flags and rounding mode. */
|
|
|
a2cf7d |
+ libc_fesetenv_s390 (&ctx->env);
|
|
|
a2cf7d |
+}
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+#define libc_feresetround_noex_ctx libc_feresetround_noex_s390_ctx
|
|
|
a2cf7d |
+#define libc_feresetround_noexf_ctx libc_feresetround_noex_s390_ctx
|
|
|
a2cf7d |
+#define libc_feresetround_noexl_ctx libc_feresetround_noex_s390_ctx
|
|
|
a2cf7d |
+
|
|
|
a2cf7d |
+#endif
|
|
|
a2cf7d |
diff --git a/sysdeps/s390/fpu/math_private.h b/sysdeps/s390/fpu/math_private.h
|
|
|
a2cf7d |
index a1ae91a87c..f3c770d59a 100644
|
|
|
a2cf7d |
--- a/sysdeps/s390/fpu/math_private.h
|
|
|
a2cf7d |
+++ b/sysdeps/s390/fpu/math_private.h
|
|
|
a2cf7d |
@@ -48,6 +48,7 @@ converttoint (double_t x)
|
|
|
a2cf7d |
}
|
|
|
a2cf7d |
#endif
|
|
|
a2cf7d |
|
|
|
a2cf7d |
+#include <fenv_private.h>
|
|
|
a2cf7d |
#include_next <math_private.h>
|
|
|
a2cf7d |
|
|
|
a2cf7d |
#endif
|
|
|
a2cf7d |
--
|
|
|
a2cf7d |
2.18.2
|
|
|
a2cf7d |
|