Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion libc/src/__support/math/atan2f.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
#include "src/__support/FPUtil/nearest_integer.h"
#include "src/__support/macros/config.h"
#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
#include "src/__support/macros/properties/cpu_features.h" // LIBC_TARGET_CPU_HAS_FMA

#if defined(LIBC_MATH_HAS_SKIP_ACCURATE_PASS) && \
defined(LIBC_MATH_HAS_INTERMEDIATE_COMP_IN_FLOAT)
defined(LIBC_MATH_HAS_INTERMEDIATE_COMP_IN_FLOAT) && \
defined(LIBC_TARGET_CPU_HAS_FMA_FLOAT)

// We use float-float implementation to reduce size.
#include "atan2f_float.h"
Expand Down
53 changes: 29 additions & 24 deletions libc/test/UnitTest/FPMatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "src/__support/FPUtil/fpbits_str.h"
#include "src/__support/libc_errno.h"
#include "src/__support/macros/config.h"
#include "src/__support/macros/optimization.h"
#include "src/__support/macros/properties/architectures.h"
#include "test/UnitTest/ErrnoCheckingTest.h"
#include "test/UnitTest/RoundingModeUtils.h"
Expand Down Expand Up @@ -294,42 +295,46 @@ struct ModifyMXCSR {

#define EXPECT_MATH_ERRNO(expected) \
do { \
if (math_errhandling & MATH_ERRNO) { \
int actual = libc_errno; \
libc_errno = 0; \
EXPECT_EQ(actual, expected); \
} \
if ((LIBC_MATH & LIBC_MATH_NO_ERRNO) == 0) \
if (math_errhandling & MATH_ERRNO) { \
int actual = libc_errno; \
libc_errno = 0; \
EXPECT_EQ(actual, expected); \
} \
} while (0)

#define ASSERT_MATH_ERRNO(expected) \
do { \
if (math_errhandling & MATH_ERRNO) { \
int actual = libc_errno; \
libc_errno = 0; \
ASSERT_EQ(actual, expected); \
} \
if ((LIBC_MATH & LIBC_MATH_NO_ERRNO) == 0) \
if (math_errhandling & MATH_ERRNO) { \
int actual = libc_errno; \
libc_errno = 0; \
ASSERT_EQ(actual, expected); \
} \
} while (0)

#define EXPECT_FP_EXCEPTION(expected) \
do { \
if (math_errhandling & MATH_ERREXCEPT) { \
EXPECT_EQ( \
LIBC_NAMESPACE::fputil::test_except( \
static_cast<int>(FE_ALL_EXCEPT)) & \
((expected) ? (expected) : static_cast<int>(FE_ALL_EXCEPT)), \
(expected)); \
} \
if ((LIBC_MATH & LIBC_MATH_NO_EXCEPT) == 0) \
if (math_errhandling & MATH_ERREXCEPT) { \
EXPECT_EQ( \
LIBC_NAMESPACE::fputil::test_except( \
static_cast<int>(FE_ALL_EXCEPT)) & \
((expected) ? (expected) : static_cast<int>(FE_ALL_EXCEPT)), \
(expected)); \
} \
} while (0)

#define ASSERT_FP_EXCEPTION(expected) \
do { \
if (math_errhandling & MATH_ERREXCEPT) { \
ASSERT_EQ( \
LIBC_NAMESPACE::fputil::test_except( \
static_cast<int>(FE_ALL_EXCEPT)) & \
((expected) ? (expected) : static_cast<int>(FE_ALL_EXCEPT)), \
(expected)); \
} \
if ((LIBC_MATH & LIBC_MATH_NO_EXCEPT) == 0) \
if (math_errhandling & MATH_ERREXCEPT) { \
ASSERT_EQ( \
LIBC_NAMESPACE::fputil::test_except( \
static_cast<int>(FE_ALL_EXCEPT)) & \
((expected) ? (expected) : static_cast<int>(FE_ALL_EXCEPT)), \
(expected)); \
} \
} while (0)

#define EXPECT_FP_EQ_WITH_EXCEPTION(expected_val, actual_val, expected_except) \
Expand Down
9 changes: 8 additions & 1 deletion libc/test/src/math/acos_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@
//
//===----------------------------------------------------------------------===//

#include "src/__support/macros/optimization.h"
#include "src/math/acos.h"
#include "test/UnitTest/FPMatcher.h"
#include "test/UnitTest/Test.h"
#include "utils/MPFRWrapper/MPFRUtils.h"

#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
#define TOLERANCE 8
#else
#define TOLERANCE 0
#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS

using LlvmLibcAcosTest = LIBC_NAMESPACE::testing::FPTest<double>;

namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
Expand Down Expand Up @@ -46,7 +53,7 @@ TEST_F(LlvmLibcAcosTest, InDoubleRange) {
++count;

if (!TEST_MPFR_MATCH_ROUNDING_SILENTLY(mpfr::Operation::Acos, x, result,
0.5, rounding_mode)) {
TOLERANCE + 0.5, rounding_mode)) {
++fails;
while (!TEST_MPFR_MATCH_ROUNDING_SILENTLY(mpfr::Operation::Acos, x,
result, tol, rounding_mode)) {
Expand Down
11 changes: 9 additions & 2 deletions libc/test/src/math/acosf16_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@
//
//===----------------------------------------------------------------------===//

#include "src/__support/macros/optimization.h"
#include "src/math/acosf16.h"
#include "test/UnitTest/FPMatcher.h"
#include "test/UnitTest/Test.h"
#include "utils/MPFRWrapper/MPFRUtils.h"

#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
#define TOLERANCE 1
#else
#define TOLERANCE 0
#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS

using LlvmLibcAcosf16Test = LIBC_NAMESPACE::testing::FPTest<float16>;

namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
Expand All @@ -28,7 +35,7 @@ TEST_F(LlvmLibcAcosf16Test, PositiveRange) {
float16 x = FPBits(v).get_val();

EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Acos, x,
LIBC_NAMESPACE::acosf16(x), 0.5);
LIBC_NAMESPACE::acosf16(x), TOLERANCE + 0.5);
}
}

