Blame sysdeps/powerpc/fpu/fenv_private.h

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 562438
/* Mask for the exception enable bits.  */
Packit Service 562438
#define _FPU_ALL_TRAPS (_FPU_MASK_ZM | _FPU_MASK_OM | _FPU_MASK_UM \
Packit Service 562438
                      | _FPU_MASK_XM | _FPU_MASK_IM)
Packit Service 562438
Packit Service 562438
/* Mask the rounding mode bits.  */
Packit Service 562438
#define _FPU_MASK_RN 0xfffffffffffffffcLL
Packit Service 562438
Packit Service 562438
/* Mask everything but the rounding modes and non-IEEE arithmetic flags.  */
Packit Service 562438
#define _FPU_MASK_NOT_RN_NI 0xffffffff00000807LL
Packit Service 562438
Packit Service 562438
/* Mask restore rounding mode and exception enabled.  */
Packit Service 562438
#define _FPU_MASK_TRAPS_RN 0xffffffffffffff00LL
Packit Service 562438
Packit Service 562438
/* Mask FP result flags, preserve fraction rounded/inexact bits.  */
Packit Service 562438
#define _FPU_MASK_FRAC_INEX_RET_CC 0xfffffffffff80fffLL
Packit Service 43e1b2
Packit 6c4009
static __always_inline void
Packit Service 562438
__libc_feholdbits_ppc (fenv_t *envp, unsigned long long mask,
Packit Service 562438
	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 562438
  new.l = (old.l & mask) | bits;
Packit Service 562438
Packit Service 562438
  /* If the old env had any enabled exceptions, then mask SIGFPE in the
Packit Service 562438
     MSR FE0/FE1 bits.  This may allow the FPU to run faster because it
Packit Service 562438
     always takes the default action and can not generate SIGFPE.  */
Packit Service 562438
  if ((old.l & _FPU_ALL_TRAPS) != 0)
Packit Service 562438
    (void) __fe_mask_env ();
Packit 6c4009
Packit 6c4009
  fesetenv_register (new.fenv);
Packit 6c4009
}
Packit 6c4009
Packit Service 562438
static __always_inline void
Packit Service 562438
libc_feholdexcept_ppc (fenv_t *envp)
Packit Service 562438
{
Packit Service 562438
  __libc_feholdbits_ppc (envp, _FPU_MASK_NOT_RN_NI, 0LL);
Packit Service 562438
}
Packit Service 562438
Packit Service 562438
static __always_inline void
Packit Service 562438
libc_feholdexcept_setround_ppc (fenv_t *envp, int r)
Packit Service 562438
{
Packit Service 562438
  __libc_feholdbits_ppc (envp, _FPU_MASK_NOT_RN_NI & _FPU_MASK_RN, r);
Packit Service 562438
}
Packit Service 562438
Packit Service 562438
static __always_inline void
Packit Service 562438
libc_fesetround_ppc (int r)
Packit Service 562438
{
Packit Service 562438
  __fesetround_inline (r);
Packit Service 562438
}
Packit Service 562438
Packit Service 562438
static __always_inline int
Packit Service 562438
libc_fetestexcept_ppc (int e)
Packit Service 562438
{
Packit Service 562438
  fenv_union_t u;
Packit Service 562438
  u.fenv = fegetenv_register ();
Packit Service 562438
  return u.l & e;
Packit Service 562438
}
Packit Service 562438
Packit Service 562438
static __always_inline void
Packit Service 562438
libc_feholdsetround_ppc (fenv_t *e, int r)
Packit Service 562438
{
Packit Service 562438
  __libc_feholdbits_ppc (e, _FPU_MASK_TRAPS_RN, r);
Packit Service 562438
}
Packit Service 562438
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 562438
  /* If the old env has no enabled exceptions and the new env has any enabled
Packit Service 562438
     exceptions, then unmask SIGFPE in the MSR FE0/FE1 bits.  This will put the
Packit Service 562438
     hardware into "precise mode" and may cause the FPU to run slower on some
Packit Service 562438
     hardware.  */
Packit Service 562438
  if ((old.l & _FPU_ALL_TRAPS) == 0 && (new.l & _FPU_ALL_TRAPS) != 0)
Packit Service 562438
    (void) __fe_nomask_env_priv ();
Packit Service 562438
Packit Service 562438
  /* If the old env had any enabled exceptions and the new env has no enabled
Packit Service 562438
     exceptions, then mask SIGFPE in the MSR FE0/FE1 bits.  This may allow the
Packit Service 562438
     FPU to run faster because it always takes the default action and can not
Packit Service 562438
     generate SIGFPE.  */
Packit Service 562438
  if ((old.l & _FPU_ALL_TRAPS) != 0 && (new.l & _FPU_ALL_TRAPS) == 0)
Packit Service 562438
    (void) __fe_mask_env ();
Packit Service 562438
Packit Service 562438
  /* Atomically enable and raise (if appropriate) exceptions set in `new'.  */
Packit Service 562438
  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 f43397
  fenv_union_t new = { .fenv = *envp };
Packit Service f43397
Packit Service f43397
  /* If the old env has no enabled exceptions and the new env has any enabled
Packit Service f43397
     exceptions, then unmask SIGFPE in the MSR FE0/FE1 bits.  This will put the
Packit Service f43397
     hardware into "precise mode" and may cause the FPU to run slower on some
Packit Service f43397
     hardware.  */
Packit Service f43397
  if ((new.l & _FPU_ALL_TRAPS) != 0)
Packit Service f43397
    (void) __fe_nomask_env_priv ();
Packit Service f43397
Packit Service f43397
  /* Atomically enable and raise (if appropriate) exceptions set in `new'.  */
Packit Service f43397
  fesetenv_mode (new.fenv);
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 562438
  return __libc_femergeenv_ppc (envp, _FPU_MASK_TRAPS_RN,
Packit Service 562438
				_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 5529a0
  fenv_union_t old, new;
Packit Service 5529a0
Packit Service f43397
  old.fenv = fegetenv_status ();
Packit Service f43397
Packit Service f43397
  new.l = (old.l & ~(FPSCR_ENABLES_MASK|FPSCR_RN_MASK)) | r;
Packit Service f43397
Packit Service f43397
  ctx->env = old.fenv;
Packit Service f43397
  if (__glibc_unlikely (new.l != old.l))
Packit Service f43397
    {
Packit Service f43397
      if ((old.l & _FPU_ALL_TRAPS) != 0)
Packit Service f43397
	(void) __fe_mask_env ();
Packit Service f43397
      fesetenv_mode (new.fenv);
Packit Service f43397
      ctx->updated_status = true;
Packit Service f43397
    }
Packit Service f43397
  else
Packit Service f43397
    ctx->updated_status = false;
Packit Service f43397
}
Packit Service f43397
Packit Service f43397
static __always_inline void
Packit Service f43397
libc_feholdsetround_noex_ppc_ctx (struct rm_ctx *ctx, int r)
Packit Service f43397
{
Packit Service f43397
  fenv_union_t old, new;
Packit Service f43397
Packit 6c4009
  old.fenv = fegetenv_register ();
Packit 6c4009
Packit Service f43397
  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 562438
      if ((old.l & _FPU_ALL_TRAPS) != 0)
Packit Service 562438
	(void) __fe_mask_env ();
Packit Service 562438
      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 f43397
#define libc_feholdsetround_noex_ctx     libc_feholdsetround_noex_ppc_ctx
Packit Service f43397
#define libc_feholdsetround_noexf_ctx    libc_feholdsetround_noex_ppc_ctx
Packit Service f43397
#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