[libc-commits] [libc] [llvm] [libc][math][c23] Add hypotbf16 function (PR #183460)
via libc-commits
libc-commits at lists.llvm.org
Thu Mar 12 23:14:21 PDT 2026
https://github.com/Sukumarsawant 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 1/3] 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 2/3] 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 9a36e6e78899bb493c8eb3723e6002791d235b40 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Thu, 26 Feb 2026 00:13:08 +0530
Subject: [PATCH 3/3] feat: exhaustive, smoke, unit tests added
exhaustive test added [positive range + special] + implemented +smoke tests
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
added true exhaustive test
reverted additional line + checking CRLF errors
test
formatted
clang-format errors
formatted
added missed dependency for bfloat
CHANGE: repositions in entrypoints.txt
REFACTOR: refactored hypotbf16 to header
FIX: Typo
FORMAT: Bazel
remove: removed redundancy
chore: smoke uses HypotTest.h now
chore: cmake updated
requested changes
fix: conflicts
test: cmake
chore: nit fix
fix: typecast
chore: clang
chore: nit
chore: lf
chore: exhaustive test synced
chore: optimization
chore: redundant
chore: nit
added exhaustive test
---
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 | 2 +-
libc/docs/headers/math/index.rst | 2 +-
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/CMakeLists.txt | 1 +
libc/src/math/generic/CMakeLists.txt | 1 -
libc/src/math/generic/hypotbf16.cpp | 8 +--
libc/src/math/hypotbf16.h | 21 ++++++
libc/test/shared/CMakeLists.txt | 1 +
libc/test/shared/shared_math_test.cpp | 3 +
libc/test/src/math/CMakeLists.txt | 13 ++++
libc/test/src/math/exhaustive/CMakeLists.txt | 18 +++++
.../src/math/exhaustive/hypotbf16_test.cpp | 71 +++++++++++++++++++
libc/test/src/math/hypotbf16_test.cpp | 22 ++++++
libc/test/src/math/smoke/CMakeLists.txt | 14 ++++
libc/test/src/math/smoke/HypotTest.h | 5 +-
libc/test/src/math/smoke/hypotbf16_test.cpp | 18 +++++
.../llvm-project-overlay/libc/BUILD.bazel | 18 +++++
31 files changed, 288 insertions(+), 19 deletions(-)
create mode 100644 libc/shared/math/hypotbf16.h
create mode 100644 libc/src/__support/math/hypotbf16.h
create mode 100644 libc/src/math/hypotbf16.h
create mode 100644 libc/test/src/math/exhaustive/hypotbf16_test.cpp
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/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..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
@@ -345,6 +344,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/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/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..82c573cfc7ba7 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..e04013e4e3d68
--- /dev/null
+++ b/libc/src/__support/math/hypotbf16.h
@@ -0,0 +1,29 @@
+//===-- 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/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/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/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 3bc0b9aa39491..c132752dc4d36 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -3024,7 +3024,6 @@ add_entrypoint_object(
../hypotbf16.h
DEPENDS
libc.src.__support.math.hypotbf16
- libc.src.math.hypotbf16
)
add_entrypoint_object(
diff --git a/libc/src/math/generic/hypotbf16.cpp b/libc/src/math/generic/hypotbf16.cpp
index 78ecc51dfb4ce..0c1a3ed84021b 100644
--- a/libc/src/math/generic/hypotbf16.cpp
+++ b/libc/src/math/generic/hypotbf16.cpp
@@ -1,18 +1,18 @@
-//===-- 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.
// 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);
+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/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/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/exhaustive/CMakeLists.txt b/libc/test/src/math/exhaustive/CMakeLists.txt
index a21e208312c56..461909323b791 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.bfloat16
+ LINK_LIBRARIES
+ -lpthread
+)
+
add_fp_unittest(
hypotf_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..3269cfc321890
--- /dev/null
+++ b/libc/test/src/math/exhaustive/hypotbf16_test.cpp
@@ -0,0 +1,71 @@
+//===-- 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 "exhaustive_test.h"
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/FPUtil/Hypot.h"
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/hypotbf16.h"
+#include "test/UnitTest/FPMatcher.h"
+#include "utils/MPFRWrapper/MPFRUtils.h"
+
+namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
+
+struct Hypotbf16Checker : public virtual LIBC_NAMESPACE::testing::Test {
+ using FloatType = bfloat16;
+ using FPBits = LIBC_NAMESPACE::fputil::FPBits<bfloat16>;
+ using StorageType = typename FPBits::StorageType;
+
+ uint64_t check(uint16_t x_start, uint16_t x_stop,uint16_t y_start, uint16_t y_stop,mpfr::RoundingMode rounding) {
+ mpfr::ForceRoundingMode r(rounding);
+ if (!r.success)
+ return true;
+ uint16_t xbits = x_start;
+ uint64_t failed = 0;
+ do {
+ bfloat16 x = FPBits(xbits).get_val();
+ uint16_t ybits = y_start;
+ do {
+ bfloat16 y = FPBits(ybits).get_val();
+ mpfr::BinaryInput<bfloat16> input{x, y};
+ bool correct = TEST_MPFR_MATCH_ROUNDING_SILENTLY(
+ mpfr::Operation::Hypot, input, LIBC_NAMESPACE::hypotbf16(x, y), 0.5,
+ rounding);
+ failed += (!correct);
+ } while (ybits++ < y_stop);
+ } while (xbits++ < x_stop);
+ return failed;
+ }
+};
+
+using LlvmLibcHypotBf16ExhaustiveTest =
+ LlvmLibcExhaustiveMathTest<Hypotbf16Checker, 1 << 2>;
+
+// range: [0, inf]
+static constexpr uint16_t POS_START = 0x0000U;
+static constexpr uint16_t POS_STOP = 0x7f80U;
+
+// range: [-0, -inf]
+static constexpr uint16_t NEG_START = 0x8000U;
+static constexpr uint16_t NEG_STOP = 0xff80U;
+
+TEST_F(LlvmLibcHypotBf16ExhaustiveTest, PositiveRange) {
+ test_full_range_all_roundings(POS_START, POS_STOP, POS_START, POS_STOP);
+}
+
+TEST_F(LlvmLibcHypotBf16ExhaustiveTest, NegativeRange) {
+ test_full_range_all_roundings(NEG_START, NEG_STOP, NEG_START, NEG_STOP);
+}
+
+TEST_F(LlvmLibcHypotBf16ExhaustiveTest, PositiveNegativeRange) {
+ test_full_range_all_roundings(POS_START, POS_STOP, NEG_START, NEG_STOP);
+}
+
+TEST_F(LlvmLibcHypotBf16ExhaustiveTest, NegativePositiveRange) {
+ test_full_range_all_roundings(NEG_START, NEG_STOP, POS_START, POS_STOP);
+}
diff --git a/libc/test/src/math/hypotbf16_test.cpp b/libc/test/src/math/hypotbf16_test.cpp
new file mode 100644
index 0000000000000..a757ff751ba77
--- /dev/null
+++ b/libc/test/src/math/hypotbf16_test.cpp
@@ -0,0 +1,22 @@
+//===-- 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.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "HypotTest.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/hypotbf16.h"
+
+using LlvmLibcHypotbf16Test = HypotTestTemplate<bfloat16>;
+
+TEST_F(LlvmLibcHypotbf16Test, SubnormalRange) {
+ test_subnormal_range(&LIBC_NAMESPACE::hypotbf16);
+}
+
+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 3d52873c40bb8..464fa3498ca6f 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -3743,6 +3743,20 @@ 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
+ libc.src.__support.FPUtil.fp_bits
+)
+
add_fp_unittest(
nanf_test
SUITE
diff --git a/libc/test/src/math/smoke/HypotTest.h b/libc/test/src/math/smoke/HypotTest.h
index 30d57a4fe2a26..800b5c41daadb 100644
--- a/libc/test/src/math/smoke/HypotTest.h
+++ b/libc/test/src/math/smoke/HypotTest.h
@@ -22,7 +22,10 @@ struct HypotTestTemplate : public LIBC_NAMESPACE::testing::Test {
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}};
+ 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.
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..c39971ecdd512
--- /dev/null
+++ b/libc/test/src/math/smoke/hypotbf16_test.cpp
@@ -0,0 +1,18 @@
+//===-- 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/__support/FPUtil/bfloat16.h"
+#include "src/math/hypotbf16.h"
+
+using LlvmLibcHypotBf16Test = HypotTestTemplate<bfloat16>;
+
+TEST_F(LlvmLibcHypotBf16Test, SpecialNumbers) {
+ test_special_numbers(&LIBC_NAMESPACE::hypotbf16);
+}
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 87d1d88e971bf..c57f0f978c483 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_common",
+ ":__support_fputil_bfloat16",
+ ":__support_fputil_hypot",
+ ":__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 = [
More information about the libc-commits
mailing list