diff options
author | bde <bde@FreeBSD.org> | 2008-02-13 10:44:44 +0000 |
---|---|---|
committer | bde <bde@FreeBSD.org> | 2008-02-13 10:44:44 +0000 |
commit | 517ddcfb705fb05303e965a0ef145cd38070db7e (patch) | |
tree | 66b2e8b635ba79677613ae3e7403b5b7a57cda62 | |
parent | cafbfde84b3c94ce73c4639e9106f7f8d3e729db (diff) | |
download | FreeBSD-src-517ddcfb705fb05303e965a0ef145cd38070db7e.zip FreeBSD-src-517ddcfb705fb05303e965a0ef145cd38070db7e.tar.gz |
Fix exp2*(x) on signaling NaNs by returning x+x as usual.
This has the side effect of confusing gcc-4.2.1's optimizer into more
often doing the right thing. When it does the wrong thing here, it
seems to be mainly making too many copies of x with dependency chains.
This effect is tiny on amd64, but in some cases on i386 it is enormous.
E.g., on i386 (A64) with -O1, the current version of exp2() should
take about 50 cycles, but took 83 cycles before this change and 66
cycles after this change. exp2f() with -O1 only speeded up from 51
to 47 cycles. (exp2f() should take about 40 cycles, on an Athlon in
either i386 or amd64 mode, and now takes 42 on amd64). exp2l() with
-O1 slowed down from 155 cycles to 123 for some args; this is unimportant
since the i386 exp2l() is a fake; the wrong thing for it seems to
involve branch misprediction.
-rw-r--r-- | lib/msun/ld128/s_exp2l.c | 2 | ||||
-rw-r--r-- | lib/msun/ld80/s_exp2l.c | 2 | ||||
-rw-r--r-- | lib/msun/src/s_exp2.c | 2 | ||||
-rw-r--r-- | lib/msun/src/s_exp2f.c | 2 |
4 files changed, 4 insertions, 4 deletions
diff --git a/lib/msun/ld128/s_exp2l.c b/lib/msun/ld128/s_exp2l.c index a94b892..31178e4 100644 --- a/lib/msun/ld128/s_exp2l.c +++ b/lib/msun/ld128/s_exp2l.c @@ -371,7 +371,7 @@ exp2l(long double x) if (u.xbits.manh != 0 || u.xbits.manl != 0 || (hx & 0x8000) == 0) - return (x); /* x is NaN or +Inf */ + return (x + x); /* x is NaN or +Inf */ else return (0.0); /* x is -Inf */ } diff --git a/lib/msun/ld80/s_exp2l.c b/lib/msun/ld80/s_exp2l.c index 8a0dbe2..14dfc1d 100644 --- a/lib/msun/ld80/s_exp2l.c +++ b/lib/msun/ld80/s_exp2l.c @@ -226,7 +226,7 @@ exp2l(long double x) if (ix >= BIAS + 14) { /* |x| >= 16384 or x is NaN */ if (ix == BIAS + LDBL_MAX_EXP) { if (u.xbits.man != 1ULL << 63 || (hx & 0x8000) == 0) - return (x); /* x is NaN or +Inf */ + return (x + x); /* x is +Inf or NaN */ else return (0.0); /* x is -Inf */ } diff --git a/lib/msun/src/s_exp2.c b/lib/msun/src/s_exp2.c index 63b8997..c46750f 100644 --- a/lib/msun/src/s_exp2.c +++ b/lib/msun/src/s_exp2.c @@ -351,7 +351,7 @@ exp2(double x) if(ix >= 0x7ff00000) { GET_LOW_WORD(lx,x); if(((ix & 0xfffff) | lx) != 0 || (hx & 0x80000000) == 0) - return (x); /* x is NaN or +Inf */ + return (x + x); /* x is NaN or +Inf */ else return (0.0); /* x is -Inf */ } diff --git a/lib/msun/src/s_exp2f.c b/lib/msun/src/s_exp2f.c index 1b9299f..43da2f6 100644 --- a/lib/msun/src/s_exp2f.c +++ b/lib/msun/src/s_exp2f.c @@ -104,7 +104,7 @@ exp2f(float x) if(ix >= 0x43000000) { /* |x| >= 128 */ if(ix >= 0x7f800000) { if ((ix & 0x7fffff) != 0 || (hx & 0x80000000) == 0) - return (x); /* x is NaN or +Inf */ + return (x + x); /* x is NaN or +Inf */ else return (0.0); /* x is -Inf */ } |