|
6 | 6 | // |
7 | 7 | //===----------------------------------------------------------------------===// |
8 | 8 |
|
9 | | -// #include "exhaustive_test.h" |
10 | | -// #include "src/__support/FPUtil/FPBits.h" |
11 | | -// #include "src/__support/FPUtil/Hypot.h" |
12 | | -// #include "src/math/hypotf16.h" |
13 | | -// #include "test/UnitTest/FPMatcher.h" |
14 | | -// #include "utils/MPFRWrapper/MPFRUtils.h" |
15 | | -// |
16 | | -// namespace mpfr = LIBC_NAMESPACE::testing::mpfr; |
17 | | -// |
18 | | -// // Range of both inputs: [0, inf] |
19 | | -// static constexpr uint16_t START = 0x0000U; |
20 | | -// static constexpr uint16_t STOP = 0x7C00U; |
21 | | -// |
22 | | -// struct Hypotf16Checker : public virtual LIBC_NAMESPACE::testing::Test { |
23 | | -// using FloatType = float16; |
24 | | -// using FPBits = LIBC_NAMESPACE::fputil::FPBits<float16>; |
25 | | -// using StorageType = typename FPBits::StorageType; |
26 | | -// |
27 | | -// uint64_t check(uint16_t start, uint16_t stop, mpfr::RoundingMode rounding) |
28 | | -// { |
29 | | -// mpfr::ForceRoundingMode r(rounding); |
30 | | -// if (!r.success) |
31 | | -// return true; |
32 | | -// uint16_t xbits = start; |
33 | | -// uint64_t failed = 0; |
34 | | -// do { |
35 | | -// float16 x = FPBits(xbits).get_val(); |
36 | | -// uint16_t ybits = xbits; |
37 | | -// do { |
38 | | -// float16 y = FPBits(ybits).get_val(); |
39 | | -// bool correct = TEST_FP_EQ(LIBC_NAMESPACE::fputil::hypot(x, y), |
40 | | -// LIBC_NAMESPACE::hypotf16(x, y)); |
41 | | -// // Using MPFR will be much slower. |
42 | | -// // mpfr::BinaryInput<float16> input{x, y}; |
43 | | -// // bool correct = TEST_MPFR_MATCH_ROUNDING_SILENTLY( |
44 | | -// // mpfr::Operation::Hypot, input, LIBC_NAMESPACE::hypotf16(x, y), |
45 | | -// 0.5, |
46 | | -// // rounding); |
47 | | -// failed += (!correct); |
48 | | -// } while (ybits++ < STOP); |
49 | | -// } while (xbits++ < stop); |
50 | | -// return failed; |
51 | | -// } |
52 | | -// }; |
53 | | -// |
54 | | -// using LlvmLibcHypotf16ExhaustiveTest = |
55 | | -// LlvmLibcExhaustiveMathTest<Hypotf16Checker>; |
56 | | -// |
57 | | -// TEST_F(LlvmLibcHypotf16ExhaustiveTest, PositiveRange) { |
58 | | -// test_full_range_all_roundings(START, STOP); |
59 | | -// } |
| 9 | +#include "exhaustive_test.h" |
| 10 | +#include "src/__support/FPUtil/FPBits.h" |
| 11 | +#include "src/__support/FPUtil/Hypot.h" |
| 12 | +#include "src/math/hypotf16.h" |
| 13 | +#include "test/UnitTest/FPMatcher.h" |
| 14 | +#include "utils/MPFRWrapper/MPFRUtils.h" |
| 15 | + |
| 16 | +namespace mpfr = LIBC_NAMESPACE::testing::mpfr; |
| 17 | + |
| 18 | +// Range of both inputs: [0, inf] |
| 19 | +static constexpr uint16_t START = 0x0000U; |
| 20 | +static constexpr uint16_t STOP = 0x7C00U; |
| 21 | + |
| 22 | +struct Hypotf16Checker : public virtual LIBC_NAMESPACE::testing::Test { |
| 23 | + using FloatType = float16; |
| 24 | + using FPBits = LIBC_NAMESPACE::fputil::FPBits<float16>; |
| 25 | + using StorageType = typename FPBits::StorageType; |
| 26 | + |
| 27 | + uint64_t check(uint16_t start, uint16_t stop, mpfr::RoundingMode rounding) |
| 28 | + { |
| 29 | + mpfr::ForceRoundingMode r(rounding); |
| 30 | + if (!r.success) |
| 31 | + return true; |
| 32 | + uint16_t xbits = start; |
| 33 | + uint64_t failed = 0; |
| 34 | + do { |
| 35 | + float16 x = FPBits(xbits).get_val(); |
| 36 | + uint16_t ybits = xbits; |
| 37 | + do { |
| 38 | + float16 y = FPBits(ybits).get_val(); |
| 39 | + bool correct = TEST_FP_EQ(LIBC_NAMESPACE::fputil::hypot(x, y), |
| 40 | + LIBC_NAMESPACE::hypotf16(x, y)); |
| 41 | + // Using MPFR will be much slower. |
| 42 | + // mpfr::BinaryInput<float16> input{x, y}; |
| 43 | + // bool correct = TEST_MPFR_MATCH_ROUNDING_SILENTLY( |
| 44 | + // mpfr::Operation::Hypot, input, LIBC_NAMESPACE::hypotf16(x, y), |
| 45 | + // 0.5, |
| 46 | + // rounding); |
| 47 | + failed += (!correct); |
| 48 | + } while (ybits++ < STOP); |
| 49 | + } while (xbits++ < stop); |
| 50 | + return failed; |
| 51 | + } |
| 52 | +}; |
| 53 | + |
| 54 | +using LlvmLibcHypotf16ExhaustiveTest = |
| 55 | + LlvmLibcExhaustiveMathTest<Hypotf16Checker>; |
| 56 | + |
| 57 | +TEST_F(LlvmLibcHypotf16ExhaustiveTest, PositiveRange) { |
| 58 | + test_full_range_all_roundings(START, STOP); |
| 59 | +} |
0 commit comments