This is an archive of the discontinued LLVM Phabricator instance.

[libc] add modified Eisel-Lemire for long doubles
ClosedPublic

Authored by michaelrj on Dec 7 2021, 1:21 PM.

Details

Summary

The Eisel-Lemire algorithm is an effecient way to handle converting to
floating point numbers from strings, but in its base form it only
supports up to 64 bit floating point numbers. This adds an
implementation to handle long doubles.

Diff Detail

Event Timeline

michaelrj created this revision.Dec 7 2021, 1:21 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 7 2021, 1:21 PM
michaelrj requested review of this revision.Dec 7 2021, 1:21 PM
lntue added inline comments.Dec 8 2021, 7:23 AM
libc/src/__support/str_to_float.h
253

I'm not sure if I understand the comment here.

michaelrj marked an inline comment as done.Dec 8 2021, 10:21 AM
michaelrj added inline comments.
libc/src/__support/str_to_float.h
253

msb is just the most significant bit of final_approx_upper (as assigned on line 248), so 1 ^ msb is equivalent to !msb

lntue added inline comments.Dec 9 2021, 6:56 AM
libc/src/__support/str_to_float.h
253

Nvm, I was confused because in line 248, msb was right shifted by (BITS_IN_MANTISSA - 1), and I thought that BITS_IN_MANTISSA was the mantissa length, which might lead to msb > 1, and hence 1 ^ msb is not the same as !msb. But actually, BITS_IN_MANTISSA = 128, and so msb is either 0 or 1, and thus 1 ^ msb = 1 - msb.

libc/test/src/__support/str_to_float_test.cpp
301

Is there any test for this #else clause?

michaelrj updated this revision to Diff 394057.Dec 13 2021, 2:27 PM
michaelrj marked an inline comment as done.

add tests for 128 bit long doubles

michaelrj marked an inline comment as done.Dec 13 2021, 2:28 PM
lntue accepted this revision.Dec 22 2021, 6:58 AM
This revision is now accepted and ready to land.Dec 22 2021, 6:58 AM
michaelrj updated this revision to Diff 395939.Dec 22 2021, 3:20 PM

rebase and add tests

This revision was automatically updated to reflect the committed changes.