This is an archive of the discontinued LLVM Phabricator instance.

[libc] tighten strtofloat cutoffs
ClosedPublic

Authored by michaelrj on Oct 25 2022, 10:14 AM.

Details

Summary

When a number for strtofloat has an exponent that's too big or small, it
doesn't need to be calculated precisely since it is guaranteed to be
either INF or 0.0. This tightens those cutoffs to improve performance.

Diff Detail

Event Timeline

michaelrj created this revision.Oct 25 2022, 10:14 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptOct 25 2022, 10:14 AM
michaelrj requested review of this revision.Oct 25 2022, 10:14 AM
sivachandra accepted this revision.Oct 25 2022, 11:00 AM
sivachandra added inline comments.
libc/src/__support/str_to_float.h
563

What is "intermediate mantissa width"?

606

If you return a negative value from get_lower_bound, you don't have to do the inverted test, but simply:

if (exp10 < 0 && int64_t(exp) < get_lower_bound<T>()) {
  ...
}
This revision is now accepted and ready to land.Oct 25 2022, 11:00 AM
michaelrj updated this revision to Diff 470627.Oct 25 2022, 3:30 PM
michaelrj marked 2 inline comments as done.

Added comments explaining the calculation for the lower bound.
Simplified lower bound logic and moved to int32.

This revision was automatically updated to reflect the committed changes.