ce426f
commit 7e0b6763e96ef9706ea9ecc7fad83fc97b837913
ce426f
Author: Ian Bolton <ian.bolton@arm.com>
ce426f
Date:   Wed Apr 16 14:41:52 2014 +0000
ce426f
ce426f
    [AArch64] Provide initial implementation of math_private.h.
ce426f
ce426f
diff --git a/ports/sysdeps/aarch64/fpu/math_private.h b/ports/sysdeps/aarch64/fpu/math_private.h
ce426f
new file mode 100644
ce426f
index 0000000..dbf203d
ce426f
--- /dev/null
ce426f
+++ b/ports/sysdeps/aarch64/fpu/math_private.h
ce426f
@@ -0,0 +1,214 @@
ce426f
+/* Private floating point rounding and exceptions handling.  AArch64 version.
ce426f
+   Copyright (C) 2014 Free Software Foundation, Inc.
ce426f
+   This file is part of the GNU C Library.
ce426f
+
ce426f
+   The GNU C Library is free software; you can redistribute it and/or
ce426f
+   modify it under the terms of the GNU Lesser General Public
ce426f
+   License as published by the Free Software Foundation; either
ce426f
+   version 2.1 of the License, or (at your option) any later version.
ce426f
+
ce426f
+   The GNU C Library is distributed in the hope that it will be useful,
ce426f
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
ce426f
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
ce426f
+   Lesser General Public License for more details.
ce426f
+
ce426f
+   You should have received a copy of the GNU Lesser General Public
ce426f
+   License along with the GNU C Library; if not, see
ce426f
+   <http://www.gnu.org/licenses/>.  */
ce426f
+
ce426f
+#ifndef AARCH64_MATH_PRIVATE_H
ce426f
+#define AARCH64_MATH_PRIVATE_H 1
ce426f
+
ce426f
+#include <fenv.h>
ce426f
+#include <fpu_control.h>
ce426f
+
ce426f
+static __always_inline void
ce426f
+libc_feholdexcept_aarch64 (fenv_t *envp)
ce426f
+{
ce426f
+  fpu_control_t fpcr, new_fpcr, fpsr, new_fpsr;
ce426f
+
ce426f
+  _FPU_GETCW (fpcr);
ce426f
+  _FPU_GETFPSR (fpsr);
ce426f
+  envp->__fpcr = fpcr;
ce426f
+  envp->__fpsr = fpsr;
ce426f
+
ce426f
+  /* Clear exception flags and set all exceptions to non-stop.  */
ce426f
+  new_fpcr = fpcr & ~(FE_ALL_EXCEPT << FE_EXCEPT_SHIFT);
ce426f
+  new_fpsr = fpsr & ~FE_ALL_EXCEPT;
ce426f
+
ce426f
+  if (__glibc_unlikely (new_fpcr != fpcr))
ce426f
+    _FPU_SETCW (new_fpcr);
ce426f
+
ce426f
+  if (new_fpsr != fpsr)
ce426f
+    _FPU_SETFPSR (new_fpsr);
ce426f
+}
ce426f
+
ce426f
+#define libc_feholdexcept  libc_feholdexcept_aarch64
ce426f
+#define libc_feholdexceptf libc_feholdexcept_aarch64
ce426f
+#define libc_feholdexceptl libc_feholdexcept_aarch64
ce426f
+
ce426f
+static __always_inline void
ce426f
+libc_fesetround_aarch64 (int round)
ce426f
+{
ce426f
+  fpu_control_t fpcr;
ce426f
+
ce426f
+  _FPU_GETCW (fpcr);
ce426f
+
ce426f
+  /* Check whether rounding modes are different.  */
ce426f
+  round = (fpcr ^ round) & FE_TOWARDZERO;
ce426f
+
ce426f
+  /* Set new rounding mode if different.  */
ce426f
+  if (__glibc_unlikely (round != 0))
ce426f
+    _FPU_SETCW (fpcr ^ round);
ce426f
+}
ce426f
+
ce426f
+#define libc_fesetround  libc_fesetround_aarch64
ce426f
+#define libc_fesetroundf libc_fesetround_aarch64
ce426f
+#define libc_fesetroundl libc_fesetround_aarch64
ce426f
+
ce426f
+static __always_inline void
ce426f
+libc_feholdexcept_setround_aarch64 (fenv_t *envp, int round)
ce426f
+{
ce426f
+  fpu_control_t fpcr, new_fpcr, fpsr, new_fpsr;
ce426f
+
ce426f
+  _FPU_GETCW (fpcr);
ce426f
+  _FPU_GETFPSR (fpsr);
ce426f
+  envp->__fpcr = fpcr;
ce426f
+  envp->__fpsr = fpsr;
ce426f
+
ce426f
+  /* Clear exception flags, set all exceptions to non-stop,
ce426f
+     and set new rounding mode.  */
ce426f
+  new_fpcr = fpcr & ~((FE_ALL_EXCEPT << FE_EXCEPT_SHIFT) | FE_TOWARDZERO);
ce426f
+  new_fpcr |= round;
ce426f
+  new_fpsr = fpsr & ~FE_ALL_EXCEPT;
ce426f
+
ce426f
+  if (__glibc_unlikely (new_fpcr != fpcr))
ce426f
+    _FPU_SETCW (new_fpcr);
ce426f
+
ce426f
+  if (new_fpsr != fpsr)
ce426f
+    _FPU_SETFPSR (new_fpsr);
ce426f
+}
ce426f
+
ce426f
+#define libc_feholdexcept_setround  libc_feholdexcept_setround_aarch64
ce426f
+#define libc_feholdexcept_setroundf libc_feholdexcept_setround_aarch64
ce426f
+#define libc_feholdexcept_setroundl libc_feholdexcept_setround_aarch64
ce426f
+
ce426f
+static __always_inline int
ce426f
+libc_fetestexcept_aarch64 (int ex)
ce426f
+{
ce426f
+  fpu_control_t fpsr;
ce426f
+
ce426f
+  _FPU_GETFPSR (fpsr);
ce426f
+  return fpsr & ex & FE_ALL_EXCEPT;
ce426f
+}
ce426f
+
ce426f
+#define libc_fetestexcept  libc_fetestexcept_aarch64
ce426f
+#define libc_fetestexceptf libc_fetestexcept_aarch64
ce426f
+#define libc_fetestexceptl libc_fetestexcept_aarch64
ce426f
+
ce426f
+static __always_inline void
ce426f
+libc_fesetenv_aarch64 (const fenv_t *envp)
ce426f
+{
ce426f
+  fpu_control_t fpcr, new_fpcr;
ce426f
+
ce426f
+  _FPU_GETCW (fpcr);
ce426f
+  new_fpcr = envp->__fpcr;
ce426f
+
ce426f
+  if (__glibc_unlikely (fpcr != new_fpcr))
ce426f
+    _FPU_SETCW (new_fpcr);
ce426f
+
ce426f
+  _FPU_SETFPSR (envp->__fpsr);
ce426f
+}
ce426f
+
ce426f
+#define libc_fesetenv  libc_fesetenv_aarch64
ce426f
+#define libc_fesetenvf libc_fesetenv_aarch64
ce426f
+#define libc_fesetenvl libc_fesetenv_aarch64
ce426f
+#define libc_feresetround_noex  libc_fesetenv_aarch64
ce426f
+#define libc_feresetround_noexf libc_fesetenv_aarch64
ce426f
+#define libc_feresetround_noexl libc_fesetenv_aarch64
ce426f
+
ce426f
+static __always_inline int
ce426f
+libc_feupdateenv_test_aarch64 (const fenv_t *envp, int ex)
ce426f
+{
ce426f
+  fpu_control_t fpcr, new_fpcr, fpsr, new_fpsr;
ce426f
+  int excepts;
ce426f
+
ce426f
+  _FPU_GETCW (fpcr);
ce426f
+  _FPU_GETFPSR (fpsr);
ce426f
+
ce426f
+  /* Merge current exception flags with the saved fenv.  */
ce426f
+  excepts = fpsr & FE_ALL_EXCEPT;
ce426f
+  new_fpcr = envp->__fpcr;
ce426f
+  new_fpsr = envp->__fpsr | excepts;
ce426f
+
ce426f
+  if (__glibc_unlikely (fpcr != new_fpcr))
ce426f
+    _FPU_SETCW (new_fpcr);
ce426f
+
ce426f
+  if (fpsr != new_fpsr)
ce426f
+    _FPU_SETFPSR (new_fpsr);
ce426f
+
ce426f
+  /* Raise the exceptions if enabled in the new FP state.  */
ce426f
+  if (__glibc_unlikely (excepts & (new_fpcr >> FE_EXCEPT_SHIFT)))
ce426f
+    feraiseexcept (excepts);
ce426f
+
ce426f
+  return excepts & ex;
ce426f
+}
ce426f
+
ce426f
+#define libc_feupdateenv_test  libc_feupdateenv_test_aarch64
ce426f
+#define libc_feupdateenv_testf libc_feupdateenv_test_aarch64
ce426f
+#define libc_feupdateenv_testl libc_feupdateenv_test_aarch64
ce426f
+
ce426f
+static __always_inline void
ce426f
+libc_feupdateenv_aarch64 (const fenv_t *envp)
ce426f
+{
ce426f
+  libc_feupdateenv_test_aarch64 (envp, 0);
ce426f
+}
ce426f
+
ce426f
+#define libc_feupdateenv  libc_feupdateenv_aarch64
ce426f
+#define libc_feupdateenvf libc_feupdateenv_aarch64
ce426f
+#define libc_feupdateenvl libc_feupdateenv_aarch64
ce426f
+
ce426f
+static __always_inline void
ce426f
+libc_feholdsetround_aarch64 (fenv_t *envp, int round)
ce426f
+{
ce426f
+  fpu_control_t fpcr, fpsr;
ce426f
+
ce426f
+  _FPU_GETCW (fpcr);
ce426f
+  _FPU_GETFPSR (fpsr);
ce426f
+  envp->__fpcr = fpcr;
ce426f
+  envp->__fpsr = fpsr;
ce426f
+
ce426f
+  /* Check whether rounding modes are different.  */
ce426f
+  round = (fpcr ^ round) & FE_TOWARDZERO;
ce426f
+
ce426f
+  /* Set new rounding mode if different.  */
ce426f
+  if (__glibc_unlikely (round != 0))
ce426f
+    _FPU_SETCW (fpcr ^ round);
ce426f
+}
ce426f
+
ce426f
+#define libc_feholdsetround  libc_feholdsetround_aarch64
ce426f
+#define libc_feholdsetroundf libc_feholdsetround_aarch64
ce426f
+#define libc_feholdsetroundl libc_feholdsetround_aarch64
ce426f
+
ce426f
+static __always_inline void
ce426f
+libc_feresetround_aarch64 (fenv_t *envp)
ce426f
+{
ce426f
+  fpu_control_t fpcr, round;
ce426f
+
ce426f
+  _FPU_GETCW (fpcr);
ce426f
+
ce426f
+  /* Check whether rounding modes are different.  */
ce426f
+  round = (envp->__fpcr ^ fpcr) & FE_TOWARDZERO;
ce426f
+
ce426f
+  /* Restore the rounding mode if it was changed.  */
ce426f
+  if (__glibc_unlikely (round != 0))
ce426f
+    _FPU_SETCW (fpcr ^ round);
ce426f
+}
ce426f
+
ce426f
+#define libc_feresetround  libc_feresetround_aarch64
ce426f
+#define libc_feresetroundf libc_feresetround_aarch64
ce426f
+#define libc_feresetroundl libc_feresetround_aarch64
ce426f
+
ce426f
+#include_next <math_private.h>
ce426f
+
ce426f
+#endif