[libc-commits] [PATCH] D117590: [libc] Implement correct rounding with all rounding modes for hypot functions.
Tue Ly via Phabricator via libc-commits
libc-commits at lists.llvm.org
Thu Jan 20 09:46:34 PST 2022
lntue added a comment.
In D117590#3258279 <https://reviews.llvm.org/D117590#3258279>, @zimmermann6 wrote:
> I'm ok with the new revision. However I see there are still some calls to get_round(). Did you try to replace them by floating-point operations?
>
> You might also want to add the following hard-to-round cases (for binary32) in your test cases:
>
> /* the following are hard-to-round cases with many identical bits after
> the round bit */
> {0x1.900004p+34,0x1.400002p+23}, /* 45 identical bits */
> {0x1.05555p+34,0x1.bffffep+23}, /* 44 identical bits */
> {0x1.e5fffap+34,0x1.affffep+23}, /* 45 identical bits */
> {0x1.260002p+34,0x1.500002p+23}, /* 45 identical bits */
> {0x1.fffffap+34,0x1.fffffep+23}, /* 45 identical bits */
> {0x1.8ffffap+34,0x1.3ffffep+23}, /* 45 identical bits */
> {0x1.87fffcp+35,0x1.bffffep+23}, /* 47 identical bits */
>
> By the way, none of the other libraries is correctly rounded for binary32, here are the corresponding worst cases:
>
> /* hypot(x,y) */
> {0x1.b8e50ap-52,-0x1.db1e78p-64}, /* GNU libc 0.500001 */
> {0x1.03b54cp-33,0x1.6ca6bep-45}, /* icc 0.500001 */
> {0x1.e2eff6p+97,-0x1.044cb2p+108}, /* AMD LibM 0.500001 */
> {-0x1.6b05c4p-127,0x1.6b3146p-126}, /* Newlib 1.20805 */
> {-0x1.6b05c4p-127,0x1.6b3146p-126}, /* OpenLibm 1.20805 */
> {0x1.26b188p-127,-0x1.a4f2fp-128}, /* Musl 0.926707 */
> {0x1.e2eff6p+97,-0x1.044cb2p+108}, /* Darwin 20.4.0 0.500001 */
Thanks Paul for the test cases! I've added these and the other 1.2k cases in your attachment to the test.
I have also tried replacing the final get_round with the corresponding floating point operations, but for some reason, -O3 always partially optimized it away even with -frounding-math flag together, and that make the results incorrect.
If I change the flag to -O2, then it is correct, but I see virtually no performance improvement. So I decided to keep the get_round() at the end so that it is easier to read and less sensitive to optimization flags.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D117590/new/
https://reviews.llvm.org/D117590
More information about the libc-commits
mailing list