-
Notifications
You must be signed in to change notification settings - Fork 88
Finish repairing the deferred KxQ rebuild, and pin the estimator constants #522
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
25583e9
Finish repairing the deferred KxQ rebuild, and pin the estimator cons…
leerho dbf2947
Merge branch 'master' into hll-kxq-rebuild-parity
leerho 0d954d6
Exclude fdlibm_log.hpp from RAT and date the deprecated alias
leerho 27e096a
Treat .sk sketch fixtures as binary, not text
leerho File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| // fdlibm __ieee754_log, used by Java's StrictMath.log (and by Math.log on most JVMs). | ||
| // Derived from FDLIBM 5.3, Copyright (C) 1993 by Sun Microsystems, Inc. | ||
| // "Permission to use, copy, modify, and distribute this software is freely granted, | ||
| // provided that this notice is preserved." | ||
| #ifndef FDLIBM_LOG_HPP | ||
| #define FDLIBM_LOG_HPP | ||
| #include <cstdint> | ||
| #include <cstring> | ||
| #include <limits> | ||
|
|
||
| namespace fdlibm { | ||
|
|
||
| inline int32_t hi_word(double x){ uint64_t u; std::memcpy(&u,&x,8); return (int32_t)(uint32_t)(u>>32); } | ||
| inline uint32_t lo_word(double x){ uint64_t u; std::memcpy(&u,&x,8); return (uint32_t)u; } | ||
| inline void set_hi_word(double& x, uint32_t hi){ uint64_t u; std::memcpy(&u,&x,8); | ||
| u = (u & 0x00000000ffffffffULL) | ((uint64_t)hi<<32); std::memcpy(&x,&u,8); } | ||
|
|
||
| // Forces a value to be rounded to a double before it is used again. fdlibm needs strict | ||
| // IEEE-754 evaluation: a fused multiply-add anywhere in the polynomial below changes the | ||
| // result. Pragmas are overridden by an explicit -ffp-contract=fast, so use a volatile | ||
| // round-trip, which the standard requires the compiler to honour. | ||
| inline double rnd(double v) { volatile double t = v; return t; } | ||
|
|
||
| inline double log(double x) { | ||
| // fdlibm depends on strict IEEE-754 evaluation: a fused multiply-add would change the result | ||
| // of the polynomial evaluation below, so contraction must be off for this function. | ||
| #if defined(__clang__) | ||
| #pragma clang fp contract(off) | ||
| #endif | ||
| static const double | ||
| ln2_hi = 6.93147180369123816490e-01, /* 3fe62e42 fee00000 */ | ||
| ln2_lo = 1.90821492927058770002e-10, /* 3dea39ef 35793c76 */ | ||
| two54 = 1.80143985094819840000e+16, /* 43500000 00000000 */ | ||
| Lg1 = 6.666666666666735130e-01, /* 3FE55555 55555593 */ | ||
| Lg2 = 3.999999999940941908e-01, /* 3FD99999 9997FA04 */ | ||
| Lg3 = 2.857142874366239149e-01, /* 3FD24924 94229359 */ | ||
| Lg4 = 2.222219843214978396e-01, /* 3FCC71C5 1D8E78AF */ | ||
| Lg5 = 1.818357216161805012e-01, /* 3FC74664 96CB03DE */ | ||
| Lg6 = 1.531383769920937332e-01, /* 3FC39A09 D078C69F */ | ||
| Lg7 = 1.479819860511658591e-01, /* 3FC2F112 DF3E5244 */ | ||
| zero = 0.0; | ||
|
|
||
| double hfsq,f,s,z,R,w,t1,t2,dk; | ||
| int32_t k,hx,i,j; | ||
| uint32_t lx; | ||
|
|
||
| hx = hi_word(x); | ||
| lx = lo_word(x); | ||
|
|
||
| k = 0; | ||
| if (hx < 0x00100000) { /* x < 2**-1022 */ | ||
| // fdlibm writes these as -two54/zero and (x-x)/zero, which also raise the divide-by-zero | ||
| // and invalid flags. MSVC rejects a compile-time division by a zero constant (C2124), so | ||
| // return the same values directly. The estimators never call log() with these inputs. | ||
| if (((hx & 0x7fffffff) | lx) == 0) { /* log(+-0) = -inf */ | ||
| return -std::numeric_limits<double>::infinity(); | ||
| } | ||
| if (hx < 0) { /* log(-#) = NaN */ | ||
| return std::numeric_limits<double>::quiet_NaN(); | ||
| } | ||
| k -= 54; x *= two54; /* subnormal: scale up */ | ||
| hx = hi_word(x); | ||
| } | ||
| if (hx >= 0x7ff00000) { return x+x; } | ||
| k += (hx>>20) - 1023; | ||
| hx &= 0x000fffff; | ||
| i = (hx + 0x95f64) & 0x100000; | ||
| set_hi_word(x, (uint32_t)(hx | (i ^ 0x3ff00000))); /* normalize x or x/2 */ | ||
| k += (i>>20); | ||
| f = x - 1.0; | ||
| if ((0x000fffff & (2+hx)) < 3) { /* |f| < 2**-20 */ | ||
| if (f == zero) { | ||
| if (k == 0) { return zero; } | ||
| dk = (double)k; return rnd(dk*ln2_hi) + rnd(dk*ln2_lo); | ||
| } | ||
| R = rnd(rnd(f*f)*rnd(0.5 - rnd(0.33333333333333333*f))); | ||
| if (k == 0) { return f-R; } | ||
| dk = (double)k; return rnd(dk*ln2_hi) - (rnd(R - rnd(dk*ln2_lo)) - f); | ||
| } | ||
| s = f/(2.0+f); | ||
| dk = (double)k; | ||
| z = s*s; | ||
| i = hx - 0x6147a; | ||
| w = z*z; | ||
| j = 0x6b851 - hx; | ||
| t1 = rnd(w*rnd(Lg2 + rnd(w*rnd(Lg4 + rnd(w*Lg6))))); | ||
| t2 = rnd(z*rnd(Lg1 + rnd(w*rnd(Lg3 + rnd(w*rnd(Lg5 + rnd(w*Lg7))))))); | ||
| i |= j; | ||
| R = t2 + t1; | ||
| if (i > 0) { | ||
| hfsq = rnd(0.5*f)*f; | ||
| if (k == 0) { return f - rnd(hfsq - rnd(s*(hfsq+R))); } | ||
| return rnd(dk*ln2_hi) - (rnd(hfsq - rnd(rnd(s*(hfsq+R)) + rnd(dk*ln2_lo))) - f); | ||
| } else { | ||
| if (k == 0) { return f - rnd(s*(f-R)); } | ||
| return rnd(dk*ln2_hi) - (rnd(rnd(s*(f-R)) - rnd(dk*ln2_lo)) - f); | ||
| } | ||
| } | ||
|
|
||
| } // namespace fdlibm | ||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like previous PR, how do you think introducing new const and deprecation instead of renaming?
after next release, remove it.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@proost,
What you see in this diff is stale, and that's on me — #522 is stacked on the pre-fix commit of #521 and hasn't been brought up to date with master yet, so the file view still shows the old state. What you don't see is the change made in #521, which addressed this same comment. On master today:
I'll merge master into this branch and it will drop out of the view.
On removal: with C++11 there's no [[deprecated]], so the alias warns nobody — it's purely a source-compatibility placeholder. Rather than name a version we can't predict yet, I'll record the date and PR in the comment itself so it can be traced to whatever release follows. Intent is to drop it one release after it ships. It will look something like this: