[libc] [llvm] [libc][math][c23] Add hypotbf16 function (PR #183460)
Muhammad Bassiouni via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 2 14:54:29 PST 2026
https://github.com/bassiounix updated https://github.com/llvm/llvm-project/pull/183460
>From 3337d8375a68ee72b84af961804ad3ee564ae79d Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Wed, 25 Feb 2026 10:06:58 +0530
Subject: [PATCH 01/30] configs
---
libc/config/baremetal/aarch64/entrypoints.txt | 1 +
libc/config/baremetal/arm/entrypoints.txt | 1 +
libc/config/baremetal/riscv/entrypoints.txt | 1 +
libc/config/darwin/aarch64/entrypoints.txt | 1 +
libc/config/darwin/x86_64/entrypoints.txt | 1 +
libc/config/gpu/amdgpu/entrypoints.txt | 1 +
libc/config/gpu/nvptx/entrypoints.txt | 1 +
libc/config/linux/aarch64/entrypoints.txt | 1 +
libc/config/linux/arm/entrypoints.txt | 1 +
libc/config/linux/riscv/entrypoints.txt | 1 +
libc/config/linux/x86_64/entrypoints.txt | 1 +
libc/config/windows/entrypoints.txt | 1 +
12 files changed, 12 insertions(+)
diff --git a/libc/config/baremetal/aarch64/entrypoints.txt b/libc/config/baremetal/aarch64/entrypoints.txt
index 1c04ee2b6d040..6b145fb6fe43f 100644
--- a/libc/config/baremetal/aarch64/entrypoints.txt
+++ b/libc/config/baremetal/aarch64/entrypoints.txt
@@ -449,6 +449,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.getpayloadf
libc.src.math.getpayloadl
libc.src.math.hypot
+ libc.src.math.hypotbf16
libc.src.math.hypotf
libc.src.math.ilogb
libc.src.math.ilogbf
diff --git a/libc/config/baremetal/arm/entrypoints.txt b/libc/config/baremetal/arm/entrypoints.txt
index ad6b6d922b57a..a26f92c418fbc 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -452,6 +452,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.getpayloadf
libc.src.math.getpayloadl
libc.src.math.hypot
+ libc.src.math.hypotbf16
libc.src.math.hypotf
libc.src.math.ilogb
libc.src.math.ilogbf
diff --git a/libc/config/baremetal/riscv/entrypoints.txt b/libc/config/baremetal/riscv/entrypoints.txt
index 29be47dfbfd53..adf597c8ff3d5 100644
--- a/libc/config/baremetal/riscv/entrypoints.txt
+++ b/libc/config/baremetal/riscv/entrypoints.txt
@@ -450,6 +450,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.getpayloadf
libc.src.math.getpayloadl
libc.src.math.hypot
+ libc.src.math.hypotbf16
libc.src.math.hypotf
libc.src.math.ilogb
libc.src.math.ilogbf
diff --git a/libc/config/darwin/aarch64/entrypoints.txt b/libc/config/darwin/aarch64/entrypoints.txt
index b4a1ee70764cb..eac6a448ed5b8 100644
--- a/libc/config/darwin/aarch64/entrypoints.txt
+++ b/libc/config/darwin/aarch64/entrypoints.txt
@@ -265,6 +265,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.getpayloadf
libc.src.math.getpayloadl
libc.src.math.hypot
+ libc.src.math.hypotbf16
libc.src.math.hypotf
libc.src.math.ilogb
libc.src.math.ilogbf
diff --git a/libc/config/darwin/x86_64/entrypoints.txt b/libc/config/darwin/x86_64/entrypoints.txt
index e899bf97ea3f6..3d205b5a10895 100644
--- a/libc/config/darwin/x86_64/entrypoints.txt
+++ b/libc/config/darwin/x86_64/entrypoints.txt
@@ -162,6 +162,7 @@ set(TARGET_LIBM_ENTRYPOINTS
#libc.src.math.fsub
#libc.src.math.fsubl
#libc.src.math.hypot
+ #libc.src.math.hypotbf16
#libc.src.math.hypotf
#libc.src.math.ilogb
#libc.src.math.ilogbf
diff --git a/libc/config/gpu/amdgpu/entrypoints.txt b/libc/config/gpu/amdgpu/entrypoints.txt
index a65b6f0274fd8..c16d478d64d18 100644
--- a/libc/config/gpu/amdgpu/entrypoints.txt
+++ b/libc/config/gpu/amdgpu/entrypoints.txt
@@ -392,6 +392,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.getpayloadf
libc.src.math.getpayloadl
libc.src.math.hypot
+ libc.src.math.hypotbf16
libc.src.math.hypotf
libc.src.math.ilogb
libc.src.math.ilogbf
diff --git a/libc/config/gpu/nvptx/entrypoints.txt b/libc/config/gpu/nvptx/entrypoints.txt
index fee0038c88cc0..31f84940dfb6f 100644
--- a/libc/config/gpu/nvptx/entrypoints.txt
+++ b/libc/config/gpu/nvptx/entrypoints.txt
@@ -393,6 +393,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.getpayloadf
libc.src.math.getpayloadl
libc.src.math.hypot
+ libc.src.math.hypotbf16
libc.src.math.hypotf
libc.src.math.ilogb
libc.src.math.ilogbf
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 960958b7cf90a..cb417b3ba1242 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -530,6 +530,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.getpayloadf
libc.src.math.getpayloadl
libc.src.math.hypot
+ libc.src.math.hypotbf16
libc.src.math.hypotf
libc.src.math.ilogb
libc.src.math.ilogbf
diff --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt
index e76bf81670ce5..c54e1f3a0eccb 100644
--- a/libc/config/linux/arm/entrypoints.txt
+++ b/libc/config/linux/arm/entrypoints.txt
@@ -351,6 +351,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.getpayloadf
libc.src.math.getpayloadl
libc.src.math.hypot
+ libc.src.math.hypotbf16
libc.src.math.hypotf
libc.src.math.ilogb
libc.src.math.ilogbf
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index a69d1a1b0a642..3ff7a6aafe13d 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -539,6 +539,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.getpayloadf
libc.src.math.getpayloadl
libc.src.math.hypot
+ libc.src.math.hypotbf16
libc.src.math.hypotf
libc.src.math.ilogb
libc.src.math.ilogbf
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index bb4973628d588..cd3552734d7ae 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -581,6 +581,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.getpayloadf
libc.src.math.getpayloadl
libc.src.math.hypot
+ libc.src.math.hypotbf16
libc.src.math.hypotf
libc.src.math.ilogb
libc.src.math.ilogbf
diff --git a/libc/config/windows/entrypoints.txt b/libc/config/windows/entrypoints.txt
index f777fc6c94bc2..17add91cdcecf 100644
--- a/libc/config/windows/entrypoints.txt
+++ b/libc/config/windows/entrypoints.txt
@@ -224,6 +224,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.fsub
libc.src.math.fsubl
libc.src.math.hypot
+ libc.src.math.hypotbf16
libc.src.math.hypotf
libc.src.math.ilogb
libc.src.math.ilogbf
>From 1a2a148ee222c17450c8c8bfad396ce014501a98 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Wed, 25 Feb 2026 10:30:19 +0530
Subject: [PATCH 02/30] initial
---
libc/src/math/generic/CMakeLists.txt | 11 +++++++++++
libc/src/math/generic/hypotbf16.cpp | 18 ++++++++++++++++++
2 files changed, 29 insertions(+)
create mode 100644 libc/src/math/generic/hypotbf16.cpp
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index f8ec25be61d12..3bc0b9aa39491 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -3016,6 +3016,17 @@ add_entrypoint_object(
libc.src.__support.macros.config
)
+add_entrypoint_object(
+ hypotbf16
+ SRCS
+ hypotbf16.cpp
+ HDRS
+ ../hypotbf16.h
+ DEPENDS
+ libc.src.__support.math.hypotbf16
+ libc.src.math.hypotbf16
+)
+
add_entrypoint_object(
hypotf
SRCS
diff --git a/libc/src/math/generic/hypotbf16.cpp b/libc/src/math/generic/hypotbf16.cpp
new file mode 100644
index 0000000000000..78ecc51dfb4ce
--- /dev/null
+++ b/libc/src/math/generic/hypotbf16.cpp
@@ -0,0 +1,18 @@
+//===-- Implementation of hypotbf16 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/hypotbf16.h"
+#include "src/__support/math/hypotbf16.h"
+#include "src/__support/FPUtil/bfloat16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(BFloat16, hypotf, (BFloat16 x, BFloat16 y)) {
+ return math::hypotf(x, y);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
>From b2690111e837244336cdb6b357099cd854fa984d Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Thu, 26 Feb 2026 00:13:08 +0530
Subject: [PATCH 03/30] exhaustive test added [positive range + special] +
implemented +smoke tests
---
libc/docs/headers/math/index.rst | 2 +-
libc/src/__support/math/hypotbf16.h | 102 ++++++++++++++++++++
libc/src/math/CMakeLists.txt | 1 +
libc/src/math/generic/hypotbf16.cpp | 6 +-
libc/src/math/hypotbf16.h | 21 ++++
libc/test/src/math/CMakeLists.txt | 13 +++
libc/test/src/math/hypotbf16_test.cpp | 52 ++++++++++
libc/test/src/math/smoke/CMakeLists.txt | 13 +++
libc/test/src/math/smoke/hypotbf16_test.cpp | 17 ++++
libc/utils/MPFRWrapper/MPFRUtils.cpp | 4 +-
10 files changed, 225 insertions(+), 6 deletions(-)
create mode 100644 libc/src/__support/math/hypotbf16.h
create mode 100644 libc/src/math/hypotbf16.h
create mode 100644 libc/test/src/math/hypotbf16_test.cpp
create mode 100644 libc/test/src/math/smoke/hypotbf16_test.cpp
diff --git a/libc/docs/headers/math/index.rst b/libc/docs/headers/math/index.rst
index 7ea54fb4d8263..8aed342628e00 100644
--- a/libc/docs/headers/math/index.rst
+++ b/libc/docs/headers/math/index.rst
@@ -319,7 +319,7 @@ Higher Math Functions
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
| fsqrt | N/A | |check| | |check| | N/A | |check|\* | | 7.12.14.6 | F.10.11 |
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| hypot | |check| | |check| | | |check| | | | 7.12.7.4 | F.10.4.4 |
+| hypot | |check| | |check| | | |check| | | |check| | 7.12.7.4 | F.10.4.4 |
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
| lgamma | | | | | | | 7.12.8.3 | F.10.5.3 |
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
diff --git a/libc/src/__support/math/hypotbf16.h b/libc/src/__support/math/hypotbf16.h
new file mode 100644
index 0000000000000..476021386b535
--- /dev/null
+++ b/libc/src/__support/math/hypotbf16.h
@@ -0,0 +1,102 @@
+//===-- Implementation header for hypotbf16 ---------------------*- 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___SUPPORT_MATH_HYPOTBF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_HYPOTBF16_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/optimization.h"
+#include "src/__support/macros/properties/types.h"
+#include "src/__support/FPUtil/bfloat16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+constexpr bfloat16 zero = bfloat16(0.0f);
+
+// For targets where conversion from float to float16 has to be
+// emulated, fputil::hypot<float16> is faster
+LIBC_INLINE bfloat16 hypotbf16(bfloat16 x, bfloat16 y) {
+ using FloatBits = fputil::FPBits<bfloat16>;
+ using FPBits = fputil::FPBits<bfloat16>;
+
+ 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();
+ }
+
+ bfloat16 af = fputil::cast<bfloat16>(a_bits.get_val());
+ bfloat16 bf = fputil::cast<bfloat16>(b_bits.get_val());
+
+ // Compiler runtime basic operations for float16 might not be correctly
+ // rounded for all rounding modes.
+ if (LIBC_UNLIKELY(a_u - b_u >=
+ static_cast<uint16_t>((FPBits::FRACTION_LEN + 2)
+ << FPBits::FRACTION_LEN)))
+ return fputil::cast<bfloat16>(af + bf);
+
+ // These squares are exact.
+ bfloat16 a_sq = af * af;
+ bfloat16 sum_sq = fputil::multiply_add(bf, bf, a_sq);
+
+ FloatBits result(fputil::sqrt<bfloat16>(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)) {
+ bfloat16 r_d = result.get_val();
+
+ // Perform rounding correction.
+ bfloat16 sum_sq_lo = fputil::multiply_add(bf, bf, a_sq - sum_sq);
+ bfloat16 err = sum_sq_lo - fputil::multiply_add(r_d, r_d, -sum_sq);
+
+ if (err > zero ) {
+ r_u |= 1;
+ } else if ((err < zero) && (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<bfloat16>(FloatBits(r_u).get_val());
+ }
+
+ return fputil::cast<bfloat16>(result.get_val());
+}
+
+} // namespace math
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_HYPOTBF16_H
diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index e617950368994..a99e965433e77 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -345,6 +345,7 @@ add_math_entrypoint_object(getpayloadf128)
add_math_entrypoint_object(getpayloadbf16)
add_math_entrypoint_object(hypot)
+add_math_entrypoint_object(hypotbf16)
add_math_entrypoint_object(hypotf)
add_math_entrypoint_object(hypotf16)
diff --git a/libc/src/math/generic/hypotbf16.cpp b/libc/src/math/generic/hypotbf16.cpp
index 78ecc51dfb4ce..49dd5d1f91ad2 100644
--- a/libc/src/math/generic/hypotbf16.cpp
+++ b/libc/src/math/generic/hypotbf16.cpp
@@ -1,4 +1,4 @@
-//===-- Implementation of hypotbf16 function -------------------------------===//
+//===-- Implementation of hypotbf16 function ------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -11,8 +11,8 @@
namespace LIBC_NAMESPACE_DECL {
-LLVM_LIBC_FUNCTION(BFloat16, hypotf, (BFloat16 x, BFloat16 y)) {
- return math::hypotf(x, y);
+LLVM_LIBC_FUNCTION(bfloat16, hypotbf16, (bfloat16 x, bfloat16 y)) {
+ return math::hypotbf16(x, y);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/hypotbf16.h b/libc/src/math/hypotbf16.h
new file mode 100644
index 0000000000000..db1365d791dba
--- /dev/null
+++ b/libc/src/math/hypotbf16.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for hypotbf16 ---------------------*- 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_HYPOTBF16_H
+#define LLVM_LIBC_SRC_MATH_HYPOTBF16_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+bfloat16 hypotbf16(bfloat16 x, bfloat16 y);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_HYPOTBF16_H
diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt
index 73b5ebf5a856e..175122e5fde29 100644
--- a/libc/test/src/math/CMakeLists.txt
+++ b/libc/test/src/math/CMakeLists.txt
@@ -1896,6 +1896,19 @@ add_fp_unittest(
libc.src.__support.FPUtil.fp_bits
)
+add_fp_unittest(
+ hypotbf16_test
+ NEED_MPFR
+ SUITE
+ libc-math-unittests
+ SRCS
+ hypotbf16_test.cpp
+ DEPENDS
+ libc.src.math.hypotbf16
+ libc.src.__support.FPUtil.fp_bits
+ libc.src.__support.FPUtil.bfloat16
+)
+
add_fp_unittest(
hypotf16_test
NEED_MPFR
diff --git a/libc/test/src/math/hypotbf16_test.cpp b/libc/test/src/math/hypotbf16_test.cpp
new file mode 100644
index 0000000000000..895e52aa51bde
--- /dev/null
+++ b/libc/test/src/math/hypotbf16_test.cpp
@@ -0,0 +1,52 @@
+//===-- Exhaustive test for hypotbf16 -------------------------------------===//
+//
+// 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 "src/math/hypotbf16.h"
+#include "src/__support/FPUtil/bfloat16.h"
+#include "test/UnitTest/FPMatcher.h"
+#include "test/UnitTest/Test.h"
+#include "utils/MPFRWrapper/MPFRUtils.h"
+
+using LlvmLibcHypotBf16Test = LIBC_NAMESPACE::testing::FPTest<bfloat16>;
+
+namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
+
+// range: [+0, inf]
+static constexpr uint16_t POS_START = 0x0000U;
+static constexpr uint16_t POS_STOP = 0x7f80U;
+
+// x+y = y+x
+TEST_F(LlvmLibcHypotBf16Test, PositiveRange){
+ for(uint16_t v1 = POS_START; v1<= POS_STOP; ++v1){
+ for(uint16_t v2 = v1; v2<=POS_STOP; ++v2){
+ bfloat16 x = FPBits(x).get_val();
+ bfloat16 y = FPBits(y).get_val();
+ mpfr::BinaryInput<bfloat16> input{x,y};
+ EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Hypot, input,LIBC_NAMESPACE::hypotbf16(x, y),0.5);
+ }
+ }
+}
+
+TEST_F(LlvmLibcHypotBf16Test, SpecialNumbers){
+ constexpr bfloat16 VAL[] = {zero, neg_zero, inf,
+ neg_inf, min_normal, max_normal};
+ for(size_t v1 = 0; v1< 6; ++v1){
+ for(uint16_t v2 = v1 ; v2< 6; ++v2){
+
+ bfloat16 x = VAL[v1];
+ bfloat16 y = VAL[v2];
+ mpfr::BinaryInput<bfloat16> input{x,y};
+ EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Hypot, input,LIBC_NAMESPACE::hypotbf16(x, y),0.5);
+ }
+ }
+}
+
+
+
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index 3d52873c40bb8..5f87aaf990741 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -3743,6 +3743,19 @@ add_fp_unittest(
libc.src.__support.macros.properties.architectures
)
+add_fp_unittest(
+ hypotbf16_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ hypotbf16_test.cpp
+ HDRS
+ HypotTest.h
+ DEPENDS
+ libc.src.math.hypotbf16
+ libc.src.__support.FPUtil.bfloat16
+)
+
add_fp_unittest(
nanf_test
SUITE
diff --git a/libc/test/src/math/smoke/hypotbf16_test.cpp b/libc/test/src/math/smoke/hypotbf16_test.cpp
new file mode 100644
index 0000000000000..07ae3938ccc7c
--- /dev/null
+++ b/libc/test/src/math/smoke/hypotbf16_test.cpp
@@ -0,0 +1,17 @@
+//===-- Unittests for hypotbf16 -------------------------------------------===//
+//
+// 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 "src/math/hypotbf16.h"
+
+using LlvmLibcHypotbf16Test = HypotTestTemplate<bfloat16>;
+
+TEST_F(LlvmLibcHypotbf16Test, SpecialNumbers) {
+ test_special_numbers(&LIBC_NAMESPACE::hypotbf16);
+}
diff --git a/libc/utils/MPFRWrapper/MPFRUtils.cpp b/libc/utils/MPFRWrapper/MPFRUtils.cpp
index a7d307b47c3e8..c61ef66c803eb 100644
--- a/libc/utils/MPFRWrapper/MPFRUtils.cpp
+++ b/libc/utils/MPFRWrapper/MPFRUtils.cpp
@@ -408,8 +408,8 @@ template void explain_binary_operation_one_output_error(
Operation, const BinaryInput<float16> &, float16, double, RoundingMode);
template void
explain_binary_operation_one_output_error(Operation, const BinaryInput<float> &,
- float16, double, RoundingMode);
-template void explain_binary_operation_one_output_error(
+ explain_binary_operation_one_output_error float16, double, RoundingMode);
+template void (
Operation, const BinaryInput<double> &, float16, double, RoundingMode);
template void explain_binary_operation_one_output_error(
Operation, const BinaryInput<long double> &, float16, double, RoundingMode);
>From ddd3f688cd7e9b443381159f20e98b4bd2832e01 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Thu, 26 Feb 2026 00:13:49 +0530
Subject: [PATCH 04/30] formatted
cmake
fix: CMake
ref itself
fixed 16/32
reset MPFRUtils
header added
formatted
HypotTest.h dosent work for smoke
size_t change
MPFR
Cmake
spell
testing with lower than 2^32
formatted
true exhaustive will be moved to math/exhaustive
formatted
testing the already available FPUtil hypot
formatted
cmaked updated
test
cmake updated
typo
spell
stack
---
libc/src/__support/math/CMakeLists.txt | 1 +
libc/src/__support/math/hypotbf16.h | 102 --------------------
libc/src/math/generic/CMakeLists.txt | 6 +-
libc/src/math/generic/hypotbf16.cpp | 10 +-
libc/test/src/math/hypotbf16_test.cpp | 44 ++-------
libc/test/src/math/smoke/CMakeLists.txt | 3 +
libc/test/src/math/smoke/hypotbf16_test.cpp | 26 ++++-
libc/utils/MPFRWrapper/MPFRUtils.cpp | 4 +-
8 files changed, 45 insertions(+), 151 deletions(-)
delete mode 100644 libc/src/__support/math/hypotbf16.h
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 3bb8e76a54bfb..0c26115cd8f13 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -1932,6 +1932,7 @@ add_header_library(
libc.src.__support.FPUtil.multiply_add
libc.src.__support.FPUtil.sqrt
libc.src.__support.macros.optimization
+ libc.sec.__support.FPUtil.bfloat16
)
add_header_library(
diff --git a/libc/src/__support/math/hypotbf16.h b/libc/src/__support/math/hypotbf16.h
deleted file mode 100644
index 476021386b535..0000000000000
--- a/libc/src/__support/math/hypotbf16.h
+++ /dev/null
@@ -1,102 +0,0 @@
-//===-- Implementation header for hypotbf16 ---------------------*- 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___SUPPORT_MATH_HYPOTBF16_H
-#define LLVM_LIBC_SRC___SUPPORT_MATH_HYPOTBF16_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/optimization.h"
-#include "src/__support/macros/properties/types.h"
-#include "src/__support/FPUtil/bfloat16.h"
-
-namespace LIBC_NAMESPACE_DECL {
-
-namespace math {
-
-constexpr bfloat16 zero = bfloat16(0.0f);
-
-// For targets where conversion from float to float16 has to be
-// emulated, fputil::hypot<float16> is faster
-LIBC_INLINE bfloat16 hypotbf16(bfloat16 x, bfloat16 y) {
- using FloatBits = fputil::FPBits<bfloat16>;
- using FPBits = fputil::FPBits<bfloat16>;
-
- 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();
- }
-
- bfloat16 af = fputil::cast<bfloat16>(a_bits.get_val());
- bfloat16 bf = fputil::cast<bfloat16>(b_bits.get_val());
-
- // Compiler runtime basic operations for float16 might not be correctly
- // rounded for all rounding modes.
- if (LIBC_UNLIKELY(a_u - b_u >=
- static_cast<uint16_t>((FPBits::FRACTION_LEN + 2)
- << FPBits::FRACTION_LEN)))
- return fputil::cast<bfloat16>(af + bf);
-
- // These squares are exact.
- bfloat16 a_sq = af * af;
- bfloat16 sum_sq = fputil::multiply_add(bf, bf, a_sq);
-
- FloatBits result(fputil::sqrt<bfloat16>(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)) {
- bfloat16 r_d = result.get_val();
-
- // Perform rounding correction.
- bfloat16 sum_sq_lo = fputil::multiply_add(bf, bf, a_sq - sum_sq);
- bfloat16 err = sum_sq_lo - fputil::multiply_add(r_d, r_d, -sum_sq);
-
- if (err > zero ) {
- r_u |= 1;
- } else if ((err < zero) && (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<bfloat16>(FloatBits(r_u).get_val());
- }
-
- return fputil::cast<bfloat16>(result.get_val());
-}
-
-} // namespace math
-
-} // namespace LIBC_NAMESPACE_DECL
-
-#endif // LLVM_LIBC_SRC___SUPPORT_MATH_HYPOTBF16_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 3bc0b9aa39491..ba97a5c59401b 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -3023,8 +3023,10 @@ add_entrypoint_object(
HDRS
../hypotbf16.h
DEPENDS
- libc.src.__support.math.hypotbf16
- libc.src.math.hypotbf16
+ libc.src.__support.FPUtil.hypot
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.common
+ libc.src.__support.macros.config
)
add_entrypoint_object(
diff --git a/libc/src/math/generic/hypotbf16.cpp b/libc/src/math/generic/hypotbf16.cpp
index 49dd5d1f91ad2..52c9d88f681cd 100644
--- a/libc/src/math/generic/hypotbf16.cpp
+++ b/libc/src/math/generic/hypotbf16.cpp
@@ -5,14 +5,18 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
-#include "src/math/hypotbf16.h"
-#include "src/__support/math/hypotbf16.h"
+
+#include "src/__support/FPUtil/Hypot.h"
#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+#include "src/math/hypotbf16.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(bfloat16, hypotbf16, (bfloat16 x, bfloat16 y)) {
- return math::hypotbf16(x, y);
+ return fputil::hypot<bfloat16>(x, y);
}
+
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/src/math/hypotbf16_test.cpp b/libc/test/src/math/hypotbf16_test.cpp
index 895e52aa51bde..dd36b7513d22d 100644
--- a/libc/test/src/math/hypotbf16_test.cpp
+++ b/libc/test/src/math/hypotbf16_test.cpp
@@ -1,4 +1,4 @@
-//===-- Exhaustive test for hypotbf16 -------------------------------------===//
+//===-- Exhaustive tests for hypotbf16 ------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -8,45 +8,15 @@
#include "HypotTest.h"
-#include "src/math/hypotbf16.h"
#include "src/__support/FPUtil/bfloat16.h"
-#include "test/UnitTest/FPMatcher.h"
-#include "test/UnitTest/Test.h"
-#include "utils/MPFRWrapper/MPFRUtils.h"
-
-using LlvmLibcHypotBf16Test = LIBC_NAMESPACE::testing::FPTest<bfloat16>;
-
-namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
+#include "src/math/hypotbf16.h"
-// range: [+0, inf]
-static constexpr uint16_t POS_START = 0x0000U;
-static constexpr uint16_t POS_STOP = 0x7f80U;
+using LlvmLibcHypotbf16Test = HypotTestTemplate<bfloat16>;
-// x+y = y+x
-TEST_F(LlvmLibcHypotBf16Test, PositiveRange){
- for(uint16_t v1 = POS_START; v1<= POS_STOP; ++v1){
- for(uint16_t v2 = v1; v2<=POS_STOP; ++v2){
- bfloat16 x = FPBits(x).get_val();
- bfloat16 y = FPBits(y).get_val();
- mpfr::BinaryInput<bfloat16> input{x,y};
- EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Hypot, input,LIBC_NAMESPACE::hypotbf16(x, y),0.5);
- }
- }
+TEST_F(LlvmLibcHypotbf16Test, SubnormalRange) {
+ test_subnormal_range(&LIBC_NAMESPACE::hypotbf16);
}
-TEST_F(LlvmLibcHypotBf16Test, SpecialNumbers){
- constexpr bfloat16 VAL[] = {zero, neg_zero, inf,
- neg_inf, min_normal, max_normal};
- for(size_t v1 = 0; v1< 6; ++v1){
- for(uint16_t v2 = v1 ; v2< 6; ++v2){
-
- bfloat16 x = VAL[v1];
- bfloat16 y = VAL[v2];
- mpfr::BinaryInput<bfloat16> input{x,y};
- EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Hypot, input,LIBC_NAMESPACE::hypotbf16(x, y),0.5);
- }
- }
+TEST_F(LlvmLibcHypotbf16Test, NormalRange) {
+ test_normal_range(&LIBC_NAMESPACE::hypotbf16);
}
-
-
-
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index 5f87aaf990741..b9792aec47e97 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -3754,6 +3754,9 @@ add_fp_unittest(
DEPENDS
libc.src.math.hypotbf16
libc.src.__support.FPUtil.bfloat16
+ libc.test.UnitTest.FPMatcher
+ libc.test.UnitTest.Test
+ libc.utils.MPFRWrapper.MPFRUtils
)
add_fp_unittest(
diff --git a/libc/test/src/math/smoke/hypotbf16_test.cpp b/libc/test/src/math/smoke/hypotbf16_test.cpp
index 07ae3938ccc7c..a0935a58d1f38 100644
--- a/libc/test/src/math/smoke/hypotbf16_test.cpp
+++ b/libc/test/src/math/smoke/hypotbf16_test.cpp
@@ -6,12 +6,28 @@
//
//===----------------------------------------------------------------------===//
-#include "HypotTest.h"
-
+#include "src/__support/FPUtil/bfloat16.h"
#include "src/math/hypotbf16.h"
+#include "test/UnitTest/FPMatcher.h"
+#include "test/UnitTest/Test.h"
+#include "utils/MPFRWrapper/MPFRUtils.h"
+
+using LlvmLibcHypotBf16Test = LIBC_NAMESPACE::testing::FPTest<bfloat16>;
-using LlvmLibcHypotbf16Test = HypotTestTemplate<bfloat16>;
+namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
-TEST_F(LlvmLibcHypotbf16Test, SpecialNumbers) {
- test_special_numbers(&LIBC_NAMESPACE::hypotbf16);
+TEST_F(LlvmLibcHypotBf16Test, SpecialNumbers) {
+ constexpr bfloat16 VAL[] = {zero, neg_zero, inf,
+ neg_inf, min_normal, max_normal};
+ for (size_t v1 = 0; v1 < 6; ++v1) {
+ for (size_t v2 = v1; v2 < 6; ++v2) {
+
+ bfloat16 x = VAL[v1];
+ bfloat16 y = VAL[v2];
+ mpfr::BinaryInput<bfloat16> input{x, y};
+ EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Hypot, input,
+ LIBC_NAMESPACE::hypotbf16(x, y), 0.5);
+ }
+ }
}
+
diff --git a/libc/utils/MPFRWrapper/MPFRUtils.cpp b/libc/utils/MPFRWrapper/MPFRUtils.cpp
index c61ef66c803eb..a7d307b47c3e8 100644
--- a/libc/utils/MPFRWrapper/MPFRUtils.cpp
+++ b/libc/utils/MPFRWrapper/MPFRUtils.cpp
@@ -408,8 +408,8 @@ template void explain_binary_operation_one_output_error(
Operation, const BinaryInput<float16> &, float16, double, RoundingMode);
template void
explain_binary_operation_one_output_error(Operation, const BinaryInput<float> &,
- explain_binary_operation_one_output_error float16, double, RoundingMode);
-template void (
+ float16, double, RoundingMode);
+template void explain_binary_operation_one_output_error(
Operation, const BinaryInput<double> &, float16, double, RoundingMode);
template void explain_binary_operation_one_output_error(
Operation, const BinaryInput<long double> &, float16, double, RoundingMode);
>From ddc7ea45a80d9bb4f7c289bf1798d3992f99bcfe Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Thu, 26 Feb 2026 11:46:36 +0530
Subject: [PATCH 05/30] added true exhaustive test
---
libc/test/src/math/exhaustive/CMakeLists.txt | 50 +++-----
.../src/math/exhaustive/hypotbf16_test.cpp | 108 ++++++++++++++++++
libc/test/src/math/hypotbf16_test.cpp | 2 +-
3 files changed, 127 insertions(+), 33 deletions(-)
create mode 100644 libc/test/src/math/exhaustive/hypotbf16_test.cpp
diff --git a/libc/test/src/math/exhaustive/CMakeLists.txt b/libc/test/src/math/exhaustive/CMakeLists.txt
index a21e208312c56..840317b6beac8 100644
--- a/libc/test/src/math/exhaustive/CMakeLists.txt
+++ b/libc/test/src/math/exhaustive/CMakeLists.txt
@@ -357,6 +357,24 @@ add_fp_unittest(
-lpthread
)
+add_fp_unittest(
+ hypotbf16_test
+ NO_RUN_POSTBUILD
+ NEED_MPFR
+ SUITE
+ libc_math_exhaustive_tests
+ SRCS
+ hypotbf16_test.cpp
+ COMPILE_OPTIONS
+ ${libc_opt_high_flag}
+ DEPENDS
+ .exhaustive_test
+ libc.src.math.hypotbf16
+ libc.src.__support.FPUtil.fp_bits
+ LINK_LIBRARIES
+ -lpthread
+)
+
add_fp_unittest(
hypotf_test
NO_RUN_POSTBUILD
@@ -502,22 +520,6 @@ add_fp_unittest(
-lpthread
)
-add_fp_unittest(
- acospif_test
- NO_RUN_POSTBUILD
- NEED_MPFR
- SUITE
- libc_math_exhaustive_tests
- SRCS
- acospif_test.cpp
- DEPENDS
- .exhaustive_test
- libc.src.math.acospif
- libc.src.__support.FPUtil.fp_bits
- LINK_LIBRARIES
- -lpthread
-)
-
add_fp_unittest(
asinhf_test
NO_RUN_POSTBUILD
@@ -534,22 +536,6 @@ add_fp_unittest(
-lpthread
)
-add_fp_unittest(
- asinpif_test
- NO_RUN_POSTBUILD
- NEED_MPFR
- SUITE
- libc_math_exhaustive_tests
- SRCS
- asinpif_test.cpp
- DEPENDS
- .exhaustive_test
- libc.src.math.asinpif
- libc.src.__support.FPUtil.fp_bits
- LINK_LIBRARIES
- -lpthread
-)
-
add_fp_unittest(
atanhf_test
NO_RUN_POSTBUILD
diff --git a/libc/test/src/math/exhaustive/hypotbf16_test.cpp b/libc/test/src/math/exhaustive/hypotbf16_test.cpp
new file mode 100644
index 0000000000000..cfc34c39099ce
--- /dev/null
+++ b/libc/test/src/math/exhaustive/hypotbf16_test.cpp
@@ -0,0 +1,108 @@
+//===-- Exhaustive test for hypotbf16 -------------------------------------===//
+//
+// 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/__support/FPUtil/bfloat16.h"
+#include "src/math/hypotbf16.h"
+#include "test/UnitTest/FPMatcher.h"
+#include "test/UnitTest/Test.h"
+#include "utils/MPFRWrapper/MPFRUtils.h"
+
+using LlvmLibcHypotBf16Test = LIBC_NAMESPACE::testing::FPTest<bfloat16>;
+
+namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
+
+// Normal range: [+0, +int]
+static constexpr uint16_t POS_START = 0x0000U;
+static constexpr uint16_t POS_STOP = 0x7f80U;
+
+// Normal range: [-0, -int]
+static constexpr uint16_t NEG_START = 0x8000U;
+static constexpr uint16_t NEG_STOP = 0xff80U;
+
+// Subnormal range (positive)
+static constexpr uint16_t SUBNORM_POS_START = 0x0001U;
+static constexpr uint16_t SUBNORM_POS_STOP = 0x007FU;
+
+// Subnormal range (negative)
+static constexpr uint16_t SUBNORM_NEG_START = 0x8001U;
+static constexpr uint16_t SUBNORM_NEG_STOP = 0x807FU;
+
+TEST_F(LlvmLibcHypotBf16Test,NormalPositiveRange){
+ for (uint16_t v1 = POS_START; v1 <= POS_STOP; v1++) {
+ for (uint16_t v2 = v1; v2 <= POS_STOP; v2++) {
+
+ bfloat16 x = FPBits(v1).get_val();
+ bfloat16 y = FPBits(v2).get_val();
+ mpfr::BinaryInput<bfloat16> input{x, y};
+
+ EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Hypot, input,
+ LIBC_NAMESPACE::hypotbf16(x, y), 0.5);
+
+ }
+ }
+}
+
+TEST_F(LlvmLibcHypotBf16Test,NormalNegativeRange){
+ for (uint16_t v1 = NEG_START; v1 <= NEG_STOP; v1++) {
+ for (uint16_t v2 = v1; v2 <= NEG_STOP; v2++) {
+
+ bfloat16 x = FPBits(v1).get_val();
+ bfloat16 y = FPBits(v2).get_val();
+ mpfr::BinaryInput<bfloat16> input{x, y};
+
+ EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Hypot, input,
+ LIBC_NAMESPACE::hypotbf16(x, y), 0.5);
+
+ }
+ }
+}
+
+TEST_F(LlvmLibcHypotBf16Test, SubnormalNegativeRange) {
+ for (uint16_t v1 = SUBNORM_NEG_START; v1 <= SUBNORM_NEG_STOP; v1++) {
+ for (uint16_t v2 = v1; v2 <= SUBNORM_NEG_STOP; v2++) {
+
+ bfloat16 x = FPBits(v1).get_val();
+ bfloat16 y = FPBits(v2).get_val();
+ mpfr::BinaryInput<bfloat16> input{x, y};
+
+ EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Hypot, input,
+ LIBC_NAMESPACE::hypotbf16(x, y), 0.5);
+
+ }
+ }
+}
+
+TEST_F(LlvmLibcHypotBf16Test, SubnormalPositiveRange) {
+ for (uint16_t v1 = SUBNORM_POS_START; v1 <= SUBNORM_POS_STOP; v1++) {
+ for (uint16_t v2 = v1; v2 <= SUBNORM_POS_STOP; v2++) {
+
+ bfloat16 x = FPBits(v1).get_val();
+ bfloat16 y = FPBits(v2).get_val();
+ mpfr::BinaryInput<bfloat16> input{x, y};
+
+ EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Hypot, input,
+ LIBC_NAMESPACE::hypotbf16(x, y), 0.5);
+
+ }
+ }
+}
+TEST_F(LlvmLibcHypotBf16Test, SpecialNumbers) {
+ constexpr bfloat16 VALUES[] = {zero, neg_zero, inf,
+ neg_inf, min_normal, max_normal};
+ for (size_t i = 0; i < 6; ++i) {
+ for (size_t j = i; j < 6; ++j) {
+ bfloat16 x = VALUES[i];
+ bfloat16 y = VALUES[j];
+ mpfr::BinaryInput<bfloat16> input{x, y};
+
+ EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Hypot, input,
+ LIBC_NAMESPACE::hypotbf16(x, y), 0.5);
+
+ }
+ }
+}
\ No newline at end of file
diff --git a/libc/test/src/math/hypotbf16_test.cpp b/libc/test/src/math/hypotbf16_test.cpp
index dd36b7513d22d..a757ff751ba77 100644
--- a/libc/test/src/math/hypotbf16_test.cpp
+++ b/libc/test/src/math/hypotbf16_test.cpp
@@ -1,4 +1,4 @@
-//===-- Exhaustive tests for hypotbf16 ------------------------------------===//
+//===-- Unittests tests for hypotbf16 ------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
>From 0a7712a1f11fceeed6387836ec155545c4b2e473 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Thu, 26 Feb 2026 12:07:45 +0530
Subject: [PATCH 06/30] reverted additional line + checking CRLF errors
---
libc/src/__support/math/CMakeLists.txt | 1 -
libc/test/src/math/exhaustive/hypotbf16_test.cpp | 2 +-
2 files changed, 1 insertion(+), 2 deletions(-)
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 0c26115cd8f13..3bb8e76a54bfb 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -1932,7 +1932,6 @@ add_header_library(
libc.src.__support.FPUtil.multiply_add
libc.src.__support.FPUtil.sqrt
libc.src.__support.macros.optimization
- libc.sec.__support.FPUtil.bfloat16
)
add_header_library(
diff --git a/libc/test/src/math/exhaustive/hypotbf16_test.cpp b/libc/test/src/math/exhaustive/hypotbf16_test.cpp
index cfc34c39099ce..8db2d52084df3 100644
--- a/libc/test/src/math/exhaustive/hypotbf16_test.cpp
+++ b/libc/test/src/math/exhaustive/hypotbf16_test.cpp
@@ -105,4 +105,4 @@ TEST_F(LlvmLibcHypotBf16Test, SpecialNumbers) {
}
}
-}
\ No newline at end of file
+}
>From 784961a24d616a02d2986a7f33902c45d7db6ac0 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Thu, 26 Feb 2026 12:17:38 +0530
Subject: [PATCH 07/30] test
---
libc/test/src/math/exhaustive/hypotbf16_test.cpp | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/libc/test/src/math/exhaustive/hypotbf16_test.cpp b/libc/test/src/math/exhaustive/hypotbf16_test.cpp
index 8db2d52084df3..7d866b9474f9a 100644
--- a/libc/test/src/math/exhaustive/hypotbf16_test.cpp
+++ b/libc/test/src/math/exhaustive/hypotbf16_test.cpp
@@ -42,7 +42,7 @@ TEST_F(LlvmLibcHypotBf16Test,NormalPositiveRange){
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Hypot, input,
LIBC_NAMESPACE::hypotbf16(x, y), 0.5);
-
+
}
}
}
@@ -57,7 +57,7 @@ TEST_F(LlvmLibcHypotBf16Test,NormalNegativeRange){
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Hypot, input,
LIBC_NAMESPACE::hypotbf16(x, y), 0.5);
-
+
}
}
}
@@ -72,7 +72,7 @@ TEST_F(LlvmLibcHypotBf16Test, SubnormalNegativeRange) {
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Hypot, input,
LIBC_NAMESPACE::hypotbf16(x, y), 0.5);
-
+
}
}
}
@@ -87,7 +87,7 @@ TEST_F(LlvmLibcHypotBf16Test, SubnormalPositiveRange) {
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Hypot, input,
LIBC_NAMESPACE::hypotbf16(x, y), 0.5);
-
+
}
}
}
@@ -95,14 +95,14 @@ TEST_F(LlvmLibcHypotBf16Test, SpecialNumbers) {
constexpr bfloat16 VALUES[] = {zero, neg_zero, inf,
neg_inf, min_normal, max_normal};
for (size_t i = 0; i < 6; ++i) {
- for (size_t j = i; j < 6; ++j) {
+ for (size_t j = i; j < 6; ++j) {
bfloat16 x = VALUES[i];
bfloat16 y = VALUES[j];
mpfr::BinaryInput<bfloat16> input{x, y};
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Hypot, input,
LIBC_NAMESPACE::hypotbf16(x, y), 0.5);
-
+
}
}
}
>From 036ab2454a6ae8e9eec4e9668cda98623522fffc Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Thu, 26 Feb 2026 12:19:39 +0530
Subject: [PATCH 08/30] formatted
---
libc/test/src/math/exhaustive/hypotbf16_test.cpp | 5 -----
1 file changed, 5 deletions(-)
diff --git a/libc/test/src/math/exhaustive/hypotbf16_test.cpp b/libc/test/src/math/exhaustive/hypotbf16_test.cpp
index 7d866b9474f9a..4001d20f5b843 100644
--- a/libc/test/src/math/exhaustive/hypotbf16_test.cpp
+++ b/libc/test/src/math/exhaustive/hypotbf16_test.cpp
@@ -42,7 +42,6 @@ TEST_F(LlvmLibcHypotBf16Test,NormalPositiveRange){
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Hypot, input,
LIBC_NAMESPACE::hypotbf16(x, y), 0.5);
-
}
}
}
@@ -57,7 +56,6 @@ TEST_F(LlvmLibcHypotBf16Test,NormalNegativeRange){
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Hypot, input,
LIBC_NAMESPACE::hypotbf16(x, y), 0.5);
-
}
}
}
@@ -72,7 +70,6 @@ TEST_F(LlvmLibcHypotBf16Test, SubnormalNegativeRange) {
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Hypot, input,
LIBC_NAMESPACE::hypotbf16(x, y), 0.5);
-
}
}
}
@@ -87,7 +84,6 @@ TEST_F(LlvmLibcHypotBf16Test, SubnormalPositiveRange) {
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Hypot, input,
LIBC_NAMESPACE::hypotbf16(x, y), 0.5);
-
}
}
}
@@ -102,7 +98,6 @@ TEST_F(LlvmLibcHypotBf16Test, SpecialNumbers) {
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Hypot, input,
LIBC_NAMESPACE::hypotbf16(x, y), 0.5);
-
}
}
}
>From b8f60118b6343db0f74c22aba823fb4e6d01c6f3 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Thu, 26 Feb 2026 12:30:55 +0530
Subject: [PATCH 09/30] clang-format errors
---
libc/src/math/generic/hypotbf16.cpp | 3 +-
.../src/math/exhaustive/hypotbf16_test.cpp | 34 +++++++++----------
libc/test/src/math/smoke/hypotbf16_test.cpp | 1 -
3 files changed, 18 insertions(+), 20 deletions(-)
diff --git a/libc/src/math/generic/hypotbf16.cpp b/libc/src/math/generic/hypotbf16.cpp
index 52c9d88f681cd..6852d6fa77035 100644
--- a/libc/src/math/generic/hypotbf16.cpp
+++ b/libc/src/math/generic/hypotbf16.cpp
@@ -6,11 +6,11 @@
//
//===----------------------------------------------------------------------===//
+#include "src/math/hypotbf16.h"
#include "src/__support/FPUtil/Hypot.h"
#include "src/__support/FPUtil/bfloat16.h"
#include "src/__support/common.h"
#include "src/__support/macros/config.h"
-#include "src/math/hypotbf16.h"
namespace LIBC_NAMESPACE_DECL {
@@ -18,5 +18,4 @@ LLVM_LIBC_FUNCTION(bfloat16, hypotbf16, (bfloat16 x, bfloat16 y)) {
return fputil::hypot<bfloat16>(x, y);
}
-
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/src/math/exhaustive/hypotbf16_test.cpp b/libc/test/src/math/exhaustive/hypotbf16_test.cpp
index 4001d20f5b843..15d50a485bd9f 100644
--- a/libc/test/src/math/exhaustive/hypotbf16_test.cpp
+++ b/libc/test/src/math/exhaustive/hypotbf16_test.cpp
@@ -32,16 +32,16 @@ static constexpr uint16_t SUBNORM_POS_STOP = 0x007FU;
static constexpr uint16_t SUBNORM_NEG_START = 0x8001U;
static constexpr uint16_t SUBNORM_NEG_STOP = 0x807FU;
-TEST_F(LlvmLibcHypotBf16Test,NormalPositiveRange){
- for (uint16_t v1 = POS_START; v1 <= POS_STOP; v1++) {
+TEST_F(LlvmLibcHypotBf16Test, NormalPositiveRange) {
+ for (uint16_t v1 = POS_START; v1 <= POS_STOP; v1++) {
for (uint16_t v2 = v1; v2 <= POS_STOP; v2++) {
bfloat16 x = FPBits(v1).get_val();
bfloat16 y = FPBits(v2).get_val();
- mpfr::BinaryInput<bfloat16> input{x, y};
+ mpfr::BinaryInput<bfloat16> input{x, y};
- EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Hypot, input,
- LIBC_NAMESPACE::hypotbf16(x, y), 0.5);
+ EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Hypot, input,
+ LIBC_NAMESPACE::hypotbf16(x, y), 0.5);
}
}
}
@@ -52,10 +52,10 @@ TEST_F(LlvmLibcHypotBf16Test,NormalNegativeRange){
bfloat16 x = FPBits(v1).get_val();
bfloat16 y = FPBits(v2).get_val();
- mpfr::BinaryInput<bfloat16> input{x, y};
+ mpfr::BinaryInput<bfloat16> input{x, y};
- EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Hypot, input,
- LIBC_NAMESPACE::hypotbf16(x, y), 0.5);
+ EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Hypot, input,
+ LIBC_NAMESPACE::hypotbf16(x, y), 0.5);
}
}
}
@@ -66,10 +66,10 @@ TEST_F(LlvmLibcHypotBf16Test, SubnormalNegativeRange) {
bfloat16 x = FPBits(v1).get_val();
bfloat16 y = FPBits(v2).get_val();
- mpfr::BinaryInput<bfloat16> input{x, y};
+ mpfr::BinaryInput<bfloat16> input{x, y};
- EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Hypot, input,
- LIBC_NAMESPACE::hypotbf16(x, y), 0.5);
+ EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Hypot, input,
+ LIBC_NAMESPACE::hypotbf16(x, y), 0.5);
}
}
}
@@ -80,10 +80,10 @@ TEST_F(LlvmLibcHypotBf16Test, SubnormalPositiveRange) {
bfloat16 x = FPBits(v1).get_val();
bfloat16 y = FPBits(v2).get_val();
- mpfr::BinaryInput<bfloat16> input{x, y};
+ mpfr::BinaryInput<bfloat16> input{x, y};
- EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Hypot, input,
- LIBC_NAMESPACE::hypotbf16(x, y), 0.5);
+ EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Hypot, input,
+ LIBC_NAMESPACE::hypotbf16(x, y), 0.5);
}
}
}
@@ -94,10 +94,10 @@ TEST_F(LlvmLibcHypotBf16Test, SpecialNumbers) {
for (size_t j = i; j < 6; ++j) {
bfloat16 x = VALUES[i];
bfloat16 y = VALUES[j];
- mpfr::BinaryInput<bfloat16> input{x, y};
+ mpfr::BinaryInput<bfloat16> input{x, y};
- EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Hypot, input,
- LIBC_NAMESPACE::hypotbf16(x, y), 0.5);
+ EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Hypot, input,
+ LIBC_NAMESPACE::hypotbf16(x, y), 0.5);
}
}
}
diff --git a/libc/test/src/math/smoke/hypotbf16_test.cpp b/libc/test/src/math/smoke/hypotbf16_test.cpp
index a0935a58d1f38..679ad9bd462a6 100644
--- a/libc/test/src/math/smoke/hypotbf16_test.cpp
+++ b/libc/test/src/math/smoke/hypotbf16_test.cpp
@@ -30,4 +30,3 @@ TEST_F(LlvmLibcHypotBf16Test, SpecialNumbers) {
}
}
}
-
>From 6c5810b889129d6e4b0f1ccbfe6c0509a73ca979 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Thu, 26 Feb 2026 12:33:52 +0530
Subject: [PATCH 10/30] formatted
---
libc/test/src/math/exhaustive/hypotbf16_test.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/libc/test/src/math/exhaustive/hypotbf16_test.cpp b/libc/test/src/math/exhaustive/hypotbf16_test.cpp
index 15d50a485bd9f..4001c0a35c914 100644
--- a/libc/test/src/math/exhaustive/hypotbf16_test.cpp
+++ b/libc/test/src/math/exhaustive/hypotbf16_test.cpp
@@ -46,8 +46,8 @@ TEST_F(LlvmLibcHypotBf16Test, NormalPositiveRange) {
}
}
-TEST_F(LlvmLibcHypotBf16Test,NormalNegativeRange){
- for (uint16_t v1 = NEG_START; v1 <= NEG_STOP; v1++) {
+TEST_F(LlvmLibcHypotBf16Test, NormalNegativeRange) {
+ for (uint16_t v1 = NEG_START; v1 <= NEG_STOP; v1++) {
for (uint16_t v2 = v1; v2 <= NEG_STOP; v2++) {
bfloat16 x = FPBits(v1).get_val();
>From 02d709193dc9c71389967db04f227cac8d74fcbb Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Thu, 26 Feb 2026 13:43:38 +0530
Subject: [PATCH 11/30] added missed dependency for bfloat
---
libc/test/src/math/exhaustive/CMakeLists.txt | 1 +
1 file changed, 1 insertion(+)
diff --git a/libc/test/src/math/exhaustive/CMakeLists.txt b/libc/test/src/math/exhaustive/CMakeLists.txt
index 840317b6beac8..87c2a91646008 100644
--- a/libc/test/src/math/exhaustive/CMakeLists.txt
+++ b/libc/test/src/math/exhaustive/CMakeLists.txt
@@ -371,6 +371,7 @@ add_fp_unittest(
.exhaustive_test
libc.src.math.hypotbf16
libc.src.__support.FPUtil.fp_bits
+ libc.src.__support.FPUtil.bfloat16
LINK_LIBRARIES
-lpthread
)
>From d7ab2485886dc38e486561e9623e915d2d89008b Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Sat, 28 Feb 2026 00:58:00 +0530
Subject: [PATCH 12/30] CHANGE: repositions in entrypoints.txt
---
libc/config/baremetal/aarch64/entrypoints.txt | 2 +-
libc/config/baremetal/arm/entrypoints.txt | 2 +-
libc/config/baremetal/riscv/entrypoints.txt | 2 +-
libc/config/darwin/aarch64/entrypoints.txt | 2 +-
libc/config/darwin/x86_64/entrypoints.txt | 2 +-
libc/config/gpu/amdgpu/entrypoints.txt | 2 +-
libc/config/gpu/nvptx/entrypoints.txt | 2 +-
libc/config/linux/aarch64/entrypoints.txt | 2 +-
libc/config/linux/arm/entrypoints.txt | 2 +-
libc/config/linux/riscv/entrypoints.txt | 2 +-
libc/config/linux/x86_64/entrypoints.txt | 2 +-
libc/config/windows/entrypoints.txt | 1 +
12 files changed, 12 insertions(+), 11 deletions(-)
diff --git a/libc/config/baremetal/aarch64/entrypoints.txt b/libc/config/baremetal/aarch64/entrypoints.txt
index 6b145fb6fe43f..01243393ada4a 100644
--- a/libc/config/baremetal/aarch64/entrypoints.txt
+++ b/libc/config/baremetal/aarch64/entrypoints.txt
@@ -449,7 +449,6 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.getpayloadf
libc.src.math.getpayloadl
libc.src.math.hypot
- libc.src.math.hypotbf16
libc.src.math.hypotf
libc.src.math.ilogb
libc.src.math.ilogbf
@@ -813,6 +812,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
+ libc.src.math.hypotbf16
libc.src.math.ilogbbf16
libc.src.math.iscanonicalbf16
libc.src.math.issignalingbf16
diff --git a/libc/config/baremetal/arm/entrypoints.txt b/libc/config/baremetal/arm/entrypoints.txt
index a26f92c418fbc..69fc722ae67cc 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -452,7 +452,6 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.getpayloadf
libc.src.math.getpayloadl
libc.src.math.hypot
- libc.src.math.hypotbf16
libc.src.math.hypotf
libc.src.math.ilogb
libc.src.math.ilogbf
@@ -816,6 +815,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
+ libc.src.math.hypotbf16
libc.src.math.ilogbbf16
libc.src.math.iscanonicalbf16
libc.src.math.issignalingbf16
diff --git a/libc/config/baremetal/riscv/entrypoints.txt b/libc/config/baremetal/riscv/entrypoints.txt
index adf597c8ff3d5..02d83320860a2 100644
--- a/libc/config/baremetal/riscv/entrypoints.txt
+++ b/libc/config/baremetal/riscv/entrypoints.txt
@@ -450,7 +450,6 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.getpayloadf
libc.src.math.getpayloadl
libc.src.math.hypot
- libc.src.math.hypotbf16
libc.src.math.hypotf
libc.src.math.ilogb
libc.src.math.ilogbf
@@ -814,6 +813,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
+ libc.src.math.hypotbf16
libc.src.math.ilogbbf16
libc.src.math.iscanonicalbf16
libc.src.math.issignalingbf16
diff --git a/libc/config/darwin/aarch64/entrypoints.txt b/libc/config/darwin/aarch64/entrypoints.txt
index eac6a448ed5b8..6bbf9b10f22f4 100644
--- a/libc/config/darwin/aarch64/entrypoints.txt
+++ b/libc/config/darwin/aarch64/entrypoints.txt
@@ -265,7 +265,6 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.getpayloadf
libc.src.math.getpayloadl
libc.src.math.hypot
- libc.src.math.hypotbf16
libc.src.math.hypotf
libc.src.math.ilogb
libc.src.math.ilogbf
@@ -630,6 +629,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
+ libc.src.math.hypotbf16
libc.src.math.ilogbbf16
libc.src.math.iscanonicalbf16
libc.src.math.issignalingbf16
diff --git a/libc/config/darwin/x86_64/entrypoints.txt b/libc/config/darwin/x86_64/entrypoints.txt
index 3d205b5a10895..d97474f0d7021 100644
--- a/libc/config/darwin/x86_64/entrypoints.txt
+++ b/libc/config/darwin/x86_64/entrypoints.txt
@@ -162,7 +162,6 @@ set(TARGET_LIBM_ENTRYPOINTS
#libc.src.math.fsub
#libc.src.math.fsubl
#libc.src.math.hypot
- #libc.src.math.hypotbf16
#libc.src.math.hypotf
#libc.src.math.ilogb
#libc.src.math.ilogbf
@@ -270,6 +269,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
+ libc.src.math.hypotbf16
libc.src.math.ilogbbf16
libc.src.math.iscanonicalbf16
libc.src.math.issignalingbf16
diff --git a/libc/config/gpu/amdgpu/entrypoints.txt b/libc/config/gpu/amdgpu/entrypoints.txt
index c16d478d64d18..b95f7cc4f9097 100644
--- a/libc/config/gpu/amdgpu/entrypoints.txt
+++ b/libc/config/gpu/amdgpu/entrypoints.txt
@@ -392,7 +392,6 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.getpayloadf
libc.src.math.getpayloadl
libc.src.math.hypot
- libc.src.math.hypotbf16
libc.src.math.hypotf
libc.src.math.ilogb
libc.src.math.ilogbf
@@ -655,6 +654,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
+ libc.src.math.hypotbf16
libc.src.math.ilogbbf16
libc.src.math.iscanonicalbf16
libc.src.math.issignalingbf16
diff --git a/libc/config/gpu/nvptx/entrypoints.txt b/libc/config/gpu/nvptx/entrypoints.txt
index 31f84940dfb6f..c96731982a323 100644
--- a/libc/config/gpu/nvptx/entrypoints.txt
+++ b/libc/config/gpu/nvptx/entrypoints.txt
@@ -393,7 +393,6 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.getpayloadf
libc.src.math.getpayloadl
libc.src.math.hypot
- libc.src.math.hypotbf16
libc.src.math.hypotf
libc.src.math.ilogb
libc.src.math.ilogbf
@@ -657,6 +656,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
+ libc.src.math.hypotbf16
libc.src.math.ilogbbf16
libc.src.math.iscanonicalbf16
libc.src.math.issignalingbf16
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index cb417b3ba1242..910bd5551dcd6 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -530,7 +530,6 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.getpayloadf
libc.src.math.getpayloadl
libc.src.math.hypot
- libc.src.math.hypotbf16
libc.src.math.hypotf
libc.src.math.ilogb
libc.src.math.ilogbf
@@ -886,6 +885,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
+ libc.src.math.hypotbf16
libc.src.math.ilogbbf16
libc.src.math.iscanonicalbf16
libc.src.math.issignalingbf16
diff --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt
index c54e1f3a0eccb..fe043d11aaa99 100644
--- a/libc/config/linux/arm/entrypoints.txt
+++ b/libc/config/linux/arm/entrypoints.txt
@@ -351,7 +351,6 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.getpayloadf
libc.src.math.getpayloadl
libc.src.math.hypot
- libc.src.math.hypotbf16
libc.src.math.hypotf
libc.src.math.ilogb
libc.src.math.ilogbf
@@ -499,6 +498,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
+ libc.src.math.hypotbf16
libc.src.math.ilogbbf16
libc.src.math.iscanonicalbf16
libc.src.math.issignalingbf16
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 3ff7a6aafe13d..a4dd1d9ee23a0 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -539,7 +539,6 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.getpayloadf
libc.src.math.getpayloadl
libc.src.math.hypot
- libc.src.math.hypotbf16
libc.src.math.hypotf
libc.src.math.ilogb
libc.src.math.ilogbf
@@ -907,6 +906,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
+ libc.src.math.hypotbf16
libc.src.math.ilogbbf16
libc.src.math.iscanonicalbf16
libc.src.math.issignalingbf16
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index cd3552734d7ae..82d1f75fa4674 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -581,7 +581,6 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.getpayloadf
libc.src.math.getpayloadl
libc.src.math.hypot
- libc.src.math.hypotbf16
libc.src.math.hypotf
libc.src.math.ilogb
libc.src.math.ilogbf
@@ -954,6 +953,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
+ libc.src.math.hypotbf16
libc.src.math.ilogbbf16
libc.src.math.iscanonicalbf16
libc.src.math.issignalingbf16
diff --git a/libc/config/windows/entrypoints.txt b/libc/config/windows/entrypoints.txt
index 17add91cdcecf..e74168a70ab64 100644
--- a/libc/config/windows/entrypoints.txt
+++ b/libc/config/windows/entrypoints.txt
@@ -345,6 +345,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
+ libc.src.math.hypotbf16
libc.src.math.ilogbbf16
libc.src.math.iscanonicalbf16
libc.src.math.issignalingbf16
>From 022bffdb843583fbd29215173c2bd2e0331792c4 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Sat, 28 Feb 2026 01:36:26 +0530
Subject: [PATCH 13/30] REFACTOR: refactored hypotbf16 to header
---
libc/config/windows/entrypoints.txt | 1 -
libc/shared/math.h | 1 +
libc/shared/math/hypotbf16.h | 26 +++++++++++++++++
libc/src/__support/math/CMakeLists.txt | 11 +++++++
libc/src/__support/math/hypotbf16.h | 29 +++++++++++++++++++
libc/src/math/generic/CMakeLists.txt | 5 +---
libc/src/math/generic/hypotbf16.cpp | 7 ++---
libc/test/shared/CMakeLists.txt | 1 +
libc/test/shared/shared_math_test.cpp | 3 ++
.../llvm-project-overlay/libc/BUILD.bazel | 18 ++++++++++++
10 files changed, 92 insertions(+), 10 deletions(-)
create mode 100644 libc/shared/math/hypotbf16.h
create mode 100644 libc/src/__support/math/hypotbf16.h
diff --git a/libc/config/windows/entrypoints.txt b/libc/config/windows/entrypoints.txt
index e74168a70ab64..dca5b2e4da5cc 100644
--- a/libc/config/windows/entrypoints.txt
+++ b/libc/config/windows/entrypoints.txt
@@ -224,7 +224,6 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.fsub
libc.src.math.fsubl
libc.src.math.hypot
- libc.src.math.hypotbf16
libc.src.math.hypotf
libc.src.math.ilogb
libc.src.math.ilogbf
diff --git a/libc/shared/math.h b/libc/shared/math.h
index a7d735ffa1746..a16c16ef030e5 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -149,6 +149,7 @@
#include "math/getpayloadf128.h"
#include "math/getpayloadf16.h"
#include "math/getpayloadl.h"
+#include "math/hypotbf16.h"
#include "math/hypotf.h"
#include "math/hypotf16.h"
#include "math/ilogb.h"
diff --git a/libc/shared/math/hypotbf16.h b/libc/shared/math/hypotbf16.h
new file mode 100644
index 0000000000000..d134d84a304aa
--- /dev/null
+++ b/libc/shared/math/hypotbf16.h
@@ -0,0 +1,26 @@
+//===-- Shared hypotbf16 function -------------------------------*- 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_SHARED_MATH_HYPOTBF16_H
+#define LLVM_LIBC_SHARED_MATH_HYPOTBF16_H
+
+#include "shared/libc_common.h"
+
+#include "src/__support/math/hypotbf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace shared {
+
+using math::hypotbf16;
+
+} // namespace shared
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_HYPOTBF16_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 3bb8e76a54bfb..af25d58833dc4 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -1934,6 +1934,17 @@ add_header_library(
libc.src.__support.macros.optimization
)
+add_header_library(
+ hypotbf16
+ HDRS
+ hypotbf16.h
+ DEPENDS
+ libc.src.__support.FPUtil.Hypot
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.common
+ libc.src.__support.macros.config
+)
+
add_header_library(
hypotf16
HDRS
diff --git a/libc/src/__support/math/hypotbf16.h b/libc/src/__support/math/hypotbf16.h
new file mode 100644
index 0000000000000..ef57ce6bebcfa
--- /dev/null
+++ b/libc/src/__support/math/hypotbf16.h
@@ -0,0 +1,29 @@
+//===-- Implementation header for fmabf16 -----------------------*- 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___SUPPORT_MATH_FMABF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_FMABF16_H
+
+#include "src/__support/FPUtil/Hypot.h"
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE bfloat16 hypotbf16(bfloat16 x, bfloat16 y) {
+ return fputil::hypot<bfloat16>(x, y);
+}
+
+} // namespace math
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_HYPOTBF16_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index ba97a5c59401b..c132752dc4d36 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -3023,10 +3023,7 @@ add_entrypoint_object(
HDRS
../hypotbf16.h
DEPENDS
- libc.src.__support.FPUtil.hypot
- libc.src.__support.FPUtil.bfloat16
- libc.src.__support.common
- libc.src.__support.macros.config
+ libc.src.__support.math.hypotbf16
)
add_entrypoint_object(
diff --git a/libc/src/math/generic/hypotbf16.cpp b/libc/src/math/generic/hypotbf16.cpp
index 6852d6fa77035..0c1a3ed84021b 100644
--- a/libc/src/math/generic/hypotbf16.cpp
+++ b/libc/src/math/generic/hypotbf16.cpp
@@ -7,15 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/hypotbf16.h"
-#include "src/__support/FPUtil/Hypot.h"
-#include "src/__support/FPUtil/bfloat16.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/hypotbf16.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(bfloat16, hypotbf16, (bfloat16 x, bfloat16 y)) {
- return fputil::hypot<bfloat16>(x, y);
+ return math::hypotbf16(x, y);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index a04a15cdabcb7..a78ae71cf5ccd 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -147,6 +147,7 @@ add_fp_unittest(
libc.src.__support.math.getpayloadf16
libc.src.__support.math.getpayloadl
libc.src.__support.math.hypotf
+ libc.src.__support.math.hypotbf16
libc.src.__support.math.hypotf16
libc.src.__support.math.ilogb
libc.src.__support.math.ilogbf
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 460449e4fcb2e..76eb2c70931b6 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -432,6 +432,9 @@ TEST(LlvmLibcSharedMathTest, AllBFloat16) {
EXPECT_FP_EQ(bfloat16(-1.0),
LIBC_NAMESPACE::shared::getpayloadbf16(&getpayloadbf16_x));
+ EXPECT_FP_EQ(bfloat16(5.0),
+ LIBC_NAMESPACE::shared::hypotbf16(bfloat16(4.0), bfloat16(3.0)));
+
bfloat16 setpayloadbf16_res = bfloat16(0.0);
EXPECT_EQ(0, LIBC_NAMESPACE::shared::setpayloadbf16(&setpayloadbf16_res,
bfloat16(0.0)));
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 87d1d88e971bf..6ab9d90546f16 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -5424,6 +5424,17 @@ libc_support_library(
],
)
+libc_support_library(
+ name = "__support_math_hypotbf16",
+ hdrs = ["src/__support/math/hypotbf16.h"],
+ deps = [
+ ":__support_fputil_hypot",
+ ":__support_fputil_bfloat16",
+ ":__support_common",
+ ":__support_macros_config",
+ ],
+)
+
libc_support_library(
name = "__support_math_hypotf16",
hdrs = ["src/__support/math/hypotf16.h"],
@@ -7099,6 +7110,13 @@ libc_math_function(
],
)
+libc_math_function(
+ name = "hypotbf16",
+ additional_deps = [
+ ":__support_math_hypotbf16",
+ ],
+)
+
libc_math_function(
name = "hypotf16",
additional_deps = [
>From 2e54f32b1193b2cdbe0b570cce1e4f8de29a0ed3 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Sat, 28 Feb 2026 01:47:26 +0530
Subject: [PATCH 14/30] FIX: Typo
---
libc/src/__support/math/hypotbf16.h | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/libc/src/__support/math/hypotbf16.h b/libc/src/__support/math/hypotbf16.h
index ef57ce6bebcfa..e04013e4e3d68 100644
--- a/libc/src/__support/math/hypotbf16.h
+++ b/libc/src/__support/math/hypotbf16.h
@@ -1,4 +1,4 @@
-//===-- Implementation header for fmabf16 -----------------------*- C++ -*-===//
+//===-- Implementation header for hypotbf16 ---------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_FMABF16_H
-#define LLVM_LIBC_SRC___SUPPORT_MATH_FMABF16_H
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_HYPOTBF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_HYPOTBF16_H
#include "src/__support/FPUtil/Hypot.h"
#include "src/__support/FPUtil/bfloat16.h"
>From b1e7e82b118fa4196869d35c0cd34b4d0fec778c Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Sat, 28 Feb 2026 16:55:16 +0530
Subject: [PATCH 15/30] FORMAT: Bazel
---
utils/bazel/llvm-project-overlay/libc/BUILD.bazel | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 6ab9d90546f16..c57f0f978c483 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -5428,9 +5428,9 @@ libc_support_library(
name = "__support_math_hypotbf16",
hdrs = ["src/__support/math/hypotbf16.h"],
deps = [
- ":__support_fputil_hypot",
- ":__support_fputil_bfloat16",
":__support_common",
+ ":__support_fputil_bfloat16",
+ ":__support_fputil_hypot",
":__support_macros_config",
],
)
>From f467e4e78f027997a520a5ee0fa9c07adf06de7c Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Sun, 1 Mar 2026 23:57:50 +0530
Subject: [PATCH 16/30] remove: removed redundancy
---
.../src/math/exhaustive/hypotbf16_test.cpp | 39 +------------------
1 file changed, 2 insertions(+), 37 deletions(-)
diff --git a/libc/test/src/math/exhaustive/hypotbf16_test.cpp b/libc/test/src/math/exhaustive/hypotbf16_test.cpp
index 4001c0a35c914..41e64b56caa3c 100644
--- a/libc/test/src/math/exhaustive/hypotbf16_test.cpp
+++ b/libc/test/src/math/exhaustive/hypotbf16_test.cpp
@@ -24,15 +24,7 @@ static constexpr uint16_t POS_STOP = 0x7f80U;
static constexpr uint16_t NEG_START = 0x8000U;
static constexpr uint16_t NEG_STOP = 0xff80U;
-// Subnormal range (positive)
-static constexpr uint16_t SUBNORM_POS_START = 0x0001U;
-static constexpr uint16_t SUBNORM_POS_STOP = 0x007FU;
-
-// Subnormal range (negative)
-static constexpr uint16_t SUBNORM_NEG_START = 0x8001U;
-static constexpr uint16_t SUBNORM_NEG_STOP = 0x807FU;
-
-TEST_F(LlvmLibcHypotBf16Test, NormalPositiveRange) {
+TEST_F(LlvmLibcHypotBf16Test, PositiveRange) {
for (uint16_t v1 = POS_START; v1 <= POS_STOP; v1++) {
for (uint16_t v2 = v1; v2 <= POS_STOP; v2++) {
@@ -46,7 +38,7 @@ TEST_F(LlvmLibcHypotBf16Test, NormalPositiveRange) {
}
}
-TEST_F(LlvmLibcHypotBf16Test, NormalNegativeRange) {
+TEST_F(LlvmLibcHypotBf16Test, NegativeRange) {
for (uint16_t v1 = NEG_START; v1 <= NEG_STOP; v1++) {
for (uint16_t v2 = v1; v2 <= NEG_STOP; v2++) {
@@ -60,33 +52,6 @@ TEST_F(LlvmLibcHypotBf16Test, NormalNegativeRange) {
}
}
-TEST_F(LlvmLibcHypotBf16Test, SubnormalNegativeRange) {
- for (uint16_t v1 = SUBNORM_NEG_START; v1 <= SUBNORM_NEG_STOP; v1++) {
- for (uint16_t v2 = v1; v2 <= SUBNORM_NEG_STOP; v2++) {
-
- bfloat16 x = FPBits(v1).get_val();
- bfloat16 y = FPBits(v2).get_val();
- mpfr::BinaryInput<bfloat16> input{x, y};
-
- EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Hypot, input,
- LIBC_NAMESPACE::hypotbf16(x, y), 0.5);
- }
- }
-}
-
-TEST_F(LlvmLibcHypotBf16Test, SubnormalPositiveRange) {
- for (uint16_t v1 = SUBNORM_POS_START; v1 <= SUBNORM_POS_STOP; v1++) {
- for (uint16_t v2 = v1; v2 <= SUBNORM_POS_STOP; v2++) {
-
- bfloat16 x = FPBits(v1).get_val();
- bfloat16 y = FPBits(v2).get_val();
- mpfr::BinaryInput<bfloat16> input{x, y};
-
- EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Hypot, input,
- LIBC_NAMESPACE::hypotbf16(x, y), 0.5);
- }
- }
-}
TEST_F(LlvmLibcHypotBf16Test, SpecialNumbers) {
constexpr bfloat16 VALUES[] = {zero, neg_zero, inf,
neg_inf, min_normal, max_normal};
>From e09c6a6e79935fa65be9167c481612793de4689e Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Mon, 2 Mar 2026 10:59:51 +0530
Subject: [PATCH 17/30] chore: smoke uses HypotTest.h now
---
libc/test/src/math/smoke/hypotbf16_test.cpp | 25 +++++----------------
1 file changed, 5 insertions(+), 20 deletions(-)
diff --git a/libc/test/src/math/smoke/hypotbf16_test.cpp b/libc/test/src/math/smoke/hypotbf16_test.cpp
index 679ad9bd462a6..f406dd71c659e 100644
--- a/libc/test/src/math/smoke/hypotbf16_test.cpp
+++ b/libc/test/src/math/smoke/hypotbf16_test.cpp
@@ -6,27 +6,12 @@
//
//===----------------------------------------------------------------------===//
-#include "src/__support/FPUtil/bfloat16.h"
-#include "src/math/hypotbf16.h"
-#include "test/UnitTest/FPMatcher.h"
-#include "test/UnitTest/Test.h"
-#include "utils/MPFRWrapper/MPFRUtils.h"
+#include "HypotTest.h"
-using LlvmLibcHypotBf16Test = LIBC_NAMESPACE::testing::FPTest<bfloat16>;
+#include "src/math/hypotbf16.h"
-namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
+using LlvmLibcHypotBf16Test = HypotTestTemplate<bfloat16>;
TEST_F(LlvmLibcHypotBf16Test, SpecialNumbers) {
- constexpr bfloat16 VAL[] = {zero, neg_zero, inf,
- neg_inf, min_normal, max_normal};
- for (size_t v1 = 0; v1 < 6; ++v1) {
- for (size_t v2 = v1; v2 < 6; ++v2) {
-
- bfloat16 x = VAL[v1];
- bfloat16 y = VAL[v2];
- mpfr::BinaryInput<bfloat16> input{x, y};
- EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Hypot, input,
- LIBC_NAMESPACE::hypotbf16(x, y), 0.5);
- }
- }
-}
+ test_special_numbers(&LIBC_NAMESPACE::hypotbf16);
+}
\ No newline at end of file
>From 994be0be62a9b48b44fd19247f4fd58d40484190 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Mon, 2 Mar 2026 11:05:28 +0530
Subject: [PATCH 18/30] chore: cmake updated
---
libc/test/src/math/smoke/CMakeLists.txt | 4 +---
libc/test/src/math/smoke/hypotbf16_test.cpp | 1 +
2 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index b9792aec47e97..464fa3498ca6f 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -3754,9 +3754,7 @@ add_fp_unittest(
DEPENDS
libc.src.math.hypotbf16
libc.src.__support.FPUtil.bfloat16
- libc.test.UnitTest.FPMatcher
- libc.test.UnitTest.Test
- libc.utils.MPFRWrapper.MPFRUtils
+ libc.src.__support.FPUtil.fp_bits
)
add_fp_unittest(
diff --git a/libc/test/src/math/smoke/hypotbf16_test.cpp b/libc/test/src/math/smoke/hypotbf16_test.cpp
index f406dd71c659e..892017c309a72 100644
--- a/libc/test/src/math/smoke/hypotbf16_test.cpp
+++ b/libc/test/src/math/smoke/hypotbf16_test.cpp
@@ -8,6 +8,7 @@
#include "HypotTest.h"
+#include "src/__support/FPUtil/bfloat16.h"
#include "src/math/hypotbf16.h"
using LlvmLibcHypotBf16Test = HypotTestTemplate<bfloat16>;
>From 5d3ed292fbc8e8d1186866a3a51f3c44f361afb7 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Mon, 2 Mar 2026 23:54:26 +0530
Subject: [PATCH 19/30] requested changes
---
libc/src/__support/math/CMakeLists.txt | 2 +-
libc/test/src/math/smoke/hypotbf16_test.cpp | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index af25d58833dc4..82c573cfc7ba7 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -1939,7 +1939,7 @@ add_header_library(
HDRS
hypotbf16.h
DEPENDS
- libc.src.__support.FPUtil.Hypot
+ libc.src.__support.FPUtil.hypot
libc.src.__support.FPUtil.bfloat16
libc.src.__support.common
libc.src.__support.macros.config
diff --git a/libc/test/src/math/smoke/hypotbf16_test.cpp b/libc/test/src/math/smoke/hypotbf16_test.cpp
index 892017c309a72..c39971ecdd512 100644
--- a/libc/test/src/math/smoke/hypotbf16_test.cpp
+++ b/libc/test/src/math/smoke/hypotbf16_test.cpp
@@ -15,4 +15,4 @@ using LlvmLibcHypotBf16Test = HypotTestTemplate<bfloat16>;
TEST_F(LlvmLibcHypotBf16Test, SpecialNumbers) {
test_special_numbers(&LIBC_NAMESPACE::hypotbf16);
-}
\ No newline at end of file
+}
>From 826a8ffc77dd902b4b24c73a2bd60e50c24a64de Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Tue, 3 Mar 2026 00:09:06 +0530
Subject: [PATCH 20/30] fix: conflicts
---
libc/test/src/math/exhaustive/CMakeLists.txt | 32 ++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/libc/test/src/math/exhaustive/CMakeLists.txt b/libc/test/src/math/exhaustive/CMakeLists.txt
index 87c2a91646008..5eaed5bb830c4 100644
--- a/libc/test/src/math/exhaustive/CMakeLists.txt
+++ b/libc/test/src/math/exhaustive/CMakeLists.txt
@@ -521,6 +521,22 @@ add_fp_unittest(
-lpthread
)
+add_fp_unittest(
+ acospif_test
+ NO_RUN_POSTBUILD
+ NEED_MPFR
+ SUITE
+ libc_math_exhaustive_tests
+ SRCS
+ acospif_test.cpp
+ DEPENDS
+ .exhaustive_test
+ libc.src.math.acospif
+ libc.src.__support.FPUtil.fp_bits
+ LINK_LIBRARIES
+ -lpthread
+)
+
add_fp_unittest(
asinhf_test
NO_RUN_POSTBUILD
@@ -537,6 +553,22 @@ add_fp_unittest(
-lpthread
)
+add_fp_unittest(
+ asinpif_test
+ NO_RUN_POSTBUILD
+ NEED_MPFR
+ SUITE
+ libc_math_exhaustive_tests
+ SRCS
+ asinpif_test.cpp
+ DEPENDS
+ .exhaustive_test
+ libc.src.math.asinpif
+ libc.src.__support.FPUtil.fp_bits
+ LINK_LIBRARIES
+ -lpthread
+)
+
add_fp_unittest(
atanhf_test
NO_RUN_POSTBUILD
>From d562673a66958b3b28831870b0b1ef7cb80d7861 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Tue, 3 Mar 2026 00:17:34 +0530
Subject: [PATCH 21/30] test: cmake
---
libc/src/__support/math/CMakeLists.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 82c573cfc7ba7..af25d58833dc4 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -1939,7 +1939,7 @@ add_header_library(
HDRS
hypotbf16.h
DEPENDS
- libc.src.__support.FPUtil.hypot
+ libc.src.__support.FPUtil.Hypot
libc.src.__support.FPUtil.bfloat16
libc.src.__support.common
libc.src.__support.macros.config
>From 3170420c3e2cb77f998e5bc853ce4a85b41eef24 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Tue, 3 Mar 2026 00:29:22 +0530
Subject: [PATCH 22/30] chore: nit fix
---
libc/src/__support/math/CMakeLists.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index af25d58833dc4..82c573cfc7ba7 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -1939,7 +1939,7 @@ add_header_library(
HDRS
hypotbf16.h
DEPENDS
- libc.src.__support.FPUtil.Hypot
+ libc.src.__support.FPUtil.hypot
libc.src.__support.FPUtil.bfloat16
libc.src.__support.common
libc.src.__support.macros.config
>From 8a8469e923c4aceb2ed421cb9aaf38c98b4c9f31 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Tue, 3 Mar 2026 00:37:30 +0530
Subject: [PATCH 23/30] fix: typecast
---
libc/test/src/math/smoke/HypotTest.h | 113 ++++++++++++++-------------
1 file changed, 59 insertions(+), 54 deletions(-)
diff --git a/libc/test/src/math/smoke/HypotTest.h b/libc/test/src/math/smoke/HypotTest.h
index 30d57a4fe2a26..c39ff88af70c3 100644
--- a/libc/test/src/math/smoke/HypotTest.h
+++ b/libc/test/src/math/smoke/HypotTest.h
@@ -1,54 +1,59 @@
-//===-- Utility class to test different flavors of hypot ------------------===//
-//
-// 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_TEST_SRC_MATH_HYPOTTEST_H
-#define LLVM_LIBC_TEST_SRC_MATH_HYPOTTEST_H
-
-#include "src/__support/macros/properties/architectures.h"
-#include "test/UnitTest/FPMatcher.h"
-#include "test/UnitTest/Test.h"
-
-template <typename T>
-struct HypotTestTemplate : public LIBC_NAMESPACE::testing::Test {
- using Func = T (*)(T, T);
-
- DECLARE_SPECIAL_CONSTANTS(T)
-
- void test_special_numbers(Func func) {
- constexpr int N = 4;
- // Pythagorean triples.
- constexpr T PYT[N][3] = {{3, 4, 5}, {5, 12, 13}, {8, 15, 17}, {7, 24, 25}};
-
-#ifndef LIBC_TARGET_ARCH_IS_NVPTX
- // TODO: Investigate why sNaN tests are failing on nVidia.
- // https://github.com/llvm/llvm-project/issues/99706.
- EXPECT_FP_EQ(func(inf, sNaN), aNaN);
- EXPECT_FP_EQ(func(sNaN, neg_inf), aNaN);
-#endif // !LIBC_TARGET_ARCH_IS_NVPTX
-
- EXPECT_FP_EQ(func(inf, aNaN), inf);
- EXPECT_FP_EQ(func(aNaN, neg_inf), inf);
- EXPECT_FP_EQ(func(aNaN, aNaN), aNaN);
- EXPECT_FP_EQ(func(aNaN, zero), aNaN);
- EXPECT_FP_EQ(func(neg_zero, aNaN), aNaN);
-
- for (int i = 0; i < N; ++i) {
- EXPECT_FP_EQ_ALL_ROUNDING(PYT[i][2], func(PYT[i][0], PYT[i][1]));
- EXPECT_FP_EQ_ALL_ROUNDING(PYT[i][2], func(-PYT[i][0], PYT[i][1]));
- EXPECT_FP_EQ_ALL_ROUNDING(PYT[i][2], func(PYT[i][0], -PYT[i][1]));
- EXPECT_FP_EQ_ALL_ROUNDING(PYT[i][2], func(-PYT[i][0], -PYT[i][1]));
-
- EXPECT_FP_EQ_ALL_ROUNDING(PYT[i][2], func(PYT[i][1], PYT[i][0]));
- EXPECT_FP_EQ_ALL_ROUNDING(PYT[i][2], func(-PYT[i][1], PYT[i][0]));
- EXPECT_FP_EQ_ALL_ROUNDING(PYT[i][2], func(PYT[i][1], -PYT[i][0]));
- EXPECT_FP_EQ_ALL_ROUNDING(PYT[i][2], func(-PYT[i][1], -PYT[i][0]));
- }
- }
-};
-
-#endif // LLVM_LIBC_TEST_SRC_MATH_HYPOTTEST_H
+//===-- Utility class to test different flavors of hypot ------------------===//
+//
+// 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_TEST_SRC_MATH_HYPOTTEST_H
+#define LLVM_LIBC_TEST_SRC_MATH_HYPOTTEST_H
+
+#include "src/__support/macros/properties/architectures.h"
+#include "test/UnitTest/FPMatcher.h"
+#include "test/UnitTest/Test.h"
+
+template <typename T>
+struct HypotTestTemplate : public LIBC_NAMESPACE::testing::Test {
+ using Func = T (*)(T, T);
+
+ DECLARE_SPECIAL_CONSTANTS(T)
+
+ void test_special_numbers(Func func) {
+ constexpr int N = 4;
+ // Pythagorean triples.
+ constexpr T PYT[N][3] = {
+ {T(3), T(4), T(5)},
+ {T(5), T(12), T(13)},
+ {T(8), T(15), T(17)},
+ {T(7), T(24), T(25)},
+ };
+
+#ifndef LIBC_TARGET_ARCH_IS_NVPTX
+ // TODO: Investigate why sNaN tests are failing on nVidia.
+ // https://github.com/llvm/llvm-project/issues/99706.
+ EXPECT_FP_EQ(func(inf, sNaN), aNaN);
+ EXPECT_FP_EQ(func(sNaN, neg_inf), aNaN);
+#endif // !LIBC_TARGET_ARCH_IS_NVPTX
+
+ EXPECT_FP_EQ(func(inf, aNaN), inf);
+ EXPECT_FP_EQ(func(aNaN, neg_inf), inf);
+ EXPECT_FP_EQ(func(aNaN, aNaN), aNaN);
+ EXPECT_FP_EQ(func(aNaN, zero), aNaN);
+ EXPECT_FP_EQ(func(neg_zero, aNaN), aNaN);
+
+ for (int i = 0; i < N; ++i) {
+ EXPECT_FP_EQ_ALL_ROUNDING(PYT[i][2], func(PYT[i][0], PYT[i][1]));
+ EXPECT_FP_EQ_ALL_ROUNDING(PYT[i][2], func(-PYT[i][0], PYT[i][1]));
+ EXPECT_FP_EQ_ALL_ROUNDING(PYT[i][2], func(PYT[i][0], -PYT[i][1]));
+ EXPECT_FP_EQ_ALL_ROUNDING(PYT[i][2], func(-PYT[i][0], -PYT[i][1]));
+
+ EXPECT_FP_EQ_ALL_ROUNDING(PYT[i][2], func(PYT[i][1], PYT[i][0]));
+ EXPECT_FP_EQ_ALL_ROUNDING(PYT[i][2], func(-PYT[i][1], PYT[i][0]));
+ EXPECT_FP_EQ_ALL_ROUNDING(PYT[i][2], func(PYT[i][1], -PYT[i][0]));
+ EXPECT_FP_EQ_ALL_ROUNDING(PYT[i][2], func(-PYT[i][1], -PYT[i][0]));
+ }
+ }
+};
+
+#endif // LLVM_LIBC_TEST_SRC_MATH_HYPOTTEST_H
>From 77d7fbb82762b20a3ea6fdf7020e903031d63626 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Tue, 3 Mar 2026 00:56:06 +0530
Subject: [PATCH 24/30] chore: clang
---
libc/test/src/math/smoke/HypotTest.h | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/libc/test/src/math/smoke/HypotTest.h b/libc/test/src/math/smoke/HypotTest.h
index c39ff88af70c3..94947cee9edc6 100644
--- a/libc/test/src/math/smoke/HypotTest.h
+++ b/libc/test/src/math/smoke/HypotTest.h
@@ -21,14 +21,12 @@ struct HypotTestTemplate : public LIBC_NAMESPACE::testing::Test {
void test_special_numbers(Func func) {
constexpr int N = 4;
- // Pythagorean triples.
- constexpr T PYT[N][3] = {
- {T(3), T(4), T(5)},
- {T(5), T(12), T(13)},
- {T(8), T(15), T(17)},
- {T(7), T(24), T(25)},
- };
-
+ // Pythagorean triples.
+ constexpr T PYT[N][3] = {{T(3), T(4), T(5)},
+ {T(5), T(12), T(13)},
+ {T(8), T(15), 17},
+ {T(7), T(24), T(25)}};
+
#ifndef LIBC_TARGET_ARCH_IS_NVPTX
// TODO: Investigate why sNaN tests are failing on nVidia.
// https://github.com/llvm/llvm-project/issues/99706.
>From d6ce735575eb7ec33a0132bb7dada7365fea234b Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Tue, 3 Mar 2026 01:03:24 +0530
Subject: [PATCH 25/30] chore: nit
---
libc/test/src/math/smoke/HypotTest.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/libc/test/src/math/smoke/HypotTest.h b/libc/test/src/math/smoke/HypotTest.h
index 94947cee9edc6..a703a1d6a1295 100644
--- a/libc/test/src/math/smoke/HypotTest.h
+++ b/libc/test/src/math/smoke/HypotTest.h
@@ -20,11 +20,11 @@ struct HypotTestTemplate : public LIBC_NAMESPACE::testing::Test {
DECLARE_SPECIAL_CONSTANTS(T)
void test_special_numbers(Func func) {
- constexpr int N = 4;
+ constexpr int N = 4;
// Pythagorean triples.
constexpr T PYT[N][3] = {{T(3), T(4), T(5)},
{T(5), T(12), T(13)},
- {T(8), T(15), 17},
+ {T(8), T(15), T(17)},
{T(7), T(24), T(25)}};
#ifndef LIBC_TARGET_ARCH_IS_NVPTX
>From 70e192bf1edb2cbefa19114469276197b4a4831b Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Tue, 3 Mar 2026 01:12:14 +0530
Subject: [PATCH 26/30] chore: lf
---
libc/test/src/math/smoke/HypotTest.h | 100 +++++++++++++--------------
1 file changed, 50 insertions(+), 50 deletions(-)
diff --git a/libc/test/src/math/smoke/HypotTest.h b/libc/test/src/math/smoke/HypotTest.h
index a703a1d6a1295..800b5c41daadb 100644
--- a/libc/test/src/math/smoke/HypotTest.h
+++ b/libc/test/src/math/smoke/HypotTest.h
@@ -1,25 +1,25 @@
-//===-- Utility class to test different flavors of hypot ------------------===//
-//
-// 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_TEST_SRC_MATH_HYPOTTEST_H
-#define LLVM_LIBC_TEST_SRC_MATH_HYPOTTEST_H
-
-#include "src/__support/macros/properties/architectures.h"
-#include "test/UnitTest/FPMatcher.h"
-#include "test/UnitTest/Test.h"
-
-template <typename T>
-struct HypotTestTemplate : public LIBC_NAMESPACE::testing::Test {
- using Func = T (*)(T, T);
-
- DECLARE_SPECIAL_CONSTANTS(T)
-
- void test_special_numbers(Func func) {
+//===-- Utility class to test different flavors of hypot ------------------===//
+//
+// 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_TEST_SRC_MATH_HYPOTTEST_H
+#define LLVM_LIBC_TEST_SRC_MATH_HYPOTTEST_H
+
+#include "src/__support/macros/properties/architectures.h"
+#include "test/UnitTest/FPMatcher.h"
+#include "test/UnitTest/Test.h"
+
+template <typename T>
+struct HypotTestTemplate : public LIBC_NAMESPACE::testing::Test {
+ using Func = T (*)(T, T);
+
+ DECLARE_SPECIAL_CONSTANTS(T)
+
+ void test_special_numbers(Func func) {
constexpr int N = 4;
// Pythagorean triples.
constexpr T PYT[N][3] = {{T(3), T(4), T(5)},
@@ -27,31 +27,31 @@ struct HypotTestTemplate : public LIBC_NAMESPACE::testing::Test {
{T(8), T(15), T(17)},
{T(7), T(24), T(25)}};
-#ifndef LIBC_TARGET_ARCH_IS_NVPTX
- // TODO: Investigate why sNaN tests are failing on nVidia.
- // https://github.com/llvm/llvm-project/issues/99706.
- EXPECT_FP_EQ(func(inf, sNaN), aNaN);
- EXPECT_FP_EQ(func(sNaN, neg_inf), aNaN);
-#endif // !LIBC_TARGET_ARCH_IS_NVPTX
-
- EXPECT_FP_EQ(func(inf, aNaN), inf);
- EXPECT_FP_EQ(func(aNaN, neg_inf), inf);
- EXPECT_FP_EQ(func(aNaN, aNaN), aNaN);
- EXPECT_FP_EQ(func(aNaN, zero), aNaN);
- EXPECT_FP_EQ(func(neg_zero, aNaN), aNaN);
-
- for (int i = 0; i < N; ++i) {
- EXPECT_FP_EQ_ALL_ROUNDING(PYT[i][2], func(PYT[i][0], PYT[i][1]));
- EXPECT_FP_EQ_ALL_ROUNDING(PYT[i][2], func(-PYT[i][0], PYT[i][1]));
- EXPECT_FP_EQ_ALL_ROUNDING(PYT[i][2], func(PYT[i][0], -PYT[i][1]));
- EXPECT_FP_EQ_ALL_ROUNDING(PYT[i][2], func(-PYT[i][0], -PYT[i][1]));
-
- EXPECT_FP_EQ_ALL_ROUNDING(PYT[i][2], func(PYT[i][1], PYT[i][0]));
- EXPECT_FP_EQ_ALL_ROUNDING(PYT[i][2], func(-PYT[i][1], PYT[i][0]));
- EXPECT_FP_EQ_ALL_ROUNDING(PYT[i][2], func(PYT[i][1], -PYT[i][0]));
- EXPECT_FP_EQ_ALL_ROUNDING(PYT[i][2], func(-PYT[i][1], -PYT[i][0]));
- }
- }
-};
-
-#endif // LLVM_LIBC_TEST_SRC_MATH_HYPOTTEST_H
+#ifndef LIBC_TARGET_ARCH_IS_NVPTX
+ // TODO: Investigate why sNaN tests are failing on nVidia.
+ // https://github.com/llvm/llvm-project/issues/99706.
+ EXPECT_FP_EQ(func(inf, sNaN), aNaN);
+ EXPECT_FP_EQ(func(sNaN, neg_inf), aNaN);
+#endif // !LIBC_TARGET_ARCH_IS_NVPTX
+
+ EXPECT_FP_EQ(func(inf, aNaN), inf);
+ EXPECT_FP_EQ(func(aNaN, neg_inf), inf);
+ EXPECT_FP_EQ(func(aNaN, aNaN), aNaN);
+ EXPECT_FP_EQ(func(aNaN, zero), aNaN);
+ EXPECT_FP_EQ(func(neg_zero, aNaN), aNaN);
+
+ for (int i = 0; i < N; ++i) {
+ EXPECT_FP_EQ_ALL_ROUNDING(PYT[i][2], func(PYT[i][0], PYT[i][1]));
+ EXPECT_FP_EQ_ALL_ROUNDING(PYT[i][2], func(-PYT[i][0], PYT[i][1]));
+ EXPECT_FP_EQ_ALL_ROUNDING(PYT[i][2], func(PYT[i][0], -PYT[i][1]));
+ EXPECT_FP_EQ_ALL_ROUNDING(PYT[i][2], func(-PYT[i][0], -PYT[i][1]));
+
+ EXPECT_FP_EQ_ALL_ROUNDING(PYT[i][2], func(PYT[i][1], PYT[i][0]));
+ EXPECT_FP_EQ_ALL_ROUNDING(PYT[i][2], func(-PYT[i][1], PYT[i][0]));
+ EXPECT_FP_EQ_ALL_ROUNDING(PYT[i][2], func(PYT[i][1], -PYT[i][0]));
+ EXPECT_FP_EQ_ALL_ROUNDING(PYT[i][2], func(-PYT[i][1], -PYT[i][0]));
+ }
+ }
+};
+
+#endif // LLVM_LIBC_TEST_SRC_MATH_HYPOTTEST_H
>From 4ee582192e6ef5676c4c9ac9f95ab8e3d2142d5d Mon Sep 17 00:00:00 2001
From: Muhammad Bassiouni <60100307+bassiounix at users.noreply.github.com>
Date: Tue, 3 Mar 2026 00:48:57 +0200
Subject: [PATCH 27/30] Update libc/shared/math/hypotbf16.h
---
libc/shared/math/hypotbf16.h | 5 -----
1 file changed, 5 deletions(-)
diff --git a/libc/shared/math/hypotbf16.h b/libc/shared/math/hypotbf16.h
index d134d84a304aa..f1794a42c93c2 100644
--- a/libc/shared/math/hypotbf16.h
+++ b/libc/shared/math/hypotbf16.h
@@ -7,20 +7,15 @@
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIBC_SHARED_MATH_HYPOTBF16_H
-#define LLVM_LIBC_SHARED_MATH_HYPOTBF16_H
-
#include "shared/libc_common.h"
-
#include "src/__support/math/hypotbf16.h"
namespace LIBC_NAMESPACE_DECL {
-
namespace shared {
using math::hypotbf16;
} // namespace shared
-
} // namespace LIBC_NAMESPACE_DECL
#endif // LLVM_LIBC_SHARED_MATH_HYPOTBF16_H
>From 3f3b00056f140fe034ec47d0c0e71875a7008aa1 Mon Sep 17 00:00:00 2001
From: Muhammad Bassiouni <60100307+bassiounix at users.noreply.github.com>
Date: Tue, 3 Mar 2026 00:50:20 +0200
Subject: [PATCH 28/30] Apply suggestion from @bassiounix
---
libc/shared/math/hypotbf16.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/libc/shared/math/hypotbf16.h b/libc/shared/math/hypotbf16.h
index f1794a42c93c2..4922e23a73d5c 100644
--- a/libc/shared/math/hypotbf16.h
+++ b/libc/shared/math/hypotbf16.h
@@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIBC_SHARED_MATH_HYPOTBF16_H
+
#include "shared/libc_common.h"
#include "src/__support/math/hypotbf16.h"
>From 45d806cda265bbf840d4a23006d5ca840348d72e Mon Sep 17 00:00:00 2001
From: Muhammad Bassiouni <60100307+bassiounix at users.noreply.github.com>
Date: Tue, 3 Mar 2026 00:51:10 +0200
Subject: [PATCH 29/30] Apply suggestion from @bassiounix
---
libc/shared/math/hypotbf16.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/libc/shared/math/hypotbf16.h b/libc/shared/math/hypotbf16.h
index 4922e23a73d5c..0a78f366901a2 100644
--- a/libc/shared/math/hypotbf16.h
+++ b/libc/shared/math/hypotbf16.h
@@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIBC_SHARED_MATH_HYPOTBF16_H
+#define LLVM_LIBC_SHARED_MATH_HYPOTBF16_H
#include "shared/libc_common.h"
#include "src/__support/math/hypotbf16.h"
>From e79de3f75d9ac20f6b6887d19d8d31ceffc728c4 Mon Sep 17 00:00:00 2001
From: Muhammad Bassiouni <60100307+bassiounix at users.noreply.github.com>
Date: Tue, 3 Mar 2026 00:54:06 +0200
Subject: [PATCH 30/30] Update libc/src/__support/math/hypotbf16.h
---
libc/src/__support/math/hypotbf16.h | 4 ----
1 file changed, 4 deletions(-)
diff --git a/libc/src/__support/math/hypotbf16.h b/libc/src/__support/math/hypotbf16.h
index e04013e4e3d68..9d2ee54fc21d7 100644
--- a/libc/src/__support/math/hypotbf16.h
+++ b/libc/src/__support/math/hypotbf16.h
@@ -12,10 +12,7 @@
#include "src/__support/FPUtil/Hypot.h"
#include "src/__support/FPUtil/bfloat16.h"
#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
-
namespace LIBC_NAMESPACE_DECL {
-
namespace math {
LIBC_INLINE bfloat16 hypotbf16(bfloat16 x, bfloat16 y) {
@@ -23,7 +20,6 @@ LIBC_INLINE bfloat16 hypotbf16(bfloat16 x, bfloat16 y) {
}
} // namespace math
-
} // namespace LIBC_NAMESPACE_DECL
#endif // LLVM_LIBC_SRC___SUPPORT_MATH_HYPOTBF16_H
More information about the llvm-commits
mailing list