about summary refs log tree commit diff
path: root/src/math/nearbyintl.c
diff options
context:
space:
mode:
authornsz <nsz@port70.net>2012-03-20 22:49:19 +0100
committernsz <nsz@port70.net>2012-03-20 22:49:19 +0100
commit91c28f61f43ba029166772e8ac25808ea3c3dc98 (patch)
treea9993bc53514ade564171678339a14470864d8e1 /src/math/nearbyintl.c
parent8c6fc860a97f79146bf5c092d5cfb90fa6d9355a (diff)
downloadmusl-91c28f61f43ba029166772e8ac25808ea3c3dc98.tar.gz
musl-91c28f61f43ba029166772e8ac25808ea3c3dc98.tar.xz
musl-91c28f61f43ba029166772e8ac25808ea3c3dc98.zip
nearbyint optimization (only clear inexact when necessary)
old code saved/restored the fenv (the new code is only as slow
as that when inexact is not set before the call, but some other
flag is set and the rounding is inexact, which is rare)

before:
bench_nearbyint_exact              5000000 N        261 ns/op
bench_nearbyint_inexact_set        5000000 N        262 ns/op
bench_nearbyint_inexact_unset      5000000 N        261 ns/op

after:
bench_nearbyint_exact             10000000 N         94.99 ns/op
bench_nearbyint_inexact_set       25000000 N         65.81 ns/op
bench_nearbyint_inexact_unset     10000000 N         94.97 ns/op
Diffstat (limited to 'src/math/nearbyintl.c')
-rw-r--r--src/math/nearbyintl.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/math/nearbyintl.c b/src/math/nearbyintl.c
index 2906f383..0ff4b1f9 100644
--- a/src/math/nearbyintl.c
+++ b/src/math/nearbyintl.c
@@ -10,11 +10,16 @@ long double nearbyintl(long double x)
 #include <fenv.h>
 long double nearbyintl(long double x)
 {
-	fenv_t e;
+#ifdef FE_INEXACT
+	int e;
 
-	fegetenv(&e);
+	e = fetestexcept(FE_INEXACT);
+#endif
 	x = rintl(x);
-	fesetenv(&e);
+#ifdef FE_INEXACT
+	if (!e)
+		feclearexcept(FE_INEXACT);
+#endif
 	return x;
 }
 #endif