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 6c4009
static __always_inline void
Packit Service 4d6756
libc_feholdexcept_setround_ppc (fenv_t *envp, int r)
Packit 6c4009
{
Packit 6c4009
  fenv_union_t old, new;
Packit 6c4009
Packit 6c4009
  old.fenv = *envp = fegetenv_register ();
Packit 6c4009
Packit Service 4d6756
  __TEST_AND_ENTER_NON_STOP (old.l, 0ULL);
Packit 6c4009
Packit Service 4d6756
  /* Clear everything and set the rounding mode.  */
Packit Service 4d6756
  new.l = r;
Packit 6c4009
  fesetenv_register (new.fenv);
Packit 6c4009
}
Packit 6c4009
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 4d6756
  __TEST_AND_EXIT_NON_STOP (old.l, new.l);
Packit Service 4d6756
  __TEST_AND_ENTER_NON_STOP (old.l, new.l);
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 9fd2e4
  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 4d6756
  return __libc_femergeenv_ppc (envp, ~FPSCR_CONTROL_MASK,
Packit Service 4d6756
				~FPSCR_STATUS_MASK) & 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 9fd2e4
  fenv_union_t old;
Packit Service 5529a0
Packit Service 9fd2e4
  ctx->env = old.fenv = fegetenv_and_set_rn (r);
Packit Service 9fd2e4
  ctx->updated_status = (r != (old.l & FPSCR_RN_MASK));
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 4d6756
      __TEST_AND_ENTER_NON_STOP (old.l, 0ULL);
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