From fff23f74e52f1cc59317c194e844aa826a516608 Mon Sep 17 00:00:00 2001 From: Taylor R Campbell Date: Wed, 23 Jan 2019 07:50:38 +0000 Subject: [PATCH] Check at runtime whether feenableexcept does anything. The bits are defined on aarch64, but apparently some CPUs are fabricated without support for them so they just read back as zers. Bummer! --- src/microcode/floenv.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/microcode/floenv.c b/src/microcode/floenv.c index 82e0f49dc..2672996d3 100644 --- a/src/microcode/floenv.c +++ b/src/microcode/floenv.c @@ -594,7 +594,22 @@ DEFINE_PRIMITIVE ("HAVE-FLOAT-TRAP-ENABLE/DISABLE?", Prim_have_float_trap_enable { PRIMITIVE_HEADER (0); #if ((defined (HAVE_FEENABLEEXCEPT)) && (defined (HAVE_FEDISABLEEXCEPT))) - PRIMITIVE_RETURN (SHARP_T); + static int have = -1; + if (have == -1) + { + fenv_t fenv; + int excepts = (fegetexcept ()); + /* Prevent traps while we futz with stuff. */ + feholdexcept (&fenv); + /* Reverse the sense. */ + feenableexcept (FE_ALL_EXCEPT &~ excepts); + fedisableexcept (excepts); + /* Check whether that had any effect. */ + have = ((fegetexcept ()) != excepts); + /* Restore the environment without raising exceptions. */ + fesetenv (&fenv); + } + PRIMITIVE_RETURN (have ? SHARP_T : SHARP_F); #else PRIMITIVE_RETURN (SHARP_F); #endif -- 2.25.1