Expand All @@ -37,6 +44,6 @@ TEST_F(LlvmLibcAcosf16Test, NegativeRange) {
float16 x = FPBits(v).get_val();

EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Acos, x,
LIBC_NAMESPACE::acosf16(x), 0.5);
LIBC_NAMESPACE::acosf16(x), TOLERANCE + 0.5);
}
}
11 changes: 9 additions & 2 deletions libc/test/src/math/acosf_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,18 @@
#include "hdr/math_macros.h"
#include "hdr/stdint_proxy.h"
#include "src/__support/FPUtil/FPBits.h"
#include "src/__support/macros/optimization.h"
#include "src/math/acosf.h"
#include "test/UnitTest/FPMatcher.h"
#include "test/UnitTest/Test.h"
#include "utils/MPFRWrapper/MPFRUtils.h"

#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
#define TOLERANCE 1
#else
#define TOLERANCE 0
#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS

namespace mpfr = LIBC_NAMESPACE::testing::mpfr;

using LlvmLibcAcosfTest = LIBC_NAMESPACE::testing::FPTest<float>;
Expand Down Expand Up @@ -72,8 +79,8 @@ TEST_F(LlvmLibcAcosfTest, SpecificBitPatterns) {
for (int i = 0; i < N; ++i) {
float x = FPBits(INPUTS[i]).get_val();
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Acos, x,
LIBC_NAMESPACE::acosf(x), 0.5);
LIBC_NAMESPACE::acosf(x), TOLERANCE + 0.5);
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Acos, -x,
LIBC_NAMESPACE::acosf(-x), 0.5);
LIBC_NAMESPACE::acosf(-x), TOLERANCE + 0.5);
}
}
9 changes: 8 additions & 1 deletion libc/test/src/math/acoshf_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,18 @@
#include "hdr/math_macros.h"
#include "hdr/stdint_proxy.h"
#include "src/__support/FPUtil/FPBits.h"
#include "src/__support/macros/optimization.h"
#include "src/math/acoshf.h"
#include "test/UnitTest/FPMatcher.h"
#include "test/UnitTest/Test.h"
#include "utils/MPFRWrapper/MPFRUtils.h"

