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