This is an archive of the discontinued LLVM Phabricator instance.

[libc] add fast path to string to float conversion
ClosedPublic

Authored by michaelrj on Oct 26 2021, 4:46 PM.

Details

Summary

Add the fast path first described by Clinger [1] with additions by Gay [2].
This speeds up conversion by about 10% by handling numbers with fewer digits
more efficiently.

[1] Clinger WD. How to Read Floating Point Numbers Accurately.
SIGPLAN Not 1990 Jun;25(6):92–101. https://doi.org/10.1145/93548.93557.
[2] Gay DM, Correctly rounded binary-decimal and decimal-binary conversions;

  1. AT&T Bell Laboratories Numerical Analysis Manuscript 90-10.

Diff Detail

Event Timeline

michaelrj created this revision.Oct 26 2021, 4:46 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 26 2021, 4:46 PM
michaelrj requested review of this revision.Oct 26 2021, 4:46 PM
sivachandra added inline comments.Oct 27 2021, 11:39 PM
libc/src/__support/str_to_float.h
321

Is it necessary to declare the members? Can we not get by with just a class declaration like this:

template <typename T> class ClingerConsts;
421

Can we add specific tests for the newly added conditions? Existing tests probably cover them, but having separated tests helps in isolating and debugging in future.

michaelrj updated this revision to Diff 383194.Oct 28 2021, 4:15 PM
michaelrj marked 2 inline comments as done.

add unit tests and clean up the fast path.

libc/src/__support/str_to_float.h
321

That was something I added when it would've allowed types without a specific set to just skip this path. I've changed it to be what you said since as it was it would return incorrect values if someone attempted to use it with a long double.

sivachandra accepted this revision.Oct 28 2021, 11:44 PM
This revision is now accepted and ready to land.Oct 28 2021, 11:44 PM
This revision was automatically updated to reflect the committed changes.