|
Packit Service |
be1c90 |
/* Private floating point rounding and exceptions handling. 390/s390x version.
|
|
Packit Service |
be1c90 |
Copyright (C) 2019 Free Software Foundation, Inc.
|
|
Packit Service |
be1c90 |
This file is part of the GNU C Library.
|
|
Packit Service |
be1c90 |
|
|
Packit Service |
be1c90 |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit Service |
be1c90 |
modify it under the terms of the GNU Lesser General Public
|
|
Packit Service |
be1c90 |
License as published by the Free Software Foundation; either
|
|
Packit Service |
be1c90 |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit Service |
be1c90 |
|
|
Packit Service |
be1c90 |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit Service |
be1c90 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
be1c90 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
be1c90 |
Lesser General Public License for more details.
|
|
Packit Service |
be1c90 |
|
|
Packit Service |
be1c90 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
be1c90 |
License along with the GNU C Library; if not, see
|
|
Packit Service |
be1c90 |
<https://www.gnu.org/licenses/>. */
|
|
Packit Service |
be1c90 |
|
|
Packit Service |
be1c90 |
#ifndef S390_FENV_PRIVATE_H
|
|
Packit Service |
be1c90 |
#define S390_FENV_PRIVATE_H 1
|
|
Packit Service |
be1c90 |
|
|
Packit Service |
be1c90 |
#include <fenv.h>
|
|
Packit Service |
be1c90 |
#include <fenv_libc.h>
|
|
Packit Service |
be1c90 |
#include <fpu_control.h>
|
|
Packit Service |
be1c90 |
|
|
Packit Service |
be1c90 |
static __always_inline void
|
|
Packit Service |
be1c90 |
libc_feholdexcept_s390 (fenv_t *envp)
|
|
Packit Service |
be1c90 |
{
|
|
Packit Service |
be1c90 |
fpu_control_t fpc, fpc_new;
|
|
Packit Service |
be1c90 |
|
|
Packit Service |
be1c90 |
/* Store the environment. */
|
|
Packit Service |
be1c90 |
_FPU_GETCW (fpc);
|
|
Packit Service |
be1c90 |
envp->__fpc = fpc;
|
|
Packit Service |
be1c90 |
|
|
Packit Service |
be1c90 |
/* Clear the current exception flags and dxc field.
|
|
Packit Service |
be1c90 |
Hold from generating fpu exceptions temporarily. */
|
|
Packit Service |
be1c90 |
fpc_new = fpc & ~(FPC_FLAGS_MASK | FPC_DXC_MASK | FPC_EXCEPTION_MASK);
|
|
Packit Service |
be1c90 |
|
|
Packit Service |
be1c90 |
/* Only set new environment if it has changed. */
|
|
Packit Service |
be1c90 |
if (fpc_new != fpc)
|
|
Packit Service |
be1c90 |
_FPU_SETCW (fpc_new);
|
|
Packit Service |
be1c90 |
}
|
|
Packit Service |
be1c90 |
|
|
Packit Service |
be1c90 |
#define libc_feholdexcept libc_feholdexcept_s390
|
|
Packit Service |
be1c90 |
#define libc_feholdexceptf libc_feholdexcept_s390
|
|
Packit Service |
be1c90 |
#define libc_feholdexceptl libc_feholdexcept_s390
|
|
Packit Service |
be1c90 |
|
|
Packit Service |
be1c90 |
static __always_inline void
|
|
Packit Service |
be1c90 |
libc_fesetround_s390 (int round)
|
|
Packit Service |
be1c90 |
{
|
|
Packit Service |
be1c90 |
__asm__ __volatile__ ("srnm 0(%0)" : : "a" (round));
|
|
Packit Service |
be1c90 |
}
|
|
Packit Service |
be1c90 |
|
|
Packit Service |
be1c90 |
#define libc_fesetround libc_fesetround_s390
|
|
Packit Service |
be1c90 |
#define libc_fesetroundf libc_fesetround_s390
|
|
Packit Service |
be1c90 |
#define libc_fesetroundl libc_fesetround_s390
|
|
Packit Service |
be1c90 |
|
|
Packit Service |
be1c90 |
static __always_inline void
|
|
Packit Service |
be1c90 |
libc_feholdexcept_setround_s390 (fenv_t *envp, int r)
|
|
Packit Service |
be1c90 |
{
|
|
Packit Service |
be1c90 |
fpu_control_t fpc, fpc_new;
|
|
Packit Service |
be1c90 |
|
|
Packit Service |
be1c90 |
_FPU_GETCW (fpc);
|
|
Packit Service |
be1c90 |
envp->__fpc = fpc;
|
|
Packit Service |
be1c90 |
|
|
Packit Service |
be1c90 |
/* Clear the current exception flags and dxc field.
|
|
Packit Service |
be1c90 |
Hold from generating fpu exceptions temporarily.
|
|
Packit Service |
be1c90 |
Reset rounding mode bits. */
|
|
Packit Service |
be1c90 |
fpc_new = fpc & ~(FPC_FLAGS_MASK | FPC_DXC_MASK | FPC_EXCEPTION_MASK
|
|
Packit Service |
be1c90 |
| FPC_RM_MASK);
|
|
Packit Service |
be1c90 |
|
|
Packit Service |
be1c90 |
/* Set new rounding mode. */
|
|
Packit Service |
be1c90 |
fpc_new |= (r & FPC_RM_MASK);
|
|
Packit Service |
be1c90 |
|
|
Packit Service |
be1c90 |
/* Only set new environment if it has changed. */
|
|
Packit Service |
be1c90 |
if (fpc_new != fpc)
|
|
Packit Service |
be1c90 |
_FPU_SETCW (fpc_new);
|
|
Packit Service |
be1c90 |
}
|
|
Packit Service |
be1c90 |
|
|
Packit Service |
be1c90 |
#define libc_feholdexcept_setround libc_feholdexcept_setround_s390
|
|
Packit Service |
be1c90 |
#define libc_feholdexcept_setroundf libc_feholdexcept_setround_s390
|
|
Packit Service |
be1c90 |
#define libc_feholdexcept_setroundl libc_feholdexcept_setround_s390
|
|
Packit Service |
be1c90 |
|
|
Packit Service |
be1c90 |
static __always_inline int
|
|
Packit Service |
be1c90 |
libc_fetestexcept_s390 (int excepts)
|
|
Packit Service |
be1c90 |
{
|
|
Packit Service |
be1c90 |
int res;
|
|
Packit Service |
be1c90 |
fexcept_t fpc;
|
|
Packit Service |
be1c90 |
|
|
Packit Service |
be1c90 |
_FPU_GETCW (fpc);
|
|
Packit Service |
be1c90 |
|
|
Packit Service |
be1c90 |
/* Get current exceptions. */
|
|
Packit Service |
be1c90 |
res = (fpc >> FPC_FLAGS_SHIFT) & FE_ALL_EXCEPT;
|
|
Packit Service |
be1c90 |
if ((fpc & FPC_NOT_FPU_EXCEPTION) == 0)
|
|
Packit Service |
be1c90 |
/* Bits 6, 7 of dxc-byte are zero,
|
|
Packit Service |
be1c90 |
thus bits 0-5 of dxc-byte correspond to the flag-bits.
|
|
Packit Service |
be1c90 |
Evaluate flags and last dxc-exception-code. */
|
|
Packit Service |
be1c90 |
res |= (fpc >> FPC_DXC_SHIFT) & FE_ALL_EXCEPT;
|
|
Packit Service |
be1c90 |
|
|
Packit Service |
be1c90 |
return res & excepts;
|
|
Packit Service |
be1c90 |
}
|
|
Packit Service |
be1c90 |
|
|
Packit Service |
be1c90 |
#define libc_fetestexcept libc_fetestexcept_s390
|
|
Packit Service |
be1c90 |
#define libc_fetestexceptf libc_fetestexcept_s390
|
|
Packit Service |
be1c90 |
#define libc_fetestexceptl libc_fetestexcept_s390
|
|
Packit Service |
be1c90 |
|
|
Packit Service |
be1c90 |
static __always_inline void
|
|
Packit Service |
be1c90 |
libc_fesetenv_s390 (const fenv_t *envp)
|
|
Packit Service |
be1c90 |
{
|
|
Packit Service |
be1c90 |
_FPU_SETCW (envp->__fpc);
|
|
Packit Service |
be1c90 |
}
|
|
Packit Service |
be1c90 |
|
|
Packit Service |
be1c90 |
#define libc_fesetenv libc_fesetenv_s390
|
|
Packit Service |
be1c90 |
#define libc_fesetenvf libc_fesetenv_s390
|
|
Packit Service |
be1c90 |
#define libc_fesetenvl libc_fesetenv_s390
|
|
Packit Service |
be1c90 |
|
|
Packit Service |
be1c90 |
static __always_inline int
|
|
Packit Service |
be1c90 |
libc_feupdateenv_test_s390 (const fenv_t *envp, int ex)
|
|
Packit Service |
be1c90 |
{
|
|
Packit Service |
be1c90 |
/* Get the currently raised exceptions. */
|
|
Packit Service |
be1c90 |
int excepts;
|
|
Packit Service |
be1c90 |
fexcept_t fpc_old;
|
|
Packit Service |
be1c90 |
|
|
Packit Service |
be1c90 |
_FPU_GETCW (fpc_old);
|
|
Packit Service |
be1c90 |
|
|
Packit Service |
be1c90 |
/* Get current exceptions. */
|
|
Packit Service |
be1c90 |
excepts = (fpc_old >> FPC_FLAGS_SHIFT) & FE_ALL_EXCEPT;
|
|
Packit Service |
be1c90 |
if ((fpc_old & FPC_NOT_FPU_EXCEPTION) == 0)
|
|
Packit Service |
be1c90 |
/* Bits 6, 7 of dxc-byte are zero,
|
|
Packit Service |
be1c90 |
thus bits 0-5 of dxc-byte correspond to the flag-bits.
|
|
Packit Service |
be1c90 |
Evaluate flags and last dxc-exception-code. */
|
|
Packit Service |
be1c90 |
excepts |= (fpc_old >> FPC_DXC_SHIFT) & FE_ALL_EXCEPT;
|
|
Packit Service |
be1c90 |
|
|
Packit Service |
be1c90 |
/* Merge the currently raised exceptions with those in envp. */
|
|
Packit Service |
be1c90 |
fpu_control_t fpc_new = envp->__fpc;
|
|
Packit Service |
be1c90 |
fpc_new |= excepts << FPC_FLAGS_SHIFT;
|
|
Packit Service |
be1c90 |
|
|
Packit Service |
be1c90 |
/* Install the new fpc from envp. */
|
|
Packit Service |
be1c90 |
if (fpc_new != fpc_old)
|
|
Packit Service |
be1c90 |
_FPU_SETCW (fpc_new);
|
|
Packit Service |
be1c90 |
|
|
Packit Service |
be1c90 |
/* Raise the exceptions if enabled in new fpc. */
|
|
Packit Service |
be1c90 |
if (__glibc_unlikely ((fpc_new >> FPC_EXCEPTION_MASK_SHIFT) & excepts))
|
|
Packit Service |
be1c90 |
__feraiseexcept (excepts);
|
|
Packit Service |
be1c90 |
|
|
Packit Service |
be1c90 |
return excepts & ex;
|
|
Packit Service |
be1c90 |
}
|
|
Packit Service |
be1c90 |
|
|
Packit Service |
be1c90 |
#define libc_feupdateenv_test libc_feupdateenv_test_s390
|
|
Packit Service |
be1c90 |
#define libc_feupdateenv_testf libc_feupdateenv_test_s390
|
|
Packit Service |
be1c90 |
#define libc_feupdateenv_testl libc_feupdateenv_test_s390
|
|
Packit Service |
be1c90 |
|
|
Packit Service |
be1c90 |
static __always_inline void
|
|
Packit Service |
be1c90 |
libc_feupdateenv_s390 (const fenv_t *envp)
|
|
Packit Service |
be1c90 |
{
|
|
Packit Service |
be1c90 |
libc_feupdateenv_test_s390 (envp, 0);
|
|
Packit Service |
be1c90 |
}
|
|
Packit Service |
be1c90 |
|
|
Packit Service |
be1c90 |
#define libc_feupdateenv libc_feupdateenv_s390
|
|
Packit Service |
be1c90 |
#define libc_feupdateenvf libc_feupdateenv_s390
|
|
Packit Service |
be1c90 |
#define libc_feupdateenvl libc_feupdateenv_s390
|
|
Packit Service |
be1c90 |
|
|
Packit Service |
be1c90 |
static __always_inline fenv_t
|
|
Packit Service |
be1c90 |
libc_handle_user_fenv_s390 (const fenv_t *envp)
|
|
Packit Service |
be1c90 |
{
|
|
Packit Service |
be1c90 |
fenv_t env;
|
|
Packit Service |
be1c90 |
if (envp == FE_DFL_ENV)
|
|
Packit Service |
be1c90 |
{
|
|
Packit Service |
be1c90 |
env.__fpc = _FPU_DEFAULT;
|
|
Packit Service |
be1c90 |
}
|
|
Packit Service |
be1c90 |
else if (envp == FE_NOMASK_ENV)
|
|
Packit Service |
be1c90 |
{
|
|
Packit Service |
be1c90 |
env.__fpc = FPC_EXCEPTION_MASK;
|
|
Packit Service |
be1c90 |
}
|
|
Packit Service |
be1c90 |
else
|
|
Packit Service |
be1c90 |
env = (*envp);
|
|
Packit Service |
be1c90 |
|
|
Packit Service |
be1c90 |
return env;
|
|
Packit Service |
be1c90 |
}
|
|
Packit Service |
be1c90 |
|
|
Packit Service |
be1c90 |
/* We have support for rounding mode context. */
|
|
Packit Service |
be1c90 |
#define HAVE_RM_CTX 1
|
|
Packit Service |
be1c90 |
|
|
Packit Service |
be1c90 |
static __always_inline void
|
|
Packit Service |
be1c90 |
libc_feholdsetround_s390_ctx (struct rm_ctx *ctx, int r)
|
|
Packit Service |
be1c90 |
{
|
|
Packit Service |
be1c90 |
fpu_control_t fpc;
|
|
Packit Service |
be1c90 |
int round;
|
|
Packit Service |
be1c90 |
|
|
Packit Service |
be1c90 |
_FPU_GETCW (fpc);
|
|
Packit Service |
be1c90 |
ctx->env.__fpc = fpc;
|
|
Packit Service |
be1c90 |
|
|
Packit Service |
be1c90 |
/* Check whether rounding modes are different. */
|
|
Packit Service |
be1c90 |
round = fpc & FPC_RM_MASK;
|
|
Packit Service |
be1c90 |
|
|
Packit Service |
be1c90 |
/* Set the rounding mode if changed. */
|
|
Packit Service |
be1c90 |
if (__glibc_unlikely (round != r))
|
|
Packit Service |
be1c90 |
{
|
|
Packit Service |
be1c90 |
ctx->updated_status = true;
|
|
Packit Service |
be1c90 |
libc_fesetround_s390 (r);
|
|
Packit Service |
be1c90 |
}
|
|
Packit Service |
be1c90 |
else
|
|
Packit Service |
be1c90 |
ctx->updated_status = false;
|
|
Packit Service |
be1c90 |
}
|
|
Packit Service |
be1c90 |
|
|
Packit Service |
be1c90 |
#define libc_feholdsetround_ctx libc_feholdsetround_s390_ctx
|
|
Packit Service |
be1c90 |
#define libc_feholdsetroundf_ctx libc_feholdsetround_s390_ctx
|
|
Packit Service |
be1c90 |
#define libc_feholdsetroundl_ctx libc_feholdsetround_s390_ctx
|
|
Packit Service |
be1c90 |
|
|
Packit Service |
be1c90 |
static __always_inline void
|
|
Packit Service |
be1c90 |
libc_feresetround_s390_ctx (struct rm_ctx *ctx)
|
|
Packit Service |
be1c90 |
{
|
|
Packit Service |
be1c90 |
/* Restore the rounding mode if updated. */
|
|
Packit Service |
be1c90 |
if (__glibc_unlikely (ctx->updated_status))
|
|
Packit Service |
be1c90 |
{
|
|
Packit Service |
be1c90 |
fpu_control_t fpc;
|
|
Packit Service |
be1c90 |
_FPU_GETCW (fpc);
|
|
Packit Service |
be1c90 |
fpc = ctx->env.__fpc | (fpc & FPC_FLAGS_MASK);
|
|
Packit Service |
be1c90 |
_FPU_SETCW (fpc);
|
|
Packit Service |
be1c90 |
}
|
|
Packit Service |
be1c90 |
}
|
|
Packit Service |
be1c90 |
|
|
Packit Service |
be1c90 |
#define libc_feresetround_ctx libc_feresetround_s390_ctx
|
|
Packit Service |
be1c90 |
#define libc_feresetroundf_ctx libc_feresetround_s390_ctx
|
|
Packit Service |
be1c90 |
#define libc_feresetroundl_ctx libc_feresetround_s390_ctx
|
|
Packit Service |
be1c90 |
|
|
Packit Service |
be1c90 |
static __always_inline void
|
|
Packit Service |
be1c90 |
libc_feholdsetround_noex_s390_ctx (struct rm_ctx *ctx, int r)
|
|
Packit Service |
be1c90 |
{
|
|
Packit Service |
be1c90 |
libc_feholdexcept_setround_s390 (&ctx->env, r);
|
|
Packit Service |
be1c90 |
}
|
|
Packit Service |
be1c90 |
|
|
Packit Service |
be1c90 |
#define libc_feholdsetround_noex_ctx libc_feholdsetround_noex_s390_ctx
|
|
Packit Service |
be1c90 |
#define libc_feholdsetround_noexf_ctx libc_feholdsetround_noex_s390_ctx
|
|
Packit Service |
be1c90 |
#define libc_feholdsetround_noexl_ctx libc_feholdsetround_noex_s390_ctx
|
|
Packit Service |
be1c90 |
|
|
Packit Service |
be1c90 |
static __always_inline void
|
|
Packit Service |
be1c90 |
libc_feresetround_noex_s390_ctx (struct rm_ctx *ctx)
|
|
Packit Service |
be1c90 |
{
|
|
Packit Service |
be1c90 |
/* Restore exception flags and rounding mode. */
|
|
Packit Service |
be1c90 |
libc_fesetenv_s390 (&ctx->env);
|
|
Packit Service |
be1c90 |
}
|
|
Packit Service |
be1c90 |
|
|
Packit Service |
be1c90 |
#define libc_feresetround_noex_ctx libc_feresetround_noex_s390_ctx
|
|
Packit Service |
be1c90 |
#define libc_feresetround_noexf_ctx libc_feresetround_noex_s390_ctx
|
|
Packit Service |
be1c90 |
#define libc_feresetround_noexl_ctx libc_feresetround_noex_s390_ctx
|
|
Packit Service |
be1c90 |
|
|
Packit Service |
be1c90 |
#endif
|