This is an archive of the discontinued LLVM Phabricator instance.

[libc][math] Clean up exhaustive tests implementations.
ClosedPublic

Authored by lntue on Jun 23 2023, 9:10 PM.

Details

Summary

Clean up exhaustive tests. Let check functions return number of failures instead of passed/failed.

Diff Detail

Event Timeline

lntue created this revision.Jun 23 2023, 9:10 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJun 23 2023, 9:10 PM
lntue requested review of this revision.Jun 23 2023, 9:10 PM
lntue edited the summary of this revision. (Show Details)Jun 24 2023, 12:16 PM
sivachandra added inline comments.Jun 25 2023, 11:01 PM
libc/test/src/math/exhaustive/exhaustive_test.h
39

Can this be more specific like:

template <typename FloatType>
using FuncType = FloatType(FloatType);

template <typename FloatType, __llvm_libc::testing::mpfr::Operation Op, FuncType<FloatType> Func>
struct LlvmLibcExhaustiveMathTest ... {
  ...
  static constexpr FuncType<FloatType> *FUNC = Func;

  uint64_t check(...) {
    bool correct = TEST_MPFR_MATCH_ROUNDING_SILENTLY(Op, x, FUNC(x), 0.5, rounding);
  }
  ...
}

For erff, you can do:

using LlvmLibcErffExhaustiveTest : publicLlvmLibcExhaustiveTest<float, mpfr::Operation::ErfOp, __llvm_libc::erff>;
45

Why is this virtual?

56

Do we tolerate errors?

lntue updated this revision to Diff 534644.Jun 26 2023, 10:42 AM

Address comments.

lntue added inline comments.Jun 26 2023, 10:49 AM
libc/test/src/math/exhaustive/exhaustive_test.h
39

I've separated them into Checker class to provide the check method, and the canonical UnaryOpChecker::check method. Other examples of Checker are in hypotf_test and sincosf_test.

Then the LlvmLibcUnaryOpExhaustiveMathTest will take 3 template parameters as you suggested.

45

Originally, it is virtual so that different tests such as hypotf or sincosf can override the check method. I refactored the classes so that the check method does not need to be virtual.

56

We do not tolerate errors, but providing the number of failed inputs is very useful when choosing the polynomial approximation.

sivachandra accepted this revision.Jun 27 2023, 10:49 PM
This revision is now accepted and ready to land.Jun 27 2023, 10:49 PM
This revision was automatically updated to reflect the committed changes.
libc/test/src/math/exhaustive/exhaustive_test.h