[libc-commits] [libc] [libc] Fix hypotbf16 ABI difference Issue (PR #214966)
via libc-commits
libc-commits at lists.llvm.org
Sat Aug 8 22:06:06 PDT 2026
https://github.com/Sukumarsawant updated https://github.com/llvm/llvm-project/pull/214966
>From 1b8f6d6778b939717b7db25123d23470238401a8 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Sat, 8 Aug 2026 19:55:48 +0530
Subject: [PATCH 1/3] Tests: adding native for I/O and emulated for internal
calculations
---
libc/src/math/generic/hypotbf16.cpp | 4 ++--
libc/src/math/hypotbf16.h | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/libc/src/math/generic/hypotbf16.cpp b/libc/src/math/generic/hypotbf16.cpp
index 0c1a3ed84021b..a1a9f97d48160 100644
--- a/libc/src/math/generic/hypotbf16.cpp
+++ b/libc/src/math/generic/hypotbf16.cpp
@@ -11,8 +11,8 @@
namespace LIBC_NAMESPACE_DECL {
-LLVM_LIBC_FUNCTION(bfloat16, hypotbf16, (bfloat16 x, bfloat16 y)) {
- return math::hypotbf16(x, y);
+LLVM_LIBC_FUNCTION(__bf16, hypotbf16, (__bf16 x, __bf16 y)) {
+ return static_cast<__bf16>(math::hypotbf16(bfloat16(x), bfloat16(y)));
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/hypotbf16.h b/libc/src/math/hypotbf16.h
index db1365d791dba..fe9e95fc70167 100644
--- a/libc/src/math/hypotbf16.h
+++ b/libc/src/math/hypotbf16.h
@@ -14,7 +14,7 @@
namespace LIBC_NAMESPACE_DECL {
-bfloat16 hypotbf16(bfloat16 x, bfloat16 y);
+__bf16 hypotbf16(__bf16(x), __bf16(y));
} // namespace LIBC_NAMESPACE_DECL
>From a86a865e71a3f7370349901a604edc46e45b1ec6 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Sat, 8 Aug 2026 20:02:48 +0530
Subject: [PATCH 2/3] add bit_cast
---
libc/src/math/generic/hypotbf16.cpp | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/libc/src/math/generic/hypotbf16.cpp b/libc/src/math/generic/hypotbf16.cpp
index a1a9f97d48160..baef9f6407ba6 100644
--- a/libc/src/math/generic/hypotbf16.cpp
+++ b/libc/src/math/generic/hypotbf16.cpp
@@ -7,12 +7,15 @@
//===----------------------------------------------------------------------===//
#include "src/math/hypotbf16.h"
+#include "src/__support/CPP/bit.h"
#include "src/__support/math/hypotbf16.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(__bf16, hypotbf16, (__bf16 x, __bf16 y)) {
- return static_cast<__bf16>(math::hypotbf16(bfloat16(x), bfloat16(y)));
+ return cpp::bit_cast<__bf16>(
+ math::hypotbf16(cpp::bit_cast<bfloat16>(x), cpp::bit_cast<bfloat16>(y))
+ .bits);
}
} // namespace LIBC_NAMESPACE_DECL
>From b25f8f78ff5925f27c09c6cd9536216a6f947282 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Sun, 9 Aug 2026 10:35:44 +0530
Subject: [PATCH 3/3] nit
---
libc/src/math/generic/hypotbf16.cpp | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/libc/src/math/generic/hypotbf16.cpp b/libc/src/math/generic/hypotbf16.cpp
index baef9f6407ba6..e5c468bca1d29 100644
--- a/libc/src/math/generic/hypotbf16.cpp
+++ b/libc/src/math/generic/hypotbf16.cpp
@@ -14,8 +14,7 @@ namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(__bf16, hypotbf16, (__bf16 x, __bf16 y)) {
return cpp::bit_cast<__bf16>(
- math::hypotbf16(cpp::bit_cast<bfloat16>(x), cpp::bit_cast<bfloat16>(y))
- .bits);
+ math::hypotbf16(cpp::bit_cast<bfloat16>(x), cpp::bit_cast<bfloat16>(y)));
}
} // namespace LIBC_NAMESPACE_DECL
More information about the libc-commits
mailing list