|
Packit |
6c4009 |
/* Private floating point rounding and exceptions handling. PowerPC version.
|
|
Packit |
6c4009 |
Copyright (C) 2013-2018 Free Software Foundation, Inc.
|
|
Packit |
6c4009 |
This file is part of the GNU C Library.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit |
6c4009 |
modify it under the terms of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License as published by the Free Software Foundation; either
|
|
Packit |
6c4009 |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit |
6c4009 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6c4009 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
6c4009 |
Lesser General Public License for more details.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License along with the GNU C Library. If not, see
|
|
Packit |
6c4009 |
<http://www.gnu.org/licenses/>. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#ifndef FENV_PRIVATE_H
|
|
Packit |
6c4009 |
#define FENV_PRIVATE_H 1
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <fenv.h>
|
|
Packit |
6c4009 |
#include <fenv_libc.h>
|
|
Packit |
6c4009 |
#include <fpu_control.h>
|
|
Packit |
6c4009 |
|
|
Packit Service |
6de65a |
/* Mask for the exception enable bits. */
|
|
Packit Service |
6de65a |
#define _FPU_ALL_TRAPS (_FPU_MASK_ZM | _FPU_MASK_OM | _FPU_MASK_UM \
|
|
Packit Service |
6de65a |
| _FPU_MASK_XM | _FPU_MASK_IM)
|
|
Packit Service |
6de65a |
|
|
Packit Service |
6de65a |
/* Mask the rounding mode bits. */
|
|
Packit Service |
6de65a |
#define _FPU_MASK_RN 0xfffffffffffffffcLL
|
|
Packit Service |
6de65a |
|
|
Packit Service |
6de65a |
/* Mask everything but the rounding modes and non-IEEE arithmetic flags. */
|
|
Packit Service |
6de65a |
#define _FPU_MASK_NOT_RN_NI 0xffffffff00000807LL
|
|
Packit Service |
6de65a |
|
|
Packit Service |
6de65a |
/* Mask restore rounding mode and exception enabled. */
|
|
Packit Service |
6de65a |
#define _FPU_MASK_TRAPS_RN 0xffffffffffffff00LL
|
|
Packit Service |
6de65a |
|
|
Packit Service |
6de65a |
/* Mask FP result flags, preserve fraction rounded/inexact bits. */
|
|
Packit Service |
6de65a |
#define _FPU_MASK_FRAC_INEX_RET_CC 0xfffffffffff80fffLL
|
|
Packit Service |
217b5c |
|
|
Packit |
6c4009 |
static __always_inline void
|
|
Packit Service |
6de65a |
__libc_feholdbits_ppc (fenv_t *envp, unsigned long long mask,
|
|
Packit Service |
6de65a |
unsigned long long bits)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
fenv_union_t old, new;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
old.fenv = *envp = fegetenv_register ();
|
|
Packit |
6c4009 |
|
|
Packit Service |
6de65a |
new.l = (old.l & mask) | bits;
|
|
Packit Service |
6de65a |
|
|
Packit Service |
6de65a |
/* If the old env had any enabled exceptions, then mask SIGFPE in the
|
|
Packit Service |
6de65a |
MSR FE0/FE1 bits. This may allow the FPU to run faster because it
|
|
Packit Service |
6de65a |
always takes the default action and can not generate SIGFPE. */
|
|
Packit Service |
6de65a |
if ((old.l & _FPU_ALL_TRAPS) != 0)
|
|
Packit Service |
6de65a |
(void) __fe_mask_env ();
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
fesetenv_register (new.fenv);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit Service |
6de65a |
static __always_inline void
|
|
Packit Service |
6de65a |
libc_feholdexcept_ppc (fenv_t *envp)
|
|
Packit Service |
6de65a |
{
|
|
Packit Service |
6de65a |
__libc_feholdbits_ppc (envp, _FPU_MASK_NOT_RN_NI, 0LL);
|
|
Packit Service |
6de65a |
}
|
|
Packit Service |
6de65a |
|
|
Packit Service |
6de65a |
static __always_inline void
|
|
Packit Service |
6de65a |
libc_feholdexcept_setround_ppc (fenv_t *envp, int r)
|
|
Packit Service |
6de65a |
{
|
|
Packit Service |
6de65a |
__libc_feholdbits_ppc (envp, _FPU_MASK_NOT_RN_NI & _FPU_MASK_RN, r);
|
|
Packit Service |
6de65a |
}
|
|
Packit Service |
6de65a |
|
|
Packit Service |
6de65a |
static __always_inline void
|
|
Packit Service |
6de65a |
libc_fesetround_ppc (int r)
|
|
Packit Service |
6de65a |
{
|
|
Packit Service |
6de65a |
__fesetround_inline (r);
|
|
Packit Service |
6de65a |
}
|
|
Packit Service |
6de65a |
|
|
Packit Service |
6de65a |
static __always_inline int
|
|
Packit Service |
6de65a |
libc_fetestexcept_ppc (int e)
|
|
Packit Service |
6de65a |
{
|
|
Packit Service |
6de65a |
fenv_union_t u;
|
|
Packit Service |
6de65a |
u.fenv = fegetenv_register ();
|
|
Packit Service |
6de65a |
return u.l & e;
|
|
Packit Service |
6de65a |
}
|
|
Packit Service |
6de65a |
|
|
Packit Service |
6de65a |
static __always_inline void
|
|
Packit Service |
6de65a |
libc_feholdsetround_ppc (fenv_t *e, int r)
|
|
Packit Service |
6de65a |
{
|
|
Packit Service |
6de65a |
__libc_feholdbits_ppc (e, _FPU_MASK_TRAPS_RN, r);
|
|
Packit Service |
6de65a |
}
|
|
Packit Service |
6de65a |
|
|
Packit |
6c4009 |
static __always_inline unsigned long long
|
|
Packit |
6c4009 |
__libc_femergeenv_ppc (const fenv_t *envp, unsigned long long old_mask,
|
|
Packit |
6c4009 |
unsigned long long new_mask)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
fenv_union_t old, new;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
new.fenv = *envp;
|
|
Packit |
6c4009 |
old.fenv = fegetenv_register ();
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Merge bits while masking unwanted bits from new and old env. */
|
|
Packit |
6c4009 |
new.l = (old.l & old_mask) | (new.l & new_mask);
|
|
Packit |
6c4009 |
|
|
Packit Service |
6de65a |
/* If the old env has no enabled exceptions and the new env has any enabled
|
|
Packit Service |
6de65a |
exceptions, then unmask SIGFPE in the MSR FE0/FE1 bits. This will put the
|
|
Packit Service |
6de65a |
hardware into "precise mode" and may cause the FPU to run slower on some
|
|
Packit Service |
6de65a |
hardware. */
|
|
Packit Service |
6de65a |
if ((old.l & _FPU_ALL_TRAPS) == 0 && (new.l & _FPU_ALL_TRAPS) != 0)
|
|
Packit Service |
6de65a |
(void) __fe_nomask_env_priv ();
|
|
Packit Service |
6de65a |
|
|
Packit Service |
6de65a |
/* If the old env had any enabled exceptions and the new env has no enabled
|
|
Packit Service |
6de65a |
exceptions, then mask SIGFPE in the MSR FE0/FE1 bits. This may allow the
|
|
Packit Service |
6de65a |
FPU to run faster because it always takes the default action and can not
|
|
Packit Service |
6de65a |
generate SIGFPE. */
|
|
Packit Service |
6de65a |
if ((old.l & _FPU_ALL_TRAPS) != 0 && (new.l & _FPU_ALL_TRAPS) == 0)
|
|
Packit Service |
6de65a |
(void) __fe_mask_env ();
|
|
Packit Service |
6de65a |
|
|
Packit Service |
6de65a |
/* Atomically enable and raise (if appropriate) exceptions set in `new'. */
|
|
Packit Service |
6de65a |
fesetenv_register (new.fenv);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
return old.l;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static __always_inline void
|
|
Packit |
6c4009 |
libc_fesetenv_ppc (const fenv_t *envp)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
/* Replace the entire environment. */
|
|
Packit |
6c4009 |
__libc_femergeenv_ppc (envp, 0LL, -1LL);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static __always_inline void
|
|
Packit |
6c4009 |
libc_feresetround_ppc (fenv_t *envp)
|
|
Packit |
6c4009 |
{
|
|
Packit Service |
26ffa5 |
fenv_union_t new = { .fenv = *envp };
|
|
Packit Service |
12d36c |
fegetenv_and_set_rn (new.l & FPSCR_RN_MASK);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static __always_inline int
|
|
Packit |
6c4009 |
libc_feupdateenv_test_ppc (fenv_t *envp, int ex)
|
|
Packit |
6c4009 |
{
|
|
Packit Service |
6de65a |
return __libc_femergeenv_ppc (envp, _FPU_MASK_TRAPS_RN,
|
|
Packit Service |
6de65a |
_FPU_MASK_FRAC_INEX_RET_CC) & ex;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static __always_inline void
|
|
Packit |
6c4009 |
libc_feupdateenv_ppc (fenv_t *e)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
libc_feupdateenv_test_ppc (e, 0);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#define libc_feholdexceptf libc_feholdexcept_ppc
|
|
Packit |
6c4009 |
#define libc_feholdexcept libc_feholdexcept_ppc
|
|
Packit |
6c4009 |
#define libc_feholdexcept_setroundf libc_feholdexcept_setround_ppc
|
|
Packit |
6c4009 |
#define libc_feholdexcept_setround libc_feholdexcept_setround_ppc
|
|
Packit |
6c4009 |
#define libc_fetestexceptf libc_fetestexcept_ppc
|
|
Packit |
6c4009 |
#define libc_fetestexcept libc_fetestexcept_ppc
|
|
Packit |
6c4009 |
#define libc_fesetroundf libc_fesetround_ppc
|
|
Packit |
6c4009 |
#define libc_fesetround libc_fesetround_ppc
|
|
Packit |
6c4009 |
#define libc_fesetenvf libc_fesetenv_ppc
|
|
Packit |
6c4009 |
#define libc_fesetenv libc_fesetenv_ppc
|
|
Packit |
6c4009 |
#define libc_feupdateenv_testf libc_feupdateenv_test_ppc
|
|
Packit |
6c4009 |
#define libc_feupdateenv_test libc_feupdateenv_test_ppc
|
|
Packit |
6c4009 |
#define libc_feupdateenvf libc_feupdateenv_ppc
|
|
Packit |
6c4009 |
#define libc_feupdateenv libc_feupdateenv_ppc
|
|
Packit |
6c4009 |
#define libc_feholdsetroundf libc_feholdsetround_ppc
|
|
Packit |
6c4009 |
#define libc_feholdsetround libc_feholdsetround_ppc
|
|
Packit |
6c4009 |
#define libc_feresetroundf libc_feresetround_ppc
|
|
Packit |
6c4009 |
#define libc_feresetround libc_feresetround_ppc
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* We have support for rounding mode context. */
|
|
Packit |
6c4009 |
#define HAVE_RM_CTX 1
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static __always_inline void
|
|
Packit |
6c4009 |
libc_feholdsetround_ppc_ctx (struct rm_ctx *ctx, int r)
|
|
Packit |
6c4009 |
{
|
|
Packit Service |
12d36c |
fenv_union_t old;
|
|
Packit Service |
52f013 |
|
|
Packit Service |
12d36c |
ctx->env = old.fenv = fegetenv_and_set_rn (r);
|
|
Packit Service |
12d36c |
ctx->updated_status = (r != (old.l & FPSCR_RN_MASK));
|
|
Packit Service |
26ffa5 |
}
|
|
Packit Service |
26ffa5 |
|
|
Packit Service |
26ffa5 |
static __always_inline void
|
|
Packit Service |
26ffa5 |
libc_feholdsetround_noex_ppc_ctx (struct rm_ctx *ctx, int r)
|
|
Packit Service |
26ffa5 |
{
|
|
Packit Service |
26ffa5 |
fenv_union_t old, new;
|
|
Packit Service |
26ffa5 |
|
|
Packit |
6c4009 |
old.fenv = fegetenv_register ();
|
|
Packit |
6c4009 |
|
|
Packit Service |
26ffa5 |
new.l = (old.l & ~(FPSCR_ENABLES_MASK|FPSCR_RN_MASK)) | r;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
ctx->env = old.fenv;
|
|
Packit |
6c4009 |
if (__glibc_unlikely (new.l != old.l))
|
|
Packit |
6c4009 |
{
|
|
Packit Service |
6de65a |
if ((old.l & _FPU_ALL_TRAPS) != 0)
|
|
Packit Service |
6de65a |
(void) __fe_mask_env ();
|
|
Packit Service |
6de65a |
fesetenv_register (new.fenv);
|
|
Packit |
6c4009 |
ctx->updated_status = true;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
else
|
|
Packit |
6c4009 |
ctx->updated_status = false;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static __always_inline void
|
|
Packit |
6c4009 |
libc_fesetenv_ppc_ctx (struct rm_ctx *ctx)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
libc_fesetenv_ppc (&ctx->env);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static __always_inline void
|
|
Packit |
6c4009 |
libc_feupdateenv_ppc_ctx (struct rm_ctx *ctx)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
if (__glibc_unlikely (ctx->updated_status))
|
|
Packit |
6c4009 |
libc_feresetround_ppc (&ctx->env);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static __always_inline void
|
|
Packit |
6c4009 |
libc_feresetround_ppc_ctx (struct rm_ctx *ctx)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
if (__glibc_unlikely (ctx->updated_status))
|
|
Packit |
6c4009 |
libc_feresetround_ppc (&ctx->env);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#define libc_fesetenv_ctx libc_fesetenv_ppc_ctx
|
|
Packit |
6c4009 |
#define libc_fesetenvf_ctx libc_fesetenv_ppc_ctx
|
|
Packit |
6c4009 |
#define libc_fesetenvl_ctx libc_fesetenv_ppc_ctx
|
|
Packit |
6c4009 |
#define libc_feholdsetround_ctx libc_feholdsetround_ppc_ctx
|
|
Packit |
6c4009 |
#define libc_feholdsetroundf_ctx libc_feholdsetround_ppc_ctx
|
|
Packit |
6c4009 |
#define libc_feholdsetroundl_ctx libc_feholdsetround_ppc_ctx
|
|
Packit Service |
26ffa5 |
#define libc_feholdsetround_noex_ctx libc_feholdsetround_noex_ppc_ctx
|
|
Packit Service |
26ffa5 |
#define libc_feholdsetround_noexf_ctx libc_feholdsetround_noex_ppc_ctx
|
|
Packit Service |
26ffa5 |
#define libc_feholdsetround_noexl_ctx libc_feholdsetround_noex_ppc_ctx
|
|
Packit |
6c4009 |
#define libc_feresetround_ctx libc_feresetround_ppc_ctx
|
|
Packit |
6c4009 |
#define libc_feresetroundf_ctx libc_feresetround_ppc_ctx
|
|
Packit |
6c4009 |
#define libc_feresetroundl_ctx libc_feresetround_ppc_ctx
|
|
Packit |
6c4009 |
#define libc_feupdateenv_ctx libc_feupdateenv_ppc_ctx
|
|
Packit |
6c4009 |
#define libc_feupdateenvf_ctx libc_feupdateenv_ppc_ctx
|
|
Packit |
6c4009 |
#define libc_feupdateenvl_ctx libc_feupdateenv_ppc_ctx
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#endif
|