#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
#define TOLERANCE 1
#else
#define TOLERANCE 0
#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS

using LlvmLibcAcoshfTest = LIBC_NAMESPACE::testing::FPTest<float>;

namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
Expand Down Expand Up @@ -68,6 +75,6 @@ TEST_F(LlvmLibcAcoshfTest, SpecificBitPatterns) {
for (int i = 0; i < N; ++i) {
float x = FPBits(INPUTS[i]).get_val();
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Acosh, x,
LIBC_NAMESPACE::acoshf(x), 0.5);
LIBC_NAMESPACE::acoshf(x), TOLERANCE + 0.5);
}
}
11 changes: 10 additions & 1 deletion libc/test/src/math/asin_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@
//
//===----------------------------------------------------------------------===//

#include "src/__support/macros/optimization.h"
#include "src/math/asin.h"
#include "test/UnitTest/FPMatcher.h"
#include "test/UnitTest/Test.h"
#include "utils/MPFRWrapper/MPFRUtils.h"

#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
#define TOLERANCE 6
#else
#define TOLERANCE 0
#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS

using LlvmLibcAsinTest = LIBC_NAMESPACE::testing::FPTest<double>;

namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
Expand Down Expand Up @@ -47,7 +54,7 @@ TEST_F(LlvmLibcAsinTest, InDoubleRange) {
++count;

if (!TEST_MPFR_MATCH_ROUNDING_SILENTLY(mpfr::Operation::Asin, x, result,
0.5, rounding_mode)) {
TOLERANCE + 0.5, rounding_mode)) {
++fails;
while (!TEST_MPFR_MATCH_ROUNDING_SILENTLY(mpfr::Operation::Asin, x,
result, tol, rounding_mode)) {
Expand All @@ -72,6 +79,7 @@ TEST_F(LlvmLibcAsinTest, InDoubleRange) {
tlog << " Test Rounding To Nearest...\n";
test(mpfr::RoundingMode::Nearest);

#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
tlog << " Test Rounding Downward...\n";
test(mpfr::RoundingMode::Downward);

Expand All @@ -80,4 +88,5 @@ TEST_F(LlvmLibcAsinTest, InDoubleRange) {

tlog << " Test Rounding Toward Zero...\n";
test(mpfr::RoundingMode::TowardZero);
#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS
}
11 changes: 9 additions & 2 deletions libc/test/src/math/asinf_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,18 @@
#include "hdr/math_macros.h"
#include "hdr/stdint_proxy.h"
#include "src/__support/FPUtil/FPBits.h"
#include "src/__support/macros/optimization.h"
#include "src/math/asinf.h"
#include "test/UnitTest/FPMatcher.h"
#include "test/UnitTest/Test.h"
#include "utils/MPFRWrapper/MPFRUtils.h"

#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
#define TOLERANCE 1
#else
#define TOLERANCE 0
#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS

using LlvmLibcAsinfTest = LIBC_NAMESPACE::testing::FPTest<float>;

namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
Expand Down Expand Up @@ -68,8 +75,8 @@ TEST_F(LlvmLibcAsinfTest, SpecificBitPatterns) {
for (int i = 0; i < N; ++i) {
float x = FPBits(INPUTS[i]).get_val();
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Asin, x,
LIBC_NAMESPACE::asinf(x), 0.5);
LIBC_NAMESPACE::asinf(x), TOLERANCE + 0.5);
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Asin, -x,
LIBC_NAMESPACE::asinf(-x), 0.5);
LIBC_NAMESPACE::asinf(-x), TOLERANCE + 0.5);
}
}
13 changes: 11 additions & 2 deletions libc/test/src/math/asinhf16_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@
//
//===----------------------------------------------------------------------===//

#include "src/__support/macros/optimization.h"
#include "src/math/asinhf16.h"
#include "test/UnitTest/FPMatcher.h"
#include "test/UnitTest/Test.h"
#include "utils/MPFRWrapper/MPFRUtils.h"

