This is an archive of the discontinued LLVM Phabricator instance.

[libc] Add implementations long double fabsl and truncl functions.
ClosedPublic

Authored by sivachandra on Jun 17 2020, 11:31 AM.

Details

Summary

Current implementations of single precision and double precision
floating point operations operate on bits of the integer type of
same size. The code made use of magic masks which were listed as
literal integer values. This is not possible in the case of long
double type as the mantissa of quad-precision long double type used
on non-x86 architectures is wider that the widest integer type for
which we can list literal values. So, in this patch, to avoid
using magic masks specified with literal values, we use packed
bit-field struct types and let the compiler generate the masks.
This new scheme allows us to implement long double flavors of the
various floating point operations. To keep the size of the patch
small, only the implementations of fabs and trunc have been
switched to the new scheme. In following patches, all exisiting
implementations will be switched to the new scheme.

Diff Detail

Event Timeline

sivachandra created this revision.Jun 17 2020, 11:31 AM

Fix few header guards.

Fix few typos.

Increase mpfr precision. This allows to to enable fabsl and
truncl for aarch64 as well.

asteinhauser accepted this revision.Jun 17 2020, 9:44 PM

Clang-tidy went completely crazy, or those warnings are expected?
Have you tested it in Visual Studio?

libc/test/src/math/fabsl_test.cpp
29

fabsl(NaN) == NaN test would be handy.

libc/test/src/math/truncl_test.cpp
28

truncl(NaN) == NaN test

37

Add some test where truncl(x) != x, e.g. truncl(2.5) == 2.0.

libc/utils/FPUtil/FPBits.h
34

This should be moved to MantissaWidth<long double> (10 lines below) if for visual studio long double and double are equivalent. You can hardly have 15 bytes for exponent and 52 bits for mantissa.

This revision is now accepted and ready to land.Jun 17 2020, 9:44 PM
sivachandra marked 4 inline comments as done.

Address comments.

libc/utils/FPUtil/FPBits.h
34

When we start adding MSVC support, we will have to enclose this in separate #define and friends. Without MSVC support, this is correct as is because all architectures use 15 bit exponent for long double.

This revision was automatically updated to reflect the committed changes.