[libc-commits] [libc] [libc][math][c23] Add hypotf16() function (PR #131991)
Tejas Vipin via libc-commits
libc-commits at lists.llvm.org
Wed Mar 19 22:45:34 PDT 2025
https://github.com/meltq updated https://github.com/llvm/llvm-project/pull/131991
>From 08792d33933092bf25c1c059fe2fd402030ca5c5 Mon Sep 17 00:00:00 2001
From: meltq <alissxlace at proton.me>
Date: Wed, 19 Mar 2025 15:19:37 +0530
Subject: [PATCH 1/3] Add hypotf16() function
---
libc/config/linux/x86_64/entrypoints.txt | 1 +
libc/docs/headers/math/index.rst | 2 +-
libc/include/math.yaml | 8 ++
libc/src/math/CMakeLists.txt | 1 +
libc/src/math/generic/CMakeLists.txt | 15 ++++
libc/src/math/generic/hypotf16.cpp | 86 +++++++++++++++++++
libc/src/math/hypotf16.h | 21 +++++
libc/test/src/math/CMakeLists.txt | 12 +++
libc/test/src/math/exhaustive/CMakeLists.txt | 18 ++++
.../src/math/exhaustive/hypotf16_test.cpp | 56 ++++++++++++
libc/test/src/math/hypotf16_test.cpp | 27 ++++++
libc/test/src/math/smoke/CMakeLists.txt | 14 +++
libc/test/src/math/smoke/hypotf16_test.cpp | 33 +++++++
13 files changed, 293 insertions(+), 1 deletion(-)
create mode 100644 libc/src/math/generic/hypotf16.cpp
create mode 100644 libc/src/math/hypotf16.h
create mode 100644 libc/test/src/math/exhaustive/hypotf16_test.cpp
create mode 100644 libc/test/src/math/hypotf16_test.cpp
create mode 100644 libc/test/src/math/smoke/hypotf16_test.cpp
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index a29478898fe70..f2a936962dd6d 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -701,6 +701,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
libc.src.math.fromfpf16
libc.src.math.fromfpxf16
libc.src.math.getpayloadf16
+ libc.src.math.hypotf16
libc.src.math.ilogbf16
libc.src.math.iscanonicalf16
libc.src.math.issignalingf16
diff --git a/libc/docs/headers/math/index.rst b/libc/docs/headers/math/index.rst
index 5b855ce4881c3..ff7fd32690b3c 100644
--- a/libc/docs/headers/math/index.rst
+++ b/libc/docs/headers/math/index.rst
@@ -305,7 +305,7 @@ Higher Math Functions
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| fsqrt | N/A | |check| | |check| | N/A | |check|\* | 7.12.14.6 | F.10.11 |
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| hypot | |check| | |check| | | | | 7.12.7.4 | F.10.4.4 |
+| hypot | |check| | |check| | | |check| | | 7.12.7.4 | F.10.4.4 |
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| lgamma | | | | | | 7.12.8.3 | F.10.5.3 |
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
diff --git a/libc/include/math.yaml b/libc/include/math.yaml
index a66f981030864..b0bb5d74c5605 100644
--- a/libc/include/math.yaml
+++ b/libc/include/math.yaml
@@ -1366,6 +1366,14 @@ functions:
arguments:
- type: float
- type: float
+ - name: hypotf16
+ standards:
+ - stdc
+ return_type: _Float16
+ arguments:
+ - type: _Float16
+ - type: _Float16
+ guard: LIBC_TYPES_HAS_FLOAT16
- name: ilogb
standards:
- stdc
diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index f18a73d46f9aa..3a098951bb205 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -310,6 +310,7 @@ add_math_entrypoint_object(getpayloadf128)
add_math_entrypoint_object(hypot)
add_math_entrypoint_object(hypotf)
+add_math_entrypoint_object(hypotf16)
add_math_entrypoint_object(ilogb)
add_math_entrypoint_object(ilogbf)
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 3114289bad486..7ec2e0bf9e865 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -3105,6 +3105,21 @@ add_entrypoint_object(
libc.src.__support.macros.optimization
)
+add_entrypoint_object(
+ hypotf16
+ SRCS
+ hypotf16.cpp
+ HDRS
+ ../hypotf16.h
+ DEPENDS
+ libc.src.__support.FPUtil.fenv_impl
+ libc.src.__support.FPUtil.fp_bits
+ libc.src.__support.FPUtil.multiply_add
+ libc.src.__support.FPUtil.sqrt
+ libc.src.__support.macros.optimization
+ libc.src.__support.macros.properties.types
+)
+
add_entrypoint_object(
fdim
SRCS
diff --git a/libc/src/math/generic/hypotf16.cpp b/libc/src/math/generic/hypotf16.cpp
new file mode 100644
index 0000000000000..c827c0d8a513f
--- /dev/null
+++ b/libc/src/math/generic/hypotf16.cpp
@@ -0,0 +1,86 @@
+//===-- Implementation of hypotf function ---------------------------------===//
+//
+// 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 "src/math/hypotf16.h"
+#include "src/__support/FPUtil/FEnvImpl.h"
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/FPUtil/multiply_add.h"
+#include "src/__support/FPUtil/sqrt.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/properties/types.h"
+#include "src/__support/macros/optimization.h"
+#include "src/__support/FPUtil/cast.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(float16, hypotf16, (float16 x, float16 y)) {
+ using FloatBits = fputil::FPBits<float>;
+ using FPBits = fputil::FPBits<float16>;
+
+ FPBits x_abs = FPBits(x).abs();
+ FPBits y_abs = FPBits(y).abs();
+
+ bool x_abs_larger = x_abs.uintval() >= y_abs.uintval();
+
+ FPBits a_bits = x_abs_larger ? x_abs : y_abs;
+ FPBits b_bits = x_abs_larger ? y_abs : x_abs;
+
+ uint16_t a_u = a_bits.uintval();
+ uint16_t b_u = b_bits.uintval();
+
+ // Note: replacing `a_u >= FPBits::EXP_MASK` with `a_bits.is_inf_or_nan()`
+ // generates extra exponent bit masking instructions on x86-64.
+ if (LIBC_UNLIKELY(a_u >= FPBits::EXP_MASK)) {
+ // x or y is inf or nan
+ if (a_bits.is_signaling_nan() || b_bits.is_signaling_nan()) {
+ fputil::raise_except_if_required(FE_INVALID);
+ return FPBits::quiet_nan().get_val();
+ }
+ if (a_bits.is_inf() || b_bits.is_inf())
+ return FPBits::inf().get_val();
+ return a_bits.get_val();
+ }
+
+ if (LIBC_UNLIKELY(a_u - b_u >=
+ static_cast<uint16_t>((FPBits::FRACTION_LEN + 2)
+ << FPBits::FRACTION_LEN)))
+ return x_abs.get_val() + y_abs.get_val();
+
+ float ad = fputil::cast<float>(a_bits.get_val());
+ float bd = fputil::cast<float>(b_bits.get_val());
+
+ // These squares are exact.
+ float a_sq = ad * ad;
+ float sum_sq = fputil::multiply_add(bd, bd, a_sq);
+
+ FloatBits result(fputil::sqrt<float>(sum_sq));
+ uint32_t r_u = result.uintval();
+
+ // If any of the sticky bits of the result are non-zero, except the LSB, then
+ // the rounded result is correct.
+ if (LIBC_UNLIKELY(((r_u + 1) & 0x0000'0FFE) == 0)) {
+ float r_d = result.get_val();
+
+ // Perform rounding correction.
+ float sum_sq_lo = fputil::multiply_add(bd, bd, a_sq - sum_sq);
+ float err = sum_sq_lo - fputil::multiply_add(r_d, r_d, -sum_sq);
+
+ if (err > 0) {
+ r_u |= 1;
+ } else if ((err < 0) && (r_u & 1) == 0) {
+ r_u -= 1;
+ } else if ((r_u & 0x0000'1FFF) == 0) {
+ // The rounded result is exact.
+ fputil::clear_except_if_required(FE_INEXACT);
+ }
+ return fputil::cast<float16>(FloatBits(r_u).get_val());
+ }
+
+ return fputil::cast<float16>(result.get_val());
+}
+}
diff --git a/libc/src/math/hypotf16.h b/libc/src/math/hypotf16.h
new file mode 100644
index 0000000000000..2d37c61b4ee7b
--- /dev/null
+++ b/libc/src/math/hypotf16.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for hypotf16 ----------------------*- C++ -*-===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_MATH_HYPOTF16_H
+#define LLVM_LIBC_SRC_MATH_HYPOTF16_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+float16 hypotf16(float16 x, float16 y);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_HYPOTF16_H
diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt
index 53ddd301900c0..79ae9377afd28 100644
--- a/libc/test/src/math/CMakeLists.txt
+++ b/libc/test/src/math/CMakeLists.txt
@@ -1701,6 +1701,18 @@ add_fp_unittest(
libc.src.__support.FPUtil.fp_bits
)
+add_fp_unittest(
+ hypotf16_test
+ NEED_MPFR
+ SUITE
+ libc-math-unittests
+ SRCS
+ hypotf16_test.cpp
+ DEPENDS
+ libc.src.math.hypotf16
+ libc.src.__support.FPUtil.fp_bits
+)
+
add_fp_unittest(
nextafter_test
SUITE
diff --git a/libc/test/src/math/exhaustive/CMakeLists.txt b/libc/test/src/math/exhaustive/CMakeLists.txt
index b1927dbc19a3b..551f449c9c8db 100644
--- a/libc/test/src/math/exhaustive/CMakeLists.txt
+++ b/libc/test/src/math/exhaustive/CMakeLists.txt
@@ -314,6 +314,24 @@ add_fp_unittest(
-lpthread
)
+add_fp_unittest(
+ hypotf16_test
+ NO_RUN_POSTBUILD
+ NEED_MPFR
+ SUITE
+ libc_math_exhaustive_tests
+ SRCS
+ hypotf16_test.cpp
+ COMPILE_OPTIONS
+ ${libc_opt_high_flag}
+ DEPENDS
+ .exhaustive_test
+ libc.src.math.hypotf16
+ libc.src.__support.FPUtil.fp_bits
+ LINK_LIBRARIES
+ -lpthread
+)
+
add_fp_unittest(
fmod_generic_impl_test
NO_RUN_POSTBUILD
diff --git a/libc/test/src/math/exhaustive/hypotf16_test.cpp b/libc/test/src/math/exhaustive/hypotf16_test.cpp
new file mode 100644
index 0000000000000..085504398deac
--- /dev/null
+++ b/libc/test/src/math/exhaustive/hypotf16_test.cpp
@@ -0,0 +1,56 @@
+//===-- Exhaustive test for hypotf16 --------------------------------------===//
+//
+// 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 "exhaustive_test.h"
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/FPUtil/Hypot.h"
+#include "src/math/hypotf16.h"
+#include "test/UnitTest/FPMatcher.h"
+#include "utils/MPFRWrapper/MPFRUtils.h"
+
+namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
+
+// Range of both inputs: [0, inf]
+static constexpr uint16_t START = 0x0000U;
+static constexpr uint16_t STOP = 0x7C00U;
+
+struct Hypotf16Checker : public virtual LIBC_NAMESPACE::testing::Test {
+ using FloatType = float16;
+ using FPBits = LIBC_NAMESPACE::fputil::FPBits<float16>;
+ using StorageType = typename FPBits::StorageType;
+
+ uint64_t check(uint16_t start, uint16_t stop, mpfr::RoundingMode rounding) {
+ mpfr::ForceRoundingMode r(rounding);
+ if (!r.success)
+ return true;
+ uint16_t xbits = start;
+ uint64_t failed = 0;
+ do {
+ float16 x = FPBits(xbits).get_val();
+ uint16_t ybits = xbits;
+ do {
+ float16 y = FPBits(ybits).get_val();
+ bool correct = TEST_FP_EQ(LIBC_NAMESPACE::fputil::hypot(x, y),
+ LIBC_NAMESPACE::hypotf16(x, y));
+ // Using MPFR will be much slower.
+ // mpfr::BinaryInput<float16> input{x, y};
+ // bool correct = TEST_MPFR_MATCH_ROUNDING_SILENTLY(
+ // mpfr::Operation::Hypot, input, LIBC_NAMESPACE::hypotf16(x, y), 0.5,
+ // rounding);
+ failed += (!correct);
+ } while (ybits++ < STOP);
+ } while (xbits++ < stop);
+ return failed;
+ }
+};
+
+using LlvmLibcHypotf16ExhaustiveTest = LlvmLibcExhaustiveMathTest<Hypotf16Checker>;
+
+TEST_F(LlvmLibcHypotf16ExhaustiveTest, PositiveRange) {
+ test_full_range_all_roundings(START, STOP);
+}
diff --git a/libc/test/src/math/hypotf16_test.cpp b/libc/test/src/math/hypotf16_test.cpp
new file mode 100644
index 0000000000000..28ac9683876a6
--- /dev/null
+++ b/libc/test/src/math/hypotf16_test.cpp
@@ -0,0 +1,27 @@
+//===-- Unittests for hypotf16 --------------------------------------------===//
+//
+// 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 "HypotTest.h"
+#include "hypotf_hard_to_round.h"
+
+#include "src/math/hypotf16.h"
+
+using LlvmLibcHypotf16Test = HypotTestTemplate<float16>;
+
+// TEST_F(LlvmLibcHypotf16Test, SubnormalRange) {
+// test_subnormal_range(&LIBC_NAMESPACE::hypotf16);
+// }
+//
+// TEST_F(LlvmLibcHypotf16Test, NormalRange) {
+// test_normal_range(&LIBC_NAMESPACE::hypotf16);
+// }
+//
+// TEST_F(LlvmLibcHypotf16Test, TrickyInputs) {
+// test_input_list(&LIBC_NAMESPACE::hypotf16, N_HARD_TO_ROUND,
+// HYPOTF_HARD_TO_ROUND);
+// }
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index 6f94440d826d9..639fe9590ef39 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -3121,6 +3121,20 @@ add_fp_unittest(
libc.src.__support.macros.properties.architectures
)
+add_fp_unittest(
+ hypotf16_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ hypotf16_test.cpp
+ HDRS
+ HypotTest.h
+ DEPENDS
+ libc.src.math.hypotf16
+ libc.src.__support.FPUtil.fp_bits
+ libc.src.__support.macros.properties.architectures
+)
+
add_fp_unittest(
hypot_test
SUITE
diff --git a/libc/test/src/math/smoke/hypotf16_test.cpp b/libc/test/src/math/smoke/hypotf16_test.cpp
new file mode 100644
index 0000000000000..5e9d987b6dbd6
--- /dev/null
+++ b/libc/test/src/math/smoke/hypotf16_test.cpp
@@ -0,0 +1,33 @@
+//===-- Unittests for hypotf16 --------------------------------------------===//
+//
+// 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 "src/errno/libc_errno.h"
+#include "test/UnitTest/FPMatcher.h"
+#include "test/UnitTest/Test.h"
+#include "src/math/hypotf16.h"
+
+using LlvmLibcHypotf16Test = LIBC_NAMESPACE::testing::FPTest<float16>;
+
+TEST_F(LlvmLibcHypotf16Test, SpecialNumbers) {
+ LIBC_NAMESPACE::libc_errno = 0;
+ EXPECT_FP_EQ(inf, LIBC_NAMESPACE::hypotf16(inf, aNaN));
+ EXPECT_MATH_ERRNO(0);
+ EXPECT_FP_EQ(inf, LIBC_NAMESPACE::hypotf16(aNaN, neg_inf));
+ EXPECT_MATH_ERRNO(0);
+ EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::hypotf16(aNaN, aNaN));
+ EXPECT_MATH_ERRNO(0);
+ EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::hypotf16(sNaN, zero));
+ EXPECT_MATH_ERRNO(0);
+ EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::hypotf16(neg_zero, sNaN));
+ EXPECT_MATH_ERRNO(0);
+
+ EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, LIBC_NAMESPACE::hypotf16(inf, sNaN), FE_INVALID);
+ EXPECT_MATH_ERRNO(0);
+ EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, LIBC_NAMESPACE::hypotf16(sNaN, neg_inf), FE_INVALID);
+ EXPECT_MATH_ERRNO(0);
+}
>From 483ce41e5ae10f4757bcdb6a0cd14ae178dea160 Mon Sep 17 00:00:00 2001
From: meltq <alissxlace at proton.me>
Date: Wed, 19 Mar 2025 15:22:34 +0530
Subject: [PATCH 2/3] Formatting changes
---
libc/src/math/generic/hypotf16.cpp | 6 +++---
libc/test/src/math/exhaustive/hypotf16_test.cpp | 3 ++-
libc/test/src/math/smoke/hypotf16_test.cpp | 8 +++++---
3 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/libc/src/math/generic/hypotf16.cpp b/libc/src/math/generic/hypotf16.cpp
index c827c0d8a513f..75323c5cf5aa8 100644
--- a/libc/src/math/generic/hypotf16.cpp
+++ b/libc/src/math/generic/hypotf16.cpp
@@ -9,12 +9,12 @@
#include "src/math/hypotf16.h"
#include "src/__support/FPUtil/FEnvImpl.h"
#include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/FPUtil/cast.h"
#include "src/__support/FPUtil/multiply_add.h"
#include "src/__support/FPUtil/sqrt.h"
#include "src/__support/common.h"
-#include "src/__support/macros/properties/types.h"
#include "src/__support/macros/optimization.h"
-#include "src/__support/FPUtil/cast.h"
+#include "src/__support/macros/properties/types.h"
namespace LIBC_NAMESPACE_DECL {
@@ -83,4 +83,4 @@ LLVM_LIBC_FUNCTION(float16, hypotf16, (float16 x, float16 y)) {
return fputil::cast<float16>(result.get_val());
}
-}
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/src/math/exhaustive/hypotf16_test.cpp b/libc/test/src/math/exhaustive/hypotf16_test.cpp
index 085504398deac..a13f2e4a1bd05 100644
--- a/libc/test/src/math/exhaustive/hypotf16_test.cpp
+++ b/libc/test/src/math/exhaustive/hypotf16_test.cpp
@@ -49,7 +49,8 @@ struct Hypotf16Checker : public virtual LIBC_NAMESPACE::testing::Test {
}
};
-using LlvmLibcHypotf16ExhaustiveTest = LlvmLibcExhaustiveMathTest<Hypotf16Checker>;
+using LlvmLibcHypotf16ExhaustiveTest =
+ LlvmLibcExhaustiveMathTest<Hypotf16Checker>;
TEST_F(LlvmLibcHypotf16ExhaustiveTest, PositiveRange) {
test_full_range_all_roundings(START, STOP);
diff --git a/libc/test/src/math/smoke/hypotf16_test.cpp b/libc/test/src/math/smoke/hypotf16_test.cpp
index 5e9d987b6dbd6..d56cdc457a134 100644
--- a/libc/test/src/math/smoke/hypotf16_test.cpp
+++ b/libc/test/src/math/smoke/hypotf16_test.cpp
@@ -7,9 +7,9 @@
//===----------------------------------------------------------------------===//
#include "src/errno/libc_errno.h"
+#include "src/math/hypotf16.h"
#include "test/UnitTest/FPMatcher.h"
#include "test/UnitTest/Test.h"
-#include "src/math/hypotf16.h"
using LlvmLibcHypotf16Test = LIBC_NAMESPACE::testing::FPTest<float16>;
@@ -26,8 +26,10 @@ TEST_F(LlvmLibcHypotf16Test, SpecialNumbers) {
EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::hypotf16(neg_zero, sNaN));
EXPECT_MATH_ERRNO(0);
- EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, LIBC_NAMESPACE::hypotf16(inf, sNaN), FE_INVALID);
+ EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, LIBC_NAMESPACE::hypotf16(inf, sNaN),
+ FE_INVALID);
EXPECT_MATH_ERRNO(0);
- EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, LIBC_NAMESPACE::hypotf16(sNaN, neg_inf), FE_INVALID);
+ EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, LIBC_NAMESPACE::hypotf16(sNaN, neg_inf),
+ FE_INVALID);
EXPECT_MATH_ERRNO(0);
}
>From 67d93c8c1ae2232666839380983a5accb75f2bd0 Mon Sep 17 00:00:00 2001
From: meltq <alissxlace at proton.me>
Date: Thu, 20 Mar 2025 11:15:17 +0530
Subject: [PATCH 3/3] Temp removed exhaustive
---
.../src/math/exhaustive/hypotf16_test.cpp | 98 +++++++++----------
1 file changed, 49 insertions(+), 49 deletions(-)
diff --git a/libc/test/src/math/exhaustive/hypotf16_test.cpp b/libc/test/src/math/exhaustive/hypotf16_test.cpp
index a13f2e4a1bd05..c552ce973489c 100644
--- a/libc/test/src/math/exhaustive/hypotf16_test.cpp
+++ b/libc/test/src/math/exhaustive/hypotf16_test.cpp
@@ -6,52 +6,52 @@
//
//===----------------------------------------------------------------------===//
-#include "exhaustive_test.h"
-#include "src/__support/FPUtil/FPBits.h"
-#include "src/__support/FPUtil/Hypot.h"
-#include "src/math/hypotf16.h"
-#include "test/UnitTest/FPMatcher.h"
-#include "utils/MPFRWrapper/MPFRUtils.h"
-
-namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
-
-// Range of both inputs: [0, inf]
-static constexpr uint16_t START = 0x0000U;
-static constexpr uint16_t STOP = 0x7C00U;
-
-struct Hypotf16Checker : public virtual LIBC_NAMESPACE::testing::Test {
- using FloatType = float16;
- using FPBits = LIBC_NAMESPACE::fputil::FPBits<float16>;
- using StorageType = typename FPBits::StorageType;
-
- uint64_t check(uint16_t start, uint16_t stop, mpfr::RoundingMode rounding) {
- mpfr::ForceRoundingMode r(rounding);
- if (!r.success)
- return true;
- uint16_t xbits = start;
- uint64_t failed = 0;
- do {
- float16 x = FPBits(xbits).get_val();
- uint16_t ybits = xbits;
- do {
- float16 y = FPBits(ybits).get_val();
- bool correct = TEST_FP_EQ(LIBC_NAMESPACE::fputil::hypot(x, y),
- LIBC_NAMESPACE::hypotf16(x, y));
- // Using MPFR will be much slower.
- // mpfr::BinaryInput<float16> input{x, y};
- // bool correct = TEST_MPFR_MATCH_ROUNDING_SILENTLY(
- // mpfr::Operation::Hypot, input, LIBC_NAMESPACE::hypotf16(x, y), 0.5,
- // rounding);
- failed += (!correct);
- } while (ybits++ < STOP);
- } while (xbits++ < stop);
- return failed;
- }
-};
-
-using LlvmLibcHypotf16ExhaustiveTest =
- LlvmLibcExhaustiveMathTest<Hypotf16Checker>;
-
-TEST_F(LlvmLibcHypotf16ExhaustiveTest, PositiveRange) {
- test_full_range_all_roundings(START, STOP);
-}
+// #include "exhaustive_test.h"
+// #include "src/__support/FPUtil/FPBits.h"
+// #include "src/__support/FPUtil/Hypot.h"
+// #include "src/math/hypotf16.h"
+// #include "test/UnitTest/FPMatcher.h"
+// #include "utils/MPFRWrapper/MPFRUtils.h"
+//
+// namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
+//
+// // Range of both inputs: [0, inf]
+// static constexpr uint16_t START = 0x0000U;
+// static constexpr uint16_t STOP = 0x7C00U;
+//
+// struct Hypotf16Checker : public virtual LIBC_NAMESPACE::testing::Test {
+// using FloatType = float16;
+// using FPBits = LIBC_NAMESPACE::fputil::FPBits<float16>;
+// using StorageType = typename FPBits::StorageType;
+//
+// uint64_t check(uint16_t start, uint16_t stop, mpfr::RoundingMode rounding) {
+// mpfr::ForceRoundingMode r(rounding);
+// if (!r.success)
+// return true;
+// uint16_t xbits = start;
+// uint64_t failed = 0;
+// do {
+// float16 x = FPBits(xbits).get_val();
+// uint16_t ybits = xbits;
+// do {
+// float16 y = FPBits(ybits).get_val();
+// bool correct = TEST_FP_EQ(LIBC_NAMESPACE::fputil::hypot(x, y),
+// LIBC_NAMESPACE::hypotf16(x, y));
+// // Using MPFR will be much slower.
+// // mpfr::BinaryInput<float16> input{x, y};
+// // bool correct = TEST_MPFR_MATCH_ROUNDING_SILENTLY(
+// // mpfr::Operation::Hypot, input, LIBC_NAMESPACE::hypotf16(x, y), 0.5,
+// // rounding);
+// failed += (!correct);
+// } while (ybits++ < STOP);
+// } while (xbits++ < stop);
+// return failed;
+// }
+// };
+//
+// using LlvmLibcHypotf16ExhaustiveTest =
+// LlvmLibcExhaustiveMathTest<Hypotf16Checker>;
+//
+// TEST_F(LlvmLibcHypotf16ExhaustiveTest, PositiveRange) {
+// test_full_range_all_roundings(START, STOP);
+// }
More information about the libc-commits
mailing list