#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
#define TOLERANCE 1
#else
#define TOLERANCE 0
#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS

using LlvmLibcAsinhf16Test = LIBC_NAMESPACE::testing::FPTest<float16>;

namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
Expand All @@ -28,7 +35,8 @@ TEST_F(LlvmLibcAsinhf16Test, PositiveRange) {
float16 x = FPBits(v).get_val();

EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Asinh, x,
LIBC_NAMESPACE::asinhf16(x), 0.5);
LIBC_NAMESPACE::asinhf16(x),
TOLERANCE + 0.5);
}
}

Expand All @@ -37,6 +45,7 @@ TEST_F(LlvmLibcAsinhf16Test, NegativeRange) {
float16 x = FPBits(v).get_val();

EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Asinh, x,
LIBC_NAMESPACE::asinhf16(x), 0.5);
LIBC_NAMESPACE::asinhf16(x),
TOLERANCE + 0.5);
}
}
11 changes: 9 additions & 2 deletions libc/test/src/math/asinhf_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,18 @@
#include "hdr/math_macros.h"
#include "hdr/stdint_proxy.h"
#include "src/__support/FPUtil/FPBits.h"
#include "src/__support/macros/optimization.h"
#include "src/math/asinhf.h"
#include "test/UnitTest/FPMatcher.h"
#include "test/UnitTest/Test.h"
#include "utils/MPFRWrapper/MPFRUtils.h"

#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
#define TOLERANCE 1
#else
#define TOLERANCE 0
#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS

using LlvmLibcAsinhfTest = LIBC_NAMESPACE::testing::FPTest<float>;

namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
Expand Down Expand Up @@ -68,8 +75,8 @@ TEST_F(LlvmLibcAsinhfTest, SpecificBitPatterns) {
for (int i = 0; i < N; ++i) {
float x = FPBits(INPUTS[i]).get_val();
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Asinh, x,
LIBC_NAMESPACE::asinhf(x), 0.5);
LIBC_NAMESPACE::asinhf(x), TOLERANCE + 0.5);
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Asinh, -x,
LIBC_NAMESPACE::asinhf(-x), 0.5);
LIBC_NAMESPACE::asinhf(-x), TOLERANCE + 0.5);
}
}
19 changes: 15 additions & 4 deletions libc/test/src/math/atan2f_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,18 @@

#include "hdr/math_macros.h"
#include "src/__support/FPUtil/FPBits.h"
#include "src/__support/macros/optimization.h"
#include "src/math/atan2f.h"
#include "test/UnitTest/FPMatcher.h"
#include "test/UnitTest/Test.h"
#include "utils/MPFRWrapper/MPFRUtils.h"

#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
#define TOLERANCE 1
#else
#define TOLERANCE 0
#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS

using LlvmLibcAtan2fTest = LIBC_NAMESPACE::testing::FPTest<float>;
using LIBC_NAMESPACE::testing::tlog;

Expand All @@ -36,16 +43,20 @@ TEST_F(LlvmLibcAtan2fTest, TrickyInputs) {
float x = INPUTS[i].x;
float y = INPUTS[i].y;
ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Atan2, INPUTS[i],
LIBC_NAMESPACE::atan2f(x, y), 0.5);
LIBC_NAMESPACE::atan2f(x, y),
TOLERANCE + 0.5);
INPUTS[i].x = -INPUTS[i].x;
ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Atan2, INPUTS[i],
LIBC_NAMESPACE::atan2f(-x, y), 0.5);
LIBC_NAMESPACE::atan2f(-x, y),
TOLERANCE + 0.5);
INPUTS[i].y = -INPUTS[i].y;
ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Atan2, INPUTS[i],
LIBC_NAMESPACE::atan2f(-x, -y), 0.5);
LIBC_NAMESPACE::atan2f(-x, -y),
TOLERANCE + 0.5);
INPUTS[i].x = -INPUTS[i].x;
ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Atan2, INPUTS[i],
LIBC_NAMESPACE::atan2f(x, -y), 0.5);
LIBC_NAMESPACE::atan2f(x, -y),
TOLERANCE + 0.5);
}
}

Expand Down
Loading
Loading