This is an archive of the discontinued LLVM Phabricator instance.

[libc][math] Implement log10 function correctly rounded for all rounding modes
ClosedPublic

Authored by lntue on Dec 12 2022, 8:14 AM.

Details

Summary

Implement double precision log10 function correctly rounded for all
rounding modes. This implementation currently needs FMA instructions for
correctness.

Use 2 passes:
Fast pass:

  • 1 step range reduction with a lookup table of 2^7 = 128 elements to reduce the ranges to [-2^-7, 2^-7].
  • Use a degree-7 minimax polynomial generated by Sollya, evaluated using a mixed of double-double and double precisions.
  • Apply Ziv's test for accuracy.

Accurate pass:

  • Apply 5 more range reduction steps to reduce the ranges further to [-2^-27, 2^-27].
  • Use a degree-4 minimax polynomial generated by Sollya, evaluated using 192-bit precisions.
  • By the result of Lefevre (add quote), this is more than enough for correct rounding to all rounding modes.

In progress: Adding detail documentations about the algorithm.

Depend on: https://reviews.llvm.org/D136799

Diff Detail

Event Timeline

lntue created this revision.Dec 12 2022, 8:14 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptDec 12 2022, 8:14 AM
lntue requested review of this revision.Dec 12 2022, 8:14 AM
lntue edited the summary of this revision. (Show Details)Dec 12 2022, 8:25 AM
lntue updated this revision to Diff 482714.Dec 13 2022, 9:49 PM

Sync to HEAD.

zimmermann6 accepted this revision.Dec 14 2022, 1:02 AM

I tried on 2096978 hard-to-round cases I have generated and all tests pass, with all four rounding modes. Great work!

zimmerma@biscotte:/tmp/core-math$ LIBM=/localdisk/zimmerma/llvm-project/build/projects/libc/lib/libllvmlibc.a ./check.sh --worst log10
Running worst cases check in --rndn mode...
2096978 tests passed, 0 failure(s)
Running worst cases check in --rndz mode...
2096978 tests passed, 0 failure(s)
Running worst cases check in --rndu mode...
2096978 tests passed, 0 failure(s)
Running worst cases check in --rndd mode...
2096978 tests passed, 0 failure(s)
This revision is now accepted and ready to land.Dec 14 2022, 1:02 AM
lntue updated this revision to Diff 487236.Jan 8 2023, 2:41 PM

Update log algorithm doc and unit tests.

This revision was landed with ongoing or failed builds.Jan 8 2023, 2:42 PM
This revision was automatically updated to reflect the committed changes.