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