On Thu, 15 Apr 2021 08:33:47 GMT, gregcawthorne <github.com+73799211+gregcawtho...@openjdk.org> wrote:
> Glibc 2.29 onwards provides optimised versions of log,log10,exp. > These functions have an accuracy of 0.9ulp or better in glibc > 2.29. > > Therefore this patch adds code to parse, store and check > the runtime glibcs version in os_linux.cpp/hpp. > This is then used to select the glibcs implementation of > log, log10, exp at runtime for c1 and c2, iff we have > glibc 2.29 or greater. > > This will ensure OpenJDK can benefit from future improvements > to glibc. > > Glibc adheres to the ieee754 standard, unless stated otherwise > in its spec. > > As there are no stated exceptions in the current glibc spec > for dlog, dlog10 and dexp, we can assume they currently follow > ieee754 (which testing confirms). As such, future version of > glibc are unlikely to lose this compliance with ieee754 in > future. > > W.r.t performance this patch sees ~15-30% performance improvements for > log and log10, with ~50-80% performance improvements for exp for the > common input ranged (which output real numbers). However for the NaN > and inf output ranges we see a slow down of up to a factor of 2 for > some functions and architectures. > > Due to this being the uncommon case we assert that this is a > worthwhile tradeoff. > [ One thing: Java uses the term "semi-monotonic" to > mean "whenever the mathematical function is non-decreasing, so is > the floating-point approximation, likewise, whenever the > mathematical function is non-increasing, so is the floating-point > approximation." I don't really understand what distinction means. ] I believe this is to allow for the fact that the function is continuous and the floating-point approximation is discrete. Let F be the actual function and f the floating point approximation. Assume we have two successive floating point values x, x' and, without loss of generality, F(x) <= F(x'). What are the circumstances under which we require f(x) =< f(x')? Semi-monotonicity says that is only needed when F is non-decreasing on the interval [x, x']. Expressed more precisely, the condition that F is non-decreasing is for all y such that x =< y =< x' : F(x) <= F(y) <= F(x'). In other words: if the graph only ever stays level or increases across the interval [x, x'] then we must have f(x) =< f(x') If the graph wiggles *up* and *down* across the interval [x, x'] we can allow f(x) > f(x'). ------------- PR: https://git.openjdk.java.net/jdk/pull/3510