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