This is an archive of the discontinued LLVM Phabricator instance.

Onboard signbitf to llvmlibc math functions.
Needs ReviewPublic

Authored by renyichen on Nov 30 2022, 4:55 PM.

Details

Reviewers
lntue
Summary

signbitf is implemented here with get_sign util.

Unit tests added. Different from existing functions, signbit output type is bool, so MPFRUtils expose the MPFR signbit function for unit test comparison instead of using (EXPECT/ASSERT)_MPFR_MATCH.

Diff Detail

Event Timeline

renyichen created this revision.Nov 30 2022, 4:55 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptNov 30 2022, 4:55 PM
renyichen requested review of this revision.Nov 30 2022, 4:55 PM
renyichen edited the summary of this revision. (Show Details)Nov 30 2022, 5:01 PM
renyichen added a reviewer: lntue.

Exhaustive/Performance tests might not be applicable for signbit. If desired, we may patch it here.

renyichen updated this revision to Diff 479124.Nov 30 2022, 5:32 PM

clang-format

lntue added inline comments.Dec 1 2022, 6:21 AM
libc/src/math/generic/CMakeLists.txt
1393

-O3 should be fine.

1395

Please fix

sivachandra added inline comments.
libc/spec/stdc.td
467

Is signbitf really specified by the C standard? For that matter, any standard at all? I think standards only specify a generic signbit macro which can be implemented as:

#define signbit(x) __builtin_signbit(x)

fputil vs builtin functions.

libc/spec/stdc.td
467

I see (I should but didn't check the C standard). I probably should implement this in a separate code change-list.

Thanks for the insight and I have several questions (which does not necessarily make sense =p): do we plan to implement a bunch of functions that rely on builtin_functions (isnan, isfinite, is_greater etc)? If so, can we rely on the builtin_functions in terms of existence/correctness/speed of builtin functions given that llvmlibc has its own fputils?

sivachandra added inline comments.Dec 2 2022, 12:04 PM
libc/spec/stdc.td
467

For items like isnan, signbit etc., all that needs to be done is to read one bit from the encoded floating point object. So, the builtins should not create recursive calls back to the libc. What will they call even if they want to as there is no equivalent libc function? It could be that a particular builtin is not implemented for a certain target. We can revisit your patch if and when we encounter such a target.

renyichen added inline comments.Dec 2 2022, 3:06 PM
libc/spec/stdc.td
467

Thanks for the explanation! I talked with lntue@ offline, and decided to leave isnan, signbit etc as they are for now and try to implement other functions.