This is an archive of the discontinued LLVM Phabricator instance.

[libc] Add a class called NormalFloat which represents normalized floats.
ClosedPublic

Authored by sivachandra on Aug 19 2020, 1:00 PM.

Details

Summary

This class helps in dealing with normal and subnormal numbers uniformly.
Moreover, since this class has been designed to handle all floating
formats across platforms, it helps implement floating point functions in
a uniform manner.

The implementations of frexp and logb have been switched to use this new
class as it allows us to use just one implementation across all
different floating point formats.

Diff Detail

Event Timeline

sivachandra created this revision.Aug 19 2020, 1:00 PM
sivachandra requested review of this revision.Aug 19 2020, 1:00 PM

@lntue - I want to use this change for few followup implementations. Also, I see that you have normalizaton functions in your sqrt patch wherein you use a binary search approach for normalization. I did a simple linear normalization in this patch. You can absorb this into your patch and implement the binary search normalization over it. I don't want to appear like I am stealing ;)

I want to avoid doing floating point multiplications so I will prefer your binary search normalization over the multiplication approach.

lntue added inline comments.Aug 19 2020, 11:08 PM
libc/utils/FPUtil/ManipulationFunctions.h
23

Are you going to add tests for frexp with subnormal inputs since this changes its behavior?

libc/utils/FPUtil/NormalFloat.h
49

This can be combined to (mantissa >= one)

142

extra ;

sivachandra marked 2 inline comments as done.

Address comments.

libc/utils/FPUtil/ManipulationFunctions.h
23

There are tests already covering the subnormal range in the InFloatRange etc kind of tests. It would be nice to compare with MPFR results, which we don't do currently because our MPFRMatcher does not yet support multiple-input-multiple-output functions. But, I agree with your point that we should add separate tests for subnormal range. I have not done it here as it doesn't make much sense to just add here if we are not comparing with MPFR results. I am working on a patch to extend MPFRMatcher for multiple-input-multiple-output. Once that is lands, and we can use it to compare frexp results with MPFR results, then I will add a separate test class for all math tests to test subnormal range exclusively.

lntue accepted this revision.Aug 20 2020, 7:53 AM
This revision is now accepted and ready to land.Aug 20 2020, 7:53 AM
This revision was landed with ongoing or failed builds.Aug 20 2020, 9:00 AM
This revision was automatically updated to reflect the committed changes.