This is an archive of the discontinued LLVM Phabricator instance.

[libc] Refactor sqrt implementations and add tests for generic sqrt implementations.
ClosedPublic

Authored by lntue on Jan 25 2022, 12:12 PM.

Details

Summary

Refactor sqrt implementations:

  • Move architecture specific instructions from src/math/<arch> to src/__support/FPUtil/<arch> folder.
  • Move generic implementation of sqrt to src/__support/FPUtil/generic folder and add it as a header library.
  • Use src/__support/FPUtil/sqrt.h for architecture/generic selections.
  • Add unit tests for generic implementation of sqrt.

Diff Detail

Event Timeline

lntue created this revision.Jan 25 2022, 12:12 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 25 2022, 12:12 PM
lntue requested review of this revision.Jan 25 2022, 12:12 PM
lntue edited the summary of this revision. (Show Details)Jan 25 2022, 12:17 PM
lntue edited the summary of this revision. (Show Details)

mostly LGTM, with a few nits.

libc/src/__support/FPUtil/CMakeLists.txt
36

fix

libc/src/__support/FPUtil/generic/CMakeLists.txt
7

fix

libc/src/__support/FPUtil/generic/sqrt.h
116

this else is unnecessary, since the only other branch returns. In addition, the other branch doesn't need braces, since it only has one line.

lntue updated this revision to Diff 403089.Jan 25 2022, 5:40 PM

Add missing extra lines at the end of files.

lntue marked 2 inline comments as done.Jan 25 2022, 5:46 PM
lntue added inline comments.
libc/src/__support/FPUtil/generic/sqrt.h
116

This else is actually necessary, since this is an if constexpr expression, which is a more C++ friendly version of #if #else #endif. Without enclosing the entire following part inside else { }, the compiler will put them in for x86 long double, and then generate a ton of warnings and errors, even though they are dead codes due to the return from the if clause.

While this is OK, you will have to do corresponding changes to the Bazel overlay as well. Best if done all together.

lntue updated this revision to Diff 403473.Jan 26 2022, 7:40 PM

Add Bazel overlay.

lntue added a comment.Jan 26 2022, 7:40 PM

While this is OK, you will have to do corresponding changes to the Bazel overlay as well. Best if done all together.

Done.

sivachandra accepted this revision.Jan 27 2022, 8:43 AM
This revision is now accepted and ready to land.Jan 27 2022, 8:43 AM
libc/src/math/x86_64/sqrt.cpp