|
Packit |
6c4009 |
/* Private floating point rounding and exceptions handling. ARM VFP version.
|
|
Packit |
6c4009 |
Copyright (C) 2014-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 <fpu_control.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static __always_inline void
|
|
Packit |
6c4009 |
libc_feholdexcept_vfp (fenv_t *envp)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
fpu_control_t fpscr;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
_FPU_GETCW (fpscr);
|
|
Packit |
6c4009 |
envp->__cw = fpscr;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Clear exception flags and set all exceptions to non-stop. */
|
|
Packit |
6c4009 |
fpscr &= ~_FPU_MASK_EXCEPT;
|
|
Packit |
6c4009 |
_FPU_SETCW (fpscr);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static __always_inline void
|
|
Packit |
6c4009 |
libc_fesetround_vfp (int round)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
fpu_control_t fpscr;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
_FPU_GETCW (fpscr);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Set new rounding mode if different. */
|
|
Packit |
6c4009 |
if (__glibc_unlikely ((fpscr & _FPU_MASK_RM) != round))
|
|
Packit |
6c4009 |
_FPU_SETCW ((fpscr & ~_FPU_MASK_RM) | round);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static __always_inline void
|
|
Packit |
6c4009 |
libc_feholdexcept_setround_vfp (fenv_t *envp, int round)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
fpu_control_t fpscr;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
_FPU_GETCW (fpscr);
|
|
Packit |
6c4009 |
envp->__cw = fpscr;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Clear exception flags, set all exceptions to non-stop,
|
|
Packit |
6c4009 |
and set new rounding mode. */
|
|
Packit |
6c4009 |
fpscr &= ~(_FPU_MASK_EXCEPT | _FPU_MASK_RM);
|
|
Packit |
6c4009 |
_FPU_SETCW (fpscr | round);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static __always_inline void
|
|
Packit |
6c4009 |
libc_feholdsetround_vfp (fenv_t *envp, int round)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
fpu_control_t fpscr;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
_FPU_GETCW (fpscr);
|
|
Packit |
6c4009 |
envp->__cw = fpscr;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Set new rounding mode if different. */
|
|
Packit |
6c4009 |
if (__glibc_unlikely ((fpscr & _FPU_MASK_RM) != round))
|
|
Packit |
6c4009 |
_FPU_SETCW ((fpscr & ~_FPU_MASK_RM) | round);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static __always_inline void
|
|
Packit |
6c4009 |
libc_feresetround_vfp (fenv_t *envp)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
fpu_control_t fpscr, round;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
_FPU_GETCW (fpscr);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Check whether rounding modes are different. */
|
|
Packit |
6c4009 |
round = (envp->__cw ^ fpscr) & _FPU_MASK_RM;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Restore the rounding mode if it was changed. */
|
|
Packit |
6c4009 |
if (__glibc_unlikely (round != 0))
|
|
Packit |
6c4009 |
_FPU_SETCW (fpscr ^ round);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static __always_inline int
|
|
Packit |
6c4009 |
libc_fetestexcept_vfp (int ex)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
fpu_control_t fpscr;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
_FPU_GETCW (fpscr);
|
|
Packit |
6c4009 |
return fpscr & ex & FE_ALL_EXCEPT;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static __always_inline void
|
|
Packit |
6c4009 |
libc_fesetenv_vfp (const fenv_t *envp)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
fpu_control_t fpscr, new_fpscr;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
_FPU_GETCW (fpscr);
|
|
Packit |
6c4009 |
new_fpscr = envp->__cw;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Write new FPSCR if different (ignoring NZCV flags). */
|
|
Packit |
6c4009 |
if (__glibc_unlikely (((fpscr ^ new_fpscr) & ~_FPU_MASK_NZCV) != 0))
|
|
Packit |
6c4009 |
_FPU_SETCW (new_fpscr);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static __always_inline int
|
|
Packit |
6c4009 |
libc_feupdateenv_test_vfp (const fenv_t *envp, int ex)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
fpu_control_t fpscr, new_fpscr;
|
|
Packit |
6c4009 |
int excepts;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
_FPU_GETCW (fpscr);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Merge current exception flags with the saved fenv. */
|
|
Packit |
6c4009 |
excepts = fpscr & FE_ALL_EXCEPT;
|
|
Packit |
6c4009 |
new_fpscr = envp->__cw | excepts;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Write new FPSCR if different (ignoring NZCV flags). */
|
|
Packit |
6c4009 |
if (__glibc_unlikely (((fpscr ^ new_fpscr) & ~_FPU_MASK_NZCV) != 0))
|
|
Packit |
6c4009 |
_FPU_SETCW (new_fpscr);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Raise the exceptions if enabled in the new FP state. */
|
|
Packit |
6c4009 |
if (__glibc_unlikely (excepts & (new_fpscr >> FE_EXCEPT_SHIFT)))
|
|
Packit |
6c4009 |
__feraiseexcept (excepts);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
return excepts & ex;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static __always_inline void
|
|
Packit |
6c4009 |
libc_feupdateenv_vfp (const fenv_t *envp)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
libc_feupdateenv_test_vfp (envp, 0);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static __always_inline void
|
|
Packit |
6c4009 |
libc_feholdsetround_vfp_ctx (struct rm_ctx *ctx, int r)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
fpu_control_t fpscr, round;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
_FPU_GETCW (fpscr);
|
|
Packit |
6c4009 |
ctx->updated_status = false;
|
|
Packit |
6c4009 |
ctx->env.__cw = fpscr;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Check whether rounding modes are different. */
|
|
Packit |
6c4009 |
round = (fpscr ^ r) & _FPU_MASK_RM;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Set the rounding mode if changed. */
|
|
Packit |
6c4009 |
if (__glibc_unlikely (round != 0))
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
ctx->updated_status = true;
|
|
Packit |
6c4009 |
_FPU_SETCW (fpscr ^ round);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static __always_inline void
|
|
Packit |
6c4009 |
libc_feresetround_vfp_ctx (struct rm_ctx *ctx)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
/* Restore the rounding mode if updated. */
|
|
Packit |
6c4009 |
if (__glibc_unlikely (ctx->updated_status))
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
fpu_control_t fpscr;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
_FPU_GETCW (fpscr);
|
|
Packit |
6c4009 |
fpscr = (fpscr & ~_FPU_MASK_RM) | (ctx->env.__cw & _FPU_MASK_RM);
|
|
Packit |
6c4009 |
_FPU_SETCW (fpscr);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static __always_inline void
|
|
Packit |
6c4009 |
libc_fesetenv_vfp_ctx (struct rm_ctx *ctx)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
fpu_control_t fpscr, new_fpscr;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
_FPU_GETCW (fpscr);
|
|
Packit |
6c4009 |
new_fpscr = ctx->env.__cw;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Write new FPSCR if different (ignoring NZCV flags). */
|
|
Packit |
6c4009 |
if (__glibc_unlikely (((fpscr ^ new_fpscr) & ~_FPU_MASK_NZCV) != 0))
|
|
Packit |
6c4009 |
_FPU_SETCW (new_fpscr);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#ifndef __SOFTFP__
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# define libc_feholdexcept libc_feholdexcept_vfp
|
|
Packit |
6c4009 |
# define libc_feholdexceptf libc_feholdexcept_vfp
|
|
Packit |
6c4009 |
# define libc_feholdexceptl libc_feholdexcept_vfp
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# define libc_fesetround libc_fesetround_vfp
|
|
Packit |
6c4009 |
# define libc_fesetroundf libc_fesetround_vfp
|
|
Packit |
6c4009 |
# define libc_fesetroundl libc_fesetround_vfp
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# define libc_feresetround libc_feresetround_vfp
|
|
Packit |
6c4009 |
# define libc_feresetroundf libc_feresetround_vfp
|
|
Packit |
6c4009 |
# define libc_feresetroundl libc_feresetround_vfp
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# define libc_feresetround_noex libc_fesetenv_vfp
|
|
Packit |
6c4009 |
# define libc_feresetround_noexf libc_fesetenv_vfp
|
|
Packit |
6c4009 |
# define libc_feresetround_noexl libc_fesetenv_vfp
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# define libc_feholdexcept_setround libc_feholdexcept_setround_vfp
|
|
Packit |
6c4009 |
# define libc_feholdexcept_setroundf libc_feholdexcept_setround_vfp
|
|
Packit |
6c4009 |
# define libc_feholdexcept_setroundl libc_feholdexcept_setround_vfp
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# define libc_feholdsetround libc_feholdsetround_vfp
|
|
Packit |
6c4009 |
# define libc_feholdsetroundf libc_feholdsetround_vfp
|
|
Packit |
6c4009 |
# define libc_feholdsetroundl libc_feholdsetround_vfp
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# define libc_fetestexcept libc_fetestexcept_vfp
|
|
Packit |
6c4009 |
# define libc_fetestexceptf libc_fetestexcept_vfp
|
|
Packit |
6c4009 |
# define libc_fetestexceptl libc_fetestexcept_vfp
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# define libc_fesetenv libc_fesetenv_vfp
|
|
Packit |
6c4009 |
# define libc_fesetenvf libc_fesetenv_vfp
|
|
Packit |
6c4009 |
# define libc_fesetenvl libc_fesetenv_vfp
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# define libc_feupdateenv libc_feupdateenv_vfp
|
|
Packit |
6c4009 |
# define libc_feupdateenvf libc_feupdateenv_vfp
|
|
Packit |
6c4009 |
# define libc_feupdateenvl libc_feupdateenv_vfp
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# define libc_feupdateenv_test libc_feupdateenv_test_vfp
|
|
Packit |
6c4009 |
# define libc_feupdateenv_testf libc_feupdateenv_test_vfp
|
|
Packit |
6c4009 |
# define libc_feupdateenv_testl libc_feupdateenv_test_vfp
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* We have support for rounding mode context. */
|
|
Packit |
6c4009 |
#define HAVE_RM_CTX 1
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# define libc_feholdsetround_ctx libc_feholdsetround_vfp_ctx
|
|
Packit |
6c4009 |
# define libc_feresetround_ctx libc_feresetround_vfp_ctx
|
|
Packit |
6c4009 |
# define libc_feresetround_noex_ctx libc_fesetenv_vfp_ctx
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# define libc_feholdsetroundf_ctx libc_feholdsetround_vfp_ctx
|
|
Packit |
6c4009 |
# define libc_feresetroundf_ctx libc_feresetround_vfp_ctx
|
|
Packit |
6c4009 |
# define libc_feresetround_noexf_ctx libc_fesetenv_vfp_ctx
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# define libc_feholdsetroundl_ctx libc_feholdsetround_vfp_ctx
|
|
Packit |
6c4009 |
# define libc_feresetroundl_ctx libc_feresetround_vfp_ctx
|
|
Packit |
6c4009 |
# define libc_feresetround_noexl_ctx libc_fesetenv_vfp_ctx
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#endif /* FENV_PRIVATE_H */
|