[libc][math] add smoke tests to shared/math.h (#149741)
Adding smoke tests for shared math header. part of #147386
This commit is contained in:
parent
f7347e9f78
commit
2865f1ba96
@ -10,10 +10,10 @@
|
||||
#define LLVM_LIBC_SHARED_MATH_EXP10F_H
|
||||
|
||||
#include "include/llvm-libc-macros/float16-macros.h"
|
||||
#include "shared/libc_common.h"
|
||||
|
||||
#ifdef LIBC_TYPES_HAS_FLOAT16
|
||||
|
||||
#include "shared/libc_common.h"
|
||||
#include "src/__support/math/exp10f16.h"
|
||||
|
||||
namespace LIBC_NAMESPACE_DECL {
|
||||
|
@ -24,10 +24,10 @@ namespace LIBC_NAMESPACE_DECL {
|
||||
|
||||
namespace math {
|
||||
|
||||
using DoubleDouble = fputil::DoubleDouble;
|
||||
using Float128 = fputil::DyadicFloat<128>;
|
||||
|
||||
static constexpr double acos(double x) {
|
||||
using DoubleDouble = fputil::DoubleDouble;
|
||||
using Float128 = fputil::DyadicFloat<128>;
|
||||
using namespace asin_internal;
|
||||
using FPBits = fputil::FPBits<double>;
|
||||
|
||||
FPBits xbits(x);
|
||||
|
@ -22,7 +22,10 @@ namespace LIBC_NAMESPACE_DECL {
|
||||
|
||||
namespace math {
|
||||
|
||||
namespace acosf_internal {
|
||||
|
||||
#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
|
||||
|
||||
static constexpr size_t N_EXCEPTS = 4;
|
||||
|
||||
// Exceptional values when |x| <= 0.5
|
||||
@ -37,9 +40,14 @@ static constexpr fputil::ExceptValues<float, N_EXCEPTS> ACOSF_EXCEPTS = {{
|
||||
// x = -0x1.04c444p-12, acosf(x) = 0x1.923p0 (RZ)
|
||||
{0xb9826222, 0x3fc91800, 1, 0, 1},
|
||||
}};
|
||||
|
||||
#endif // !LIBC_MATH_HAS_SKIP_ACCURATE_PASS
|
||||
|
||||
} // namespace acosf_internal
|
||||
|
||||
static constexpr float acosf(float x) {
|
||||
using namespace acosf_internal;
|
||||
using namespace inv_trigf_utils_internal;
|
||||
using FPBits = typename fputil::FPBits<float>;
|
||||
|
||||
FPBits xbits(x);
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
namespace LIBC_NAMESPACE_DECL {
|
||||
|
||||
namespace {
|
||||
namespace asin_internal {
|
||||
|
||||
using DoubleDouble = fputil::DoubleDouble;
|
||||
using Float128 = fputil::DyadicFloat<128>;
|
||||
@ -567,7 +567,7 @@ LIBC_INLINE static constexpr Float128 asin_eval(const Float128 &u,
|
||||
|
||||
#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS
|
||||
|
||||
} // anonymous namespace
|
||||
} // namespace asin_internal
|
||||
|
||||
} // namespace LIBC_NAMESPACE_DECL
|
||||
|
||||
|
@ -16,6 +16,8 @@
|
||||
|
||||
namespace LIBC_NAMESPACE_DECL {
|
||||
|
||||
namespace inv_trigf_utils_internal {
|
||||
|
||||
// PI and PI / 2
|
||||
static constexpr double M_MATH_PI = 0x1.921fb54442d18p+1;
|
||||
static constexpr double M_MATH_PI_2 = 0x1.921fb54442d18p+0;
|
||||
@ -175,6 +177,8 @@ LIBC_INLINE static double asin_eval(double xsq) {
|
||||
return fputil::multiply_add(xsq, r2, r1);
|
||||
}
|
||||
|
||||
} // namespace inv_trigf_utils_internal
|
||||
|
||||
} // namespace LIBC_NAMESPACE_DECL
|
||||
|
||||
#endif // LLVM_LIBC_SRC___SUPPORT_MATH_INV_TRIGF_UTILS_H
|
||||
|
@ -25,6 +25,7 @@ using DoubleDouble = fputil::DoubleDouble;
|
||||
using Float128 = fputil::DyadicFloat<128>;
|
||||
|
||||
LLVM_LIBC_FUNCTION(double, asin, (double x)) {
|
||||
using namespace asin_internal;
|
||||
using FPBits = fputil::FPBits<double>;
|
||||
|
||||
FPBits xbits(x);
|
||||
|
@ -44,6 +44,7 @@ static constexpr fputil::ExceptValues<float, N_EXCEPTS> ASINF_EXCEPTS_HI = {{
|
||||
#endif // !LIBC_MATH_HAS_SKIP_ACCURATE_PASS
|
||||
|
||||
LLVM_LIBC_FUNCTION(float, asinf, (float x)) {
|
||||
using namespace inv_trigf_utils_internal;
|
||||
using FPBits = typename fputil::FPBits<float>;
|
||||
|
||||
FPBits xbits(x);
|
||||
|
@ -236,6 +236,7 @@ float atan2f_double_double(double num_d, double den_d, double q_d, int idx,
|
||||
// which is about rounding errors of double-double (2^-104).
|
||||
|
||||
LLVM_LIBC_FUNCTION(float, atan2f, (float y, float x)) {
|
||||
using namespace inv_trigf_utils_internal;
|
||||
using FPBits = typename fputil::FPBits<float>;
|
||||
constexpr double IS_NEG[2] = {1.0, -1.0};
|
||||
constexpr double PI = 0x1.921fb54442d18p1;
|
||||
|
@ -20,6 +20,7 @@
|
||||
namespace LIBC_NAMESPACE_DECL {
|
||||
|
||||
LLVM_LIBC_FUNCTION(float, atanf, (float x)) {
|
||||
using namespace inv_trigf_utils_internal;
|
||||
using FPBits = typename fputil::FPBits<float>;
|
||||
|
||||
constexpr double FINAL_SIGN[2] = {1.0, -1.0};
|
||||
|
@ -20,6 +20,7 @@ endif()
|
||||
|
||||
add_subdirectory(src)
|
||||
add_subdirectory(utils)
|
||||
add_subdirectory(shared)
|
||||
|
||||
if(NOT LLVM_LIBC_FULL_BUILD)
|
||||
return()
|
||||
|
24
libc/test/shared/CMakeLists.txt
Normal file
24
libc/test/shared/CMakeLists.txt
Normal file
@ -0,0 +1,24 @@
|
||||
add_custom_target(libc-shared-tests)
|
||||
|
||||
add_fp_unittest(
|
||||
shared_math_test
|
||||
SUITE
|
||||
libc-shared-tests
|
||||
SRCS
|
||||
shared_math_test.cpp
|
||||
DEPENDS
|
||||
libc.src.__support.math.acos
|
||||
libc.src.__support.math.acosf
|
||||
libc.src.__support.math.exp
|
||||
libc.src.__support.math.exp10
|
||||
libc.src.__support.math.exp10f
|
||||
libc.src.__support.math.exp10f16
|
||||
libc.src.__support.math.expf
|
||||
libc.src.__support.math.expf16
|
||||
libc.src.__support.math.frexpf
|
||||
libc.src.__support.math.frexpf128
|
||||
libc.src.__support.math.frexpf16
|
||||
libc.src.__support.math.ldexpf
|
||||
libc.src.__support.math.ldexpf128
|
||||
libc.src.__support.math.ldexpf16
|
||||
)
|
65
libc/test/shared/shared_math_test.cpp
Normal file
65
libc/test/shared/shared_math_test.cpp
Normal file
@ -0,0 +1,65 @@
|
||||
//===-- Unittests for shared math functions -------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "shared/math.h"
|
||||
#include "test/UnitTest/FPMatcher.h"
|
||||
|
||||
#ifdef LIBC_TYPES_HAS_FLOAT16
|
||||
|
||||
TEST(LlvmLibcSharedMathTest, AllFloat16) {
|
||||
int exponent;
|
||||
|
||||
EXPECT_FP_EQ(0x1p+0f16, LIBC_NAMESPACE::shared::exp10f16(0.0f16));
|
||||
|
||||
EXPECT_FP_EQ(0x1p+0f16, LIBC_NAMESPACE::shared::expf16(0.0f16));
|
||||
|
||||
ASSERT_FP_EQ(float16(8 << 5), LIBC_NAMESPACE::shared::ldexpf16(float(8), 5));
|
||||
ASSERT_FP_EQ(float16(-1 * (8 << 5)),
|
||||
LIBC_NAMESPACE::shared::ldexpf16(float(-8), 5));
|
||||
|
||||
EXPECT_FP_EQ_ALL_ROUNDING(0.75f16,
|
||||
LIBC_NAMESPACE::shared::frexpf16(24.0f, &exponent));
|
||||
EXPECT_EQ(exponent, 5);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
TEST(LlvmLibcSharedMathTest, AllFloat) {
|
||||
int exponent;
|
||||
|
||||
EXPECT_FP_EQ(0x1.921fb6p+0, LIBC_NAMESPACE::shared::acosf(0.0f));
|
||||
EXPECT_FP_EQ(0x1p+0f, LIBC_NAMESPACE::shared::exp10f(0.0f));
|
||||
EXPECT_FP_EQ(0x1p+0f, LIBC_NAMESPACE::shared::expf(0.0f));
|
||||
|
||||
EXPECT_FP_EQ_ALL_ROUNDING(0.75f,
|
||||
LIBC_NAMESPACE::shared::frexpf(24.0f, &exponent));
|
||||
EXPECT_EQ(exponent, 5);
|
||||
|
||||
ASSERT_FP_EQ(float(8 << 5), LIBC_NAMESPACE::shared::ldexpf(float(8), 5));
|
||||
ASSERT_FP_EQ(float(-1 * (8 << 5)),
|
||||
LIBC_NAMESPACE::shared::ldexpf(float(-8), 5));
|
||||
}
|
||||
|
||||
TEST(LlvmLibcSharedMathTest, AllDouble) {
|
||||
EXPECT_FP_EQ(0x1.921fb54442d18p+0, LIBC_NAMESPACE::shared::acos(0.0));
|
||||
EXPECT_FP_EQ(0x1p+0, LIBC_NAMESPACE::shared::exp(0.0));
|
||||
EXPECT_FP_EQ(0x1p+0, LIBC_NAMESPACE::shared::exp10(0.0));
|
||||
}
|
||||
|
||||
TEST(LlvmLibcSharedMathTest, AllFloat128) {
|
||||
int exponent;
|
||||
|
||||
EXPECT_FP_EQ_ALL_ROUNDING(
|
||||
float128(0.75), LIBC_NAMESPACE::shared::frexpf128(24.0f, &exponent));
|
||||
EXPECT_EQ(exponent, 5);
|
||||
|
||||
ASSERT_FP_EQ(float128(8 << 5),
|
||||
LIBC_NAMESPACE::shared::ldexpf128(float(8), 5));
|
||||
ASSERT_FP_EQ(float128(-1 * (8 << 5)),
|
||||
LIBC_NAMESPACE::shared::ldexpf128(float(-8), 5));
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user