bca718
commit bc93ab2946efe008bb0ce2d4d3c212bd01384fca
bca718
Author: Ian Bolton <ian.bolton@arm.com>
bca718
Date:   Wed Apr 16 23:41:04 2014 +0100
bca718
bca718
    [AArch64] Define HAVE_RM_CTX and related hooks.
bca718
bca718
diff --git a/ports/sysdeps/aarch64/fpu/math_private.h b/ports/sysdeps/aarch64/fpu/math_private.h
bca718
index dbf203d..7424952 100644
bca718
--- a/ports/sysdeps/aarch64/fpu/math_private.h
bca718
+++ b/ports/sysdeps/aarch64/fpu/math_private.h
bca718
@@ -209,6 +209,61 @@ libc_feresetround_aarch64 (fenv_t *envp)
bca718
 #define libc_feresetroundf libc_feresetround_aarch64
bca718
 #define libc_feresetroundl libc_feresetround_aarch64
bca718
 
bca718
+/* We have support for rounding mode context.  */
bca718
+#define HAVE_RM_CTX 1
bca718
+
bca718
+static __always_inline void
bca718
+libc_feholdsetround_aarch64_ctx (struct rm_ctx *ctx, int r)
bca718
+{
bca718
+  fpu_control_t fpcr, fpsr, round;
bca718
+
bca718
+  _FPU_GETCW (fpcr);
bca718
+  _FPU_GETFPSR (fpsr);
bca718
+  ctx->env.__fpsr = fpsr;
bca718
+
bca718
+  /* Check whether rounding modes are different.  */
bca718
+  round = (fpcr ^ r) & FE_TOWARDZERO;
bca718
+  ctx->updated_status = round != 0;
bca718
+
bca718
+  /* Set the rounding mode if changed.  */
bca718
+  if (__glibc_unlikely (round != 0))
bca718
+    {
bca718
+      ctx->env.__fpcr = fpcr;
bca718
+      _FPU_SETCW (fpcr ^ round);
bca718
+    }
bca718
+}
bca718
+
bca718
+#define libc_feholdsetround_ctx		libc_feholdsetround_aarch64_ctx
bca718
+#define libc_feholdsetroundf_ctx	libc_feholdsetround_aarch64_ctx
bca718
+#define libc_feholdsetroundl_ctx	libc_feholdsetround_aarch64_ctx
bca718
+
bca718
+static __always_inline void
bca718
+libc_feresetround_aarch64_ctx (struct rm_ctx *ctx)
bca718
+{
bca718
+  /* Restore the rounding mode if updated.  */
bca718
+  if (__glibc_unlikely (ctx->updated_status))
bca718
+    _FPU_SETCW (ctx->env.__fpcr);
bca718
+}
bca718
+
bca718
+#define libc_feresetround_ctx		libc_feresetround_aarch64_ctx
bca718
+#define libc_feresetroundf_ctx		libc_feresetround_aarch64_ctx
bca718
+#define libc_feresetroundl_ctx		libc_feresetround_aarch64_ctx
bca718
+
bca718
+static __always_inline void
bca718
+libc_feresetround_noex_aarch64_ctx (struct rm_ctx *ctx)
bca718
+{
bca718
+  /* Restore the rounding mode if updated.  */
bca718
+  if (__glibc_unlikely (ctx->updated_status))
bca718
+    _FPU_SETCW (ctx->env.__fpcr);
bca718
+
bca718
+  /* Write new FPSR to restore exception flags.  */
bca718
+  _FPU_SETFPSR (ctx->env.__fpsr);
bca718
+}
bca718
+
bca718
+#define libc_feresetround_noex_ctx	libc_feresetround_noex_aarch64_ctx
bca718
+#define libc_feresetround_noexf_ctx	libc_feresetround_noex_aarch64_ctx
bca718
+#define libc_feresetround_noexl_ctx	libc_feresetround_noex_aarch64_ctx
bca718
+
bca718
 #include_next <math_private.h>
bca718
 
bca718
 #endif