[llvm-branch-commits] [libc] [libc][math][c++23] Add {modf, remainder, remquo}bf16 math functions (PR #154652)
https://github.com/krishna2803 updated
https://github.com/llvm/llvm-project/pull/154652
>From fc5e2152b4c57238ed424138ca27de1635146ef5 Mon Sep 17 00:00:00 2001
From: Krishna Pandey
Date: Wed, 20 Aug 2025 03:43:58 +0530
Subject: [PATCH 1/6] feat: implement {modf,remainder,remquo}bf16 math
functions
Signed-off-by: Krishna Pandey
---
libc/src/math/CMakeLists.txt| 6 ++-
libc/src/math/generic/CMakeLists.txt| 58 +
libc/src/math/generic/modfbf16.cpp | 21 +
libc/src/math/generic/remainderbf16.cpp | 22 ++
libc/src/math/generic/remquobf16.cpp| 21 +
libc/src/math/modfbf16.h| 21 +
libc/src/math/remainderbf16.h | 21 +
libc/src/math/remquobf16.h | 21 +
8 files changed, 190 insertions(+), 1 deletion(-)
create mode 100644 libc/src/math/generic/modfbf16.cpp
create mode 100644 libc/src/math/generic/remainderbf16.cpp
create mode 100644 libc/src/math/generic/remquobf16.cpp
create mode 100644 libc/src/math/modfbf16.h
create mode 100644 libc/src/math/remainderbf16.h
create mode 100644 libc/src/math/remquobf16.h
diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index b1d76c6008cf5..6cc221178df94 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -300,6 +300,7 @@ add_math_entrypoint_object(fmodf)
add_math_entrypoint_object(fmodl)
add_math_entrypoint_object(fmodf16)
add_math_entrypoint_object(fmodf128)
+add_math_entrypoint_object(fmodbf16)
add_math_entrypoint_object(frexp)
add_math_entrypoint_object(frexpf)
@@ -419,6 +420,7 @@ add_math_entrypoint_object(modff)
add_math_entrypoint_object(modfl)
add_math_entrypoint_object(modff16)
add_math_entrypoint_object(modff128)
+add_math_entrypoint_object(modfbf16)
add_math_entrypoint_object(nan)
add_math_entrypoint_object(nanf)
@@ -470,12 +472,14 @@ add_math_entrypoint_object(remainderf)
add_math_entrypoint_object(remainderl)
add_math_entrypoint_object(remainderf16)
add_math_entrypoint_object(remainderf128)
+add_math_entrypoint_object(remainderbf16)
add_math_entrypoint_object(remquo)
add_math_entrypoint_object(remquof)
-add_math_entrypoint_object(remquof128)
add_math_entrypoint_object(remquol)
add_math_entrypoint_object(remquof16)
+add_math_entrypoint_object(remquof128)
+add_math_entrypoint_object(remquobf16)
add_math_entrypoint_object(rint)
add_math_entrypoint_object(rintf)
diff --git a/libc/src/math/generic/CMakeLists.txt
b/libc/src/math/generic/CMakeLists.txt
index 3dbc54a819722..46de2e09d3ba9 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -2280,6 +2280,21 @@ add_entrypoint_object(
libc.src.__support.FPUtil.manipulation_functions
)
+add_entrypoint_object(
+ modfbf16
+ SRCS
+modfbf16.cpp
+ HDRS
+../modfbf16.h
+ DEPENDS
+libc.src.__support.common
+libc.src.__support.FPUtil.bfloat16
+libc.src.__support.FPUtil.manipulation_functions
+libc.src.__support.macros.config
+libc.src.__support.macros.properties.types
+)
+
+
add_entrypoint_object(
fmin
SRCS
@@ -3184,6 +3199,21 @@ add_entrypoint_object(
libc.src.__support.FPUtil.division_and_remainder_operations
)
+add_entrypoint_object(
+ remquobf16
+ SRCS
+remquobf16.cpp
+ HDRS
+../remquobf16.h
+ DEPENDS
+libc.src.__support.common
+libc.src.__support.FPUtil.bfloat16
+libc.src.__support.FPUtil.division_and_remainder_operations
+libc.src.__support.macros.properties.types
+libc.src.__support.macros.config
+)
+
+
add_entrypoint_object(
remainderf
SRCS
@@ -3236,6 +3266,20 @@ add_entrypoint_object(
libc.src.__support.FPUtil.division_and_remainder_operations
)
+add_entrypoint_object(
+ remainderbf16
+ SRCS
+remainderbf16.cpp
+ HDRS
+../remainderbf16.h
+ DEPENDS
+libc.src.__support.common
+libc.src.__support.FPUtil.bfloat16
+libc.src.__support.FPUtil.division_and_remainder_operations
+libc.src.__support.macros.properties.types
+libc.src.__support.macros.config
+)
+
add_entrypoint_object(
hypotf
SRCS
@@ -3835,6 +3879,20 @@ add_entrypoint_object(
libc.src.__support.FPUtil.generic.fmod
)
+add_entrypoint_object(
+ fmodbf16
+ SRCS
+fmodbf16.cpp
+ HDRS
+../fmodbf16.h
+ DEPENDS
+libc.src.__support.common
+libc.src.__support.FPUtil.bfloat16
+libc.src.__support.FPUtil.generic.fmod
+libc.src.__support.macros.config
+libc.src.__support.macros.properties.types
+)
+
add_entrypoint_object(
fromfp
SRCS
diff --git a/libc/src/math/generic/modfbf16.cpp
b/libc/src/math/generic/modfbf16.cpp
new file mode 100644
index 0..09458f6a2db40
--- /dev/null
+++ b/libc/src/math/generic/modfbf16.cpp
@@ -0,0 +1,21 @@
+//===-- Implementation of modfbf16 function
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM
Exceptions.
+// See https://llvm.org/LI
[llvm-branch-commits] [libc] [libc][math][c++23] Add {get, set}payloadbf16 and setpayloadsigbf16 math functions (PR #153994)
https://github.com/krishna2803 created
https://github.com/llvm/llvm-project/pull/153994
This PR adds the following basic math functions for BFloat16 type along with
the tests:
- getpayloadbf16
- setpayloadbf16
- setpayloadsigbf16
>From 6f8d84d83beff959e838c70057f2e4bb29f0bc4c Mon Sep 17 00:00:00 2001
From: Krishna Pandey
Date: Sun, 17 Aug 2025 08:09:15 +0530
Subject: [PATCH 1/5] feat: implement {get,set}payloadbf16 and
setpayloadsigbf16 math functions
Signed-off-by: Krishna Pandey
---
libc/src/math/CMakeLists.txt| 3 ++
libc/src/math/generic/CMakeLists.txt| 42 +
libc/src/math/generic/getpayloadbf16.cpp| 21 +++
libc/src/math/generic/setpayloadbf16.cpp| 21 +++
libc/src/math/generic/setpayloadsigbf16.cpp | 21 +++
libc/src/math/getpayloadbf16.h | 21 +++
libc/src/math/setpayloadbf16.h | 21 +++
libc/src/math/setpayloadsigbf16.h | 21 +++
8 files changed, 171 insertions(+)
create mode 100644 libc/src/math/generic/getpayloadbf16.cpp
create mode 100644 libc/src/math/generic/setpayloadbf16.cpp
create mode 100644 libc/src/math/generic/setpayloadsigbf16.cpp
create mode 100644 libc/src/math/getpayloadbf16.h
create mode 100644 libc/src/math/setpayloadbf16.h
create mode 100644 libc/src/math/setpayloadsigbf16.h
diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index 3843247c4fa5b..023829b21996f 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -330,6 +330,7 @@ add_math_entrypoint_object(getpayloadf)
add_math_entrypoint_object(getpayloadl)
add_math_entrypoint_object(getpayloadf16)
add_math_entrypoint_object(getpayloadf128)
+add_math_entrypoint_object(getpayloadbf16)
add_math_entrypoint_object(hypot)
add_math_entrypoint_object(hypotf)
@@ -507,12 +508,14 @@ add_math_entrypoint_object(setpayloadf)
add_math_entrypoint_object(setpayloadl)
add_math_entrypoint_object(setpayloadf16)
add_math_entrypoint_object(setpayloadf128)
+add_math_entrypoint_object(setpayloadbf16)
add_math_entrypoint_object(setpayloadsig)
add_math_entrypoint_object(setpayloadsigf)
add_math_entrypoint_object(setpayloadsigl)
add_math_entrypoint_object(setpayloadsigf16)
add_math_entrypoint_object(setpayloadsigf128)
+add_math_entrypoint_object(setpayloadsigbf16)
add_math_entrypoint_object(sincos)
add_math_entrypoint_object(sincosf)
diff --git a/libc/src/math/generic/CMakeLists.txt
b/libc/src/math/generic/CMakeLists.txt
index 822da74d7597e..38ba34ae521ea 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -4609,6 +4609,20 @@ add_entrypoint_object(
libc.src.__support.FPUtil.basic_operations
)
+add_entrypoint_object(
+ getpayloadbf16
+ SRCS
+getpayloadbf16.cpp
+ HDRS
+../getpayloadbf16.h
+ DEPENDS
+libc.src.__support.common
+libc.src.__support.FPUtil.basic_operations
+libc.src.__support.FPUtil.bfloat16
+libc.src.__support.macros.config
+libc.src.__support.macros.properties.types
+)
+
add_entrypoint_object(
setpayload
SRCS
@@ -4661,6 +4675,20 @@ add_entrypoint_object(
libc.src.__support.FPUtil.basic_operations
)
+add_entrypoint_object(
+ setpayloadbf16
+ SRCS
+setpayloadbf16.cpp
+ HDRS
+../setpayloadbf16.h
+ DEPENDS
+libc.src.__support.common
+libc.src.__support.FPUtil.basic_operations
+libc.src.__support.FPUtil.bfloat16
+libc.src.__support.macros.config
+libc.src.__support.macros.properties.types
+)
+
add_entrypoint_object(
setpayloadsig
SRCS
@@ -4713,6 +4741,20 @@ add_entrypoint_object(
libc.src.__support.FPUtil.basic_operations
)
+add_entrypoint_object(
+ setpayloadsigbf16
+ SRCS
+setpayloadsigbf16.cpp
+ HDRS
+../setpayloadsigbf16.h
+ DEPENDS
+libc.src.__support.common
+libc.src.__support.FPUtil.basic_operations
+libc.src.__support.FPUtil.bfloat16
+libc.src.__support.macros.config
+libc.src.__support.macros.properties.types
+)
+
add_entrypoint_object(
f16add
SRCS
diff --git a/libc/src/math/generic/getpayloadbf16.cpp
b/libc/src/math/generic/getpayloadbf16.cpp
new file mode 100644
index 0..544ed0a2f5c9d
--- /dev/null
+++ b/libc/src/math/generic/getpayloadbf16.cpp
@@ -0,0 +1,21 @@
+//===-- Implementation of getpayloadbf16 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/getpayloadbf16.h"
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(bfloat16, getpayloadbf16, (c
[llvm-branch-commits] [libc] [libc][math][c++23] Add next{after, down, toward, up}bf16 math functions (PR #153993)
https://github.com/krishna2803 created
https://github.com/llvm/llvm-project/pull/153993
This PR adds the following basic math functions for BFloat16 type along with
the tests:
- nextafterbf16
- nextdownbf16
- nexttowardbf16
- nextupbf16
>From 4a80312010e3adaff8873a40831e74d393a1d71c Mon Sep 17 00:00:00 2001
From: Krishna Pandey
Date: Sun, 17 Aug 2025 05:59:39 +0530
Subject: [PATCH 1/4] feat: implement next{after,down,toward,up}bf16 math
functions
Signed-off-by: Krishna Pandey
---
libc/src/math/CMakeLists.txt | 4 ++
libc/src/math/generic/CMakeLists.txt | 56
libc/src/math/generic/nextafterbf16.cpp | 21 +
libc/src/math/generic/nextdownbf16.cpp | 21 +
libc/src/math/generic/nexttowardbf16.cpp | 22 ++
libc/src/math/generic/nextupbf16.cpp | 21 +
libc/src/math/nextafterbf16.h| 21 +
libc/src/math/nextdownbf16.h | 21 +
libc/src/math/nexttowardbf16.h | 21 +
libc/src/math/nextupbf16.h | 21 +
10 files changed, 229 insertions(+)
create mode 100644 libc/src/math/generic/nextafterbf16.cpp
create mode 100644 libc/src/math/generic/nextdownbf16.cpp
create mode 100644 libc/src/math/generic/nexttowardbf16.cpp
create mode 100644 libc/src/math/generic/nextupbf16.cpp
create mode 100644 libc/src/math/nextafterbf16.h
create mode 100644 libc/src/math/nextdownbf16.h
create mode 100644 libc/src/math/nexttowardbf16.h
create mode 100644 libc/src/math/nextupbf16.h
diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index f94120272ce66..3843247c4fa5b 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -431,23 +431,27 @@ add_math_entrypoint_object(nextafterf)
add_math_entrypoint_object(nextafterl)
add_math_entrypoint_object(nextafterf16)
add_math_entrypoint_object(nextafterf128)
+add_math_entrypoint_object(nextafterbf16)
add_math_entrypoint_object(nexttoward)
add_math_entrypoint_object(nexttowardf)
add_math_entrypoint_object(nexttowardl)
add_math_entrypoint_object(nexttowardf16)
+add_math_entrypoint_object(nexttowardbf16)
add_math_entrypoint_object(nextdown)
add_math_entrypoint_object(nextdownf)
add_math_entrypoint_object(nextdownl)
add_math_entrypoint_object(nextdownf16)
add_math_entrypoint_object(nextdownf128)
+add_math_entrypoint_object(nextdownbf16)
add_math_entrypoint_object(nextup)
add_math_entrypoint_object(nextupf)
add_math_entrypoint_object(nextupl)
add_math_entrypoint_object(nextupf16)
add_math_entrypoint_object(nextupf128)
+add_math_entrypoint_object(nextupbf16)
add_math_entrypoint_object(pow)
add_math_entrypoint_object(powf)
diff --git a/libc/src/math/generic/CMakeLists.txt
b/libc/src/math/generic/CMakeLists.txt
index 1608bed87cb6b..822da74d7597e 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -3496,6 +3496,20 @@ add_entrypoint_object(
libc.src.__support.FPUtil.manipulation_functions
)
+add_entrypoint_object(
+ nextafterbf16
+ SRCS
+nextafterbf16.cpp
+ HDRS
+../nextafterbf16.h
+ DEPENDS
+libc.src.__support.common
+libc.src.__support.FPUtil.bfloat16
+libc.src.__support.FPUtil.manipulation_functions
+libc.src.__support.macros.config
+libc.src.__support.macros.properties.types
+)
+
add_entrypoint_object(
nexttoward
SRCS
@@ -3537,6 +3551,20 @@ add_entrypoint_object(
libc.src.__support.FPUtil.manipulation_functions
)
+add_entrypoint_object(
+ nexttowardbf16
+ SRCS
+nexttowardbf16.cpp
+ HDRS
+../nexttowardbf16.h
+ DEPENDS
+libc.src.__support.common
+libc.src.__support.FPUtil.bfloat16
+libc.src.__support.FPUtil.manipulation_functions
+libc.src.__support.macros.config
+libc.src.__support.macros.properties.types
+)
+
add_entrypoint_object(
nextdown
SRCS
@@ -3589,6 +3617,20 @@ add_entrypoint_object(
libc.src.__support.FPUtil.manipulation_functions
)
+add_entrypoint_object(
+ nextdownbf16
+ SRCS
+nextdownbf16.cpp
+ HDRS
+../nextdownbf16.h
+ DEPENDS
+libc.src.__support.common
+libc.src.__support.FPUtil.bfloat16
+libc.src.__support.FPUtil.manipulation_functions
+libc.src.__support.macros.config
+libc.src.__support.macros.properties.types
+)
+
add_entrypoint_object(
nextup
SRCS
@@ -3641,6 +3683,20 @@ add_entrypoint_object(
libc.src.__support.FPUtil.manipulation_functions
)
+add_entrypoint_object(
+ nextupbf16
+ SRCS
+nextupbf16.cpp
+ HDRS
+../nextupbf16.h
+ DEPENDS
+libc.src.__support.common
+libc.src.__support.FPUtil.bfloat16
+libc.src.__support.FPUtil.manipulation_functions
+libc.src.__support.macros.config
+libc.src.__support.macros.properties.types
+)
+
add_entrypoint_object(
fmod
SRCS
diff --git a/libc/src/math/generic/nextafterbf16.cpp
b/libc/src/math/generic/nextafterbf16.cpp
new file mode 100644
index 0..e21a2dcb3d664
--- /dev/
[llvm-branch-commits] [libc] [libc][math][c++23] Add nanbf16 math function (PR #153995)
https://github.com/krishna2803 created
https://github.com/llvm/llvm-project/pull/153995
This PR adds the nanbf16 basic math function for BFloat16 type along with the
tests.
>From ea9625e60eb47e205c8acb8d9f4cabcd1959c8e6 Mon Sep 17 00:00:00 2001
From: Krishna Pandey
Date: Sun, 17 Aug 2025 08:42:17 +0530
Subject: [PATCH 1/4] feat: implement nanbf16 math function
Signed-off-by: Krishna Pandey
---
libc/src/math/CMakeLists.txt | 1 +
libc/src/math/generic/CMakeLists.txt | 16
libc/src/math/generic/nanbf16.cpp| 25 +
libc/src/math/nanbf16.h | 21 +
4 files changed, 63 insertions(+)
create mode 100644 libc/src/math/generic/nanbf16.cpp
create mode 100644 libc/src/math/nanbf16.h
diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index 023829b21996f..87a341bb6267b 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -420,6 +420,7 @@ add_math_entrypoint_object(nanf)
add_math_entrypoint_object(nanl)
add_math_entrypoint_object(nanf16)
add_math_entrypoint_object(nanf128)
+add_math_entrypoint_object(nanbf16)
add_math_entrypoint_object(nearbyint)
add_math_entrypoint_object(nearbyintf)
diff --git a/libc/src/math/generic/CMakeLists.txt
b/libc/src/math/generic/CMakeLists.txt
index 38ba34ae521ea..e34e3f04ed8bd 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -3444,6 +3444,22 @@ add_entrypoint_object(
libc.src.errno.errno
)
+add_entrypoint_object(
+ nanbf16
+ SRCS
+nanbf16.cpp
+ HDRS
+../nanbf16.h
+ DEPENDS
+libc.src.errno.errno
+libc.src.__support.common
+libc.src.__support.FPUtil.bfloat16
+libc.src.__support.libc_errno
+libc.src.__support.macros.config
+libc.src.__support.macros.properties.types
+libc.src.__support.str_to_float
+)
+
add_entrypoint_object(
nextafter
SRCS
diff --git a/libc/src/math/generic/nanbf16.cpp
b/libc/src/math/generic/nanbf16.cpp
new file mode 100644
index 0..678dd6aed9ee3
--- /dev/null
+++ b/libc/src/math/generic/nanbf16.cpp
@@ -0,0 +1,25 @@
+//===-- Implementation of nanbf16 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/nanbf16.h"
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/common.h"
+#include "src/__support/libc_errno.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/str_to_float.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(bfloat16, nanbf16, (const char *arg)) {
+ auto result = internal::strtonan(arg);
+ if (result.has_error())
+libc_errno = result.error;
+ return result.value;
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/nanbf16.h b/libc/src/math/nanbf16.h
new file mode 100644
index 0..1551044677768
--- /dev/null
+++ b/libc/src/math/nanbf16.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for nanbf16 ---*- 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_NANBF16_H
+#define LLVM_LIBC_SRC_MATH_NANBF16_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+bfloat16 nanbf16(const char *arg);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_NANBF16_H
>From ae0e6165f51e45721fead6ba7af0adb29345b263 Mon Sep 17 00:00:00 2001
From: Krishna Pandey
Date: Sun, 17 Aug 2025 08:42:41 +0530
Subject: [PATCH 2/4] chore: add smoke tests for nanbf16 math function
Signed-off-by: Krishna Pandey
---
libc/test/src/math/smoke/CMakeLists.txt | 16 +++
libc/test/src/math/smoke/nanbf16_test.cpp | 55 +++
2 files changed, 71 insertions(+)
create mode 100644 libc/test/src/math/smoke/nanbf16_test.cpp
diff --git a/libc/test/src/math/smoke/CMakeLists.txt
b/libc/test/src/math/smoke/CMakeLists.txt
index 8c257664dd8d7..c26bd84e2ca9d 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -3515,6 +3515,22 @@ add_fp_unittest(
UNIT_TEST_ONLY
)
+add_fp_unittest(
+ nanbf16_test
+ SUITE
+libc-math-smoke-tests
+ SRCS
+nanbf16_test.cpp
+ DEPENDS
+libc.hdr.signal_macros
+libc.src.math.nanbf16
+libc.src.__support.FPUtil.bfloat16
+libc.src.__support.FPUtil.fp_bits
+ # FIXME: The nan tests currently have death tests, which aren't supported for
+ # h
[llvm-branch-commits] [libc] [libc][math][c++23] Add fmodbf16 math function (PR #155575)
@@ -165,10 +175,10 @@ class FmodTest : public
LIBC_NAMESPACE::testing::FEnvSafeTest {
TEST_SPECIAL(neg_sNaN, sNaN, aNaN, false, FE_INVALID);
TEST_SPECIAL(neg_sNaN, neg_sNaN, aNaN, false, FE_INVALID);
-TEST_SPECIAL(T(6.5), T(2.25), T(2.0), false, 0);
-TEST_SPECIAL(T(-6.5), T(2.25), T(-2.0), false, 0);
-TEST_SPECIAL(T(6.5), T(-2.25), T(2.0), false, 0);
-TEST_SPECIAL(T(-6.5), T(-2.25), T(-2.0), false, 0);
+TEST_SPECIAL(six_halves, two_quaters, two, false, 0);
+TEST_SPECIAL(neg_six_halves, two_quaters, neg_two, false, 0);
+TEST_SPECIAL(six_halves, neg_two_quaters, two, false, 0);
+TEST_SPECIAL(neg_six_halves, neg_two_quaters, neg_two, false, 0);
krishna2803 wrote:
you mean removing these tests or reverting these changes?
https://github.com/llvm/llvm-project/pull/155575
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [libc] [libc][math][c++23] Add totalorder{, mag}bf16 math functions (PR #155568)
https://github.com/krishna2803 created
https://github.com/llvm/llvm-project/pull/155568
This PR adds the following basic math functions for BFloat16 type along with
the tests:
- totalorderbf16
- totalordermagbf16
>From 204df3472901aba6382817f36b1f3d19e80d662a Mon Sep 17 00:00:00 2001
From: Krishna Pandey
Date: Wed, 27 Aug 2025 12:43:27 +0530
Subject: [PATCH 1/4] feat: implement totalorder{,mag}bf16 math functions
Signed-off-by: Krishna Pandey
---
libc/src/math/CMakeLists.txt| 2 ++
libc/src/math/generic/CMakeLists.txt| 29 +
libc/src/math/generic/totalorderbf16.cpp| 22
libc/src/math/generic/totalordermagbf16.cpp | 22
libc/src/math/totalorderbf16.h | 21 +++
libc/src/math/totalordermagbf16.h | 21 +++
6 files changed, 117 insertions(+)
create mode 100644 libc/src/math/generic/totalorderbf16.cpp
create mode 100644 libc/src/math/generic/totalordermagbf16.cpp
create mode 100644 libc/src/math/totalorderbf16.h
create mode 100644 libc/src/math/totalordermagbf16.h
diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index e6a2f868e46b5..1edb517421e28 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -579,12 +579,14 @@ add_math_entrypoint_object(totalorderf)
add_math_entrypoint_object(totalorderl)
add_math_entrypoint_object(totalorderf16)
add_math_entrypoint_object(totalorderf128)
+add_math_entrypoint_object(totalorderbf16)
add_math_entrypoint_object(totalordermag)
add_math_entrypoint_object(totalordermagf)
add_math_entrypoint_object(totalordermagl)
add_math_entrypoint_object(totalordermagf16)
add_math_entrypoint_object(totalordermagf128)
+add_math_entrypoint_object(totalordermagbf16)
add_math_entrypoint_object(trunc)
add_math_entrypoint_object(truncf)
diff --git a/libc/src/math/generic/CMakeLists.txt
b/libc/src/math/generic/CMakeLists.txt
index 70ca5c51990de..904f8d2eb4704 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -4784,6 +4784,21 @@ add_entrypoint_object(
libc.src.__support.FPUtil.basic_operations
libc.src.__support.macros.properties.types
)
+
+add_entrypoint_object(
+ totalorderbf16
+ SRCS
+totalorderbf16.cpp
+ HDRS
+../totalorderbf16.h
+ DEPENDS
+libc.src.__support.common
+libc.src.__support.macros.config
+libc.src.__support.macros.properties.types
+libc.src.__support.FPUtil.basic_operations
+libc.src.__support.FPUtil.bfloat16
+)
+
add_entrypoint_object(
totalordermag
SRCS
@@ -4835,6 +4850,20 @@ add_entrypoint_object(
libc.src.__support.macros.properties.types
)
+add_entrypoint_object(
+ totalordermagbf16
+ SRCS
+totalordermagbf16.cpp
+ HDRS
+../totalordermagbf16.h
+ DEPENDS
+libc.src.__support.common
+libc.src.__support.macros.config
+libc.src.__support.macros.properties.types
+libc.src.__support.FPUtil.basic_operations
+libc.src.__support.FPUtil.bfloat16
+)
+
add_entrypoint_object(
getpayload
SRCS
diff --git a/libc/src/math/generic/totalorderbf16.cpp
b/libc/src/math/generic/totalorderbf16.cpp
new file mode 100644
index 0..bb9c86e281f6b
--- /dev/null
+++ b/libc/src/math/generic/totalorderbf16.cpp
@@ -0,0 +1,22 @@
+//===-- Implementation of totalorderbf16 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/totalorderbf16.h"
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(int, totalorderbf16,
+ (const bfloat16 *x, const bfloat16 *y)) {
+ return static_cast(fputil::totalorder(*x, *y));
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/totalordermagbf16.cpp
b/libc/src/math/generic/totalordermagbf16.cpp
new file mode 100644
index 0..3fc61d9d8bcb4
--- /dev/null
+++ b/libc/src/math/generic/totalordermagbf16.cpp
@@ -0,0 +1,22 @@
+//===-- Implementation of totalordermagbf16 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/totalordermagbf16.h"
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+na
[llvm-branch-commits] [libc] [libc][math][c++23] Add scalb{, l}nbf16 math functions (PR #155569)
https://github.com/krishna2803 created
https://github.com/llvm/llvm-project/pull/155569
This PR adds the following basic math functions for BFloat16 type along with
the tests:
- scalbnbf16
- scalblnbf16
>From b633a7651bfe97a3f23b911c4c28b39f28abe5c3 Mon Sep 17 00:00:00 2001
From: Krishna Pandey
Date: Wed, 27 Aug 2025 12:54:58 +0530
Subject: [PATCH 1/4] feat: implement scalb{,l}nbf16 math functions
Signed-off-by: Krishna Pandey
---
libc/src/math/CMakeLists.txt | 2 ++
libc/src/math/generic/CMakeLists.txt | 28 +++
libc/src/math/generic/scalblnbf16.cpp | 21
libc/src/math/generic/scalbnbf16.cpp | 21
libc/src/math/scalblnbf16.h | 21
libc/src/math/scalbnbf16.h| 21
6 files changed, 114 insertions(+)
create mode 100644 libc/src/math/generic/scalblnbf16.cpp
create mode 100644 libc/src/math/generic/scalbnbf16.cpp
create mode 100644 libc/src/math/scalblnbf16.h
create mode 100644 libc/src/math/scalbnbf16.h
diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index 1edb517421e28..4b325f773b35f 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -518,12 +518,14 @@ add_math_entrypoint_object(scalblnf)
add_math_entrypoint_object(scalblnl)
add_math_entrypoint_object(scalblnf16)
add_math_entrypoint_object(scalblnf128)
+add_math_entrypoint_object(scalblnbf16)
add_math_entrypoint_object(scalbn)
add_math_entrypoint_object(scalbnf)
add_math_entrypoint_object(scalbnl)
add_math_entrypoint_object(scalbnf16)
add_math_entrypoint_object(scalbnf128)
+add_math_entrypoint_object(scalbnbf16)
add_math_entrypoint_object(setpayload)
add_math_entrypoint_object(setpayloadf)
diff --git a/libc/src/math/generic/CMakeLists.txt
b/libc/src/math/generic/CMakeLists.txt
index 904f8d2eb4704..b1fcbf356777a 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -4646,6 +4646,20 @@ add_entrypoint_object(
libc.src.__support.FPUtil.manipulation_functions
)
+add_entrypoint_object(
+ scalblnbf16
+ SRCS
+scalblnbf16.cpp
+ HDRS
+../scalblnbf16.h
+ DEPENDS
+libc.src.__support.common
+libc.src.__support.macros.config
+libc.src.__support.macros.properties.types
+libc.src.__support.FPUtil.bfloat16
+libc.src.__support.FPUtil.manipulation_functions
+)
+
add_entrypoint_object(
scalbn
SRCS
@@ -4703,6 +4717,20 @@ add_entrypoint_object(
libc.src.__support.FPUtil.manipulation_functions
)
+add_entrypoint_object(
+ scalbnbf16
+ SRCS
+scalbnbf16.cpp
+ HDRS
+../scalblnbf16.h
+ DEPENDS
+libc.src.__support.common
+libc.src.__support.macros.config
+libc.src.__support.macros.properties.types
+libc.src.__support.FPUtil.bfloat16
+libc.src.__support.FPUtil.manipulation_functions
+)
+
add_entrypoint_object(
fmaf
SRCS
diff --git a/libc/src/math/generic/scalblnbf16.cpp
b/libc/src/math/generic/scalblnbf16.cpp
new file mode 100644
index 0..cda8e126efacb
--- /dev/null
+++ b/libc/src/math/generic/scalblnbf16.cpp
@@ -0,0 +1,21 @@
+//===-- Implementation of scalblnbf16 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/scalblnbf16.h"
+#include "src/__support/FPUtil/ManipulationFunctions.h"
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(bfloat16, scalblnbf16, (bfloat16 x, long n)) {
+ return fputil::ldexp(x, n);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/scalbnbf16.cpp
b/libc/src/math/generic/scalbnbf16.cpp
new file mode 100644
index 0..87833742d59ac
--- /dev/null
+++ b/libc/src/math/generic/scalbnbf16.cpp
@@ -0,0 +1,21 @@
+//===-- Implementation of scalbnbf16 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/scalbnbf16.h"
+#include "src/__support/FPUtil/ManipulationFunctions.h"
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(bfloat16, scalbnbf16, (bfloat16 x, int n)) {
+ return fputil::ldexp(x, n);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/scalblnbf16.h b/libc/src/math/scalblnbf16.h
new
[llvm-branch-commits] [libc] [libc][math][c++23] Add {frexp, ilogb, ldexp, llogb, logb}bf16 math functions (PR #154427)
https://github.com/krishna2803 updated
https://github.com/llvm/llvm-project/pull/154427
>From 832bbc6f4743015ef1af5e9d4a9aea4b94e73374 Mon Sep 17 00:00:00 2001
From: Krishna Pandey
Date: Tue, 19 Aug 2025 22:13:40 +0530
Subject: [PATCH 1/6] feat: implement {frexp,ilogb,ldexp,llogb,logb}bf16 math
functions
Signed-off-by: Krishna Pandey
---
libc/src/math/CMakeLists.txt | 5 ++
libc/src/math/frexpbf16.h| 21 +
libc/src/math/generic/CMakeLists.txt | 70
libc/src/math/generic/frexpbf16.cpp | 21 +
libc/src/math/generic/ilogbbf16.cpp | 21 +
libc/src/math/generic/ldexpbf16.cpp | 21 +
libc/src/math/generic/llogbbf16.cpp | 21 +
libc/src/math/generic/logbbf16.cpp | 19
libc/src/math/ilogbbf16.h| 21 +
libc/src/math/ldexpbf16.h| 21 +
libc/src/math/llogbbf16.h| 21 +
libc/src/math/logbbf16.h | 21 +
12 files changed, 283 insertions(+)
create mode 100644 libc/src/math/frexpbf16.h
create mode 100644 libc/src/math/generic/frexpbf16.cpp
create mode 100644 libc/src/math/generic/ilogbbf16.cpp
create mode 100644 libc/src/math/generic/ldexpbf16.cpp
create mode 100644 libc/src/math/generic/llogbbf16.cpp
create mode 100644 libc/src/math/generic/logbbf16.cpp
create mode 100644 libc/src/math/ilogbbf16.h
create mode 100644 libc/src/math/ldexpbf16.h
create mode 100644 libc/src/math/llogbbf16.h
create mode 100644 libc/src/math/logbbf16.h
diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index 87a341bb6267b..b1d76c6008cf5 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -306,6 +306,7 @@ add_math_entrypoint_object(frexpf)
add_math_entrypoint_object(frexpl)
add_math_entrypoint_object(frexpf16)
add_math_entrypoint_object(frexpf128)
+add_math_entrypoint_object(frexpbf16)
add_math_entrypoint_object(fromfp)
add_math_entrypoint_object(fromfpf)
@@ -341,6 +342,7 @@ add_math_entrypoint_object(ilogbf)
add_math_entrypoint_object(ilogbl)
add_math_entrypoint_object(ilogbf16)
add_math_entrypoint_object(ilogbf128)
+add_math_entrypoint_object(ilogbbf16)
add_math_entrypoint_object(isnan)
add_math_entrypoint_object(isnanf)
@@ -357,12 +359,14 @@ add_math_entrypoint_object(llogbf)
add_math_entrypoint_object(llogbl)
add_math_entrypoint_object(llogbf16)
add_math_entrypoint_object(llogbf128)
+add_math_entrypoint_object(llogbbf16)
add_math_entrypoint_object(ldexp)
add_math_entrypoint_object(ldexpf)
add_math_entrypoint_object(ldexpl)
add_math_entrypoint_object(ldexpf16)
add_math_entrypoint_object(ldexpf128)
+add_math_entrypoint_object(ldexpbf16)
add_math_entrypoint_object(log10)
add_math_entrypoint_object(log10f)
@@ -384,6 +388,7 @@ add_math_entrypoint_object(logbf)
add_math_entrypoint_object(logbl)
add_math_entrypoint_object(logbf16)
add_math_entrypoint_object(logbf128)
+add_math_entrypoint_object(logbbf16)
add_math_entrypoint_object(llrint)
add_math_entrypoint_object(llrintf)
diff --git a/libc/src/math/frexpbf16.h b/libc/src/math/frexpbf16.h
new file mode 100644
index 0..1e9bba16ea6c4
--- /dev/null
+++ b/libc/src/math/frexpbf16.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for frexpbf16 -*- 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_FREXPFB16_H
+#define LLVM_LIBC_SRC_MATH_FREXPFB16_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+bfloat16 frexpbf16(bfloat16 x, int *exp);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_FREXPFB16_H
diff --git a/libc/src/math/generic/CMakeLists.txt
b/libc/src/math/generic/CMakeLists.txt
index e34e3f04ed8bd..3dbc54a819722 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -1732,6 +1732,20 @@ add_entrypoint_object(
libc.src.__support.math.frexpf128
)
+add_entrypoint_object(
+ frexpbf16
+ SRCS
+frexpbf16.cpp
+ HDRS
+../frexpbf16.h
+ DEPENDS
+libc.src.__support.common
+libc.src.__support.FPUtil.bfloat16
+libc.src.__support.FPUtil.manipulation_functions
+libc.src.__support.macros.config
+libc.src.__support.macros.properties.types
+)
+
add_entrypoint_object(
ilogb
SRCS
@@ -1784,6 +1798,20 @@ add_entrypoint_object(
libc.src.__support.FPUtil.manipulation_functions
)
+add_entrypoint_object(
+ ilogbbf16
+ SRCS
+ilogbbf16.cpp
+ HDRS
+../ilogbbf16.h
+ DEPENDS
+libc.src.__support.common
+libc.src.__support.FPUtil.bfloat16
+libc.src.__support.FPUtil.manipulation_functions
+libc.src.__support
[llvm-branch-commits] [libc] [libc][math][c++23] Add fmodbf16 math function (PR #155575)
https://github.com/krishna2803 updated
https://github.com/llvm/llvm-project/pull/155575
>From d7930ac1d1d79b0aaf197857abd77f64ab7f3679 Mon Sep 17 00:00:00 2001
From: Krishna Pandey
Date: Wed, 27 Aug 2025 14:06:39 +0530
Subject: [PATCH 1/6] feat: implement fmodbf16 math function
Signed-off-by: Krishna Pandey
---
libc/src/math/CMakeLists.txt | 1 +
libc/src/math/fmodbf16.h | 21 +
libc/src/math/generic/CMakeLists.txt | 14 ++
libc/src/math/generic/fmodbf16.cpp | 21 +
4 files changed, 57 insertions(+)
create mode 100644 libc/src/math/fmodbf16.h
create mode 100644 libc/src/math/generic/fmodbf16.cpp
diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index 4b325f773b35f..d2fba849f7e27 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -306,6 +306,7 @@ add_math_entrypoint_object(fmodf)
add_math_entrypoint_object(fmodl)
add_math_entrypoint_object(fmodf16)
add_math_entrypoint_object(fmodf128)
+add_math_entrypoint_object(fmodbf16)
add_math_entrypoint_object(frexp)
add_math_entrypoint_object(frexpf)
diff --git a/libc/src/math/fmodbf16.h b/libc/src/math/fmodbf16.h
new file mode 100644
index 0..176dbcc83eda0
--- /dev/null
+++ b/libc/src/math/fmodbf16.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for fmodbf16 --*- 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_FMODBF16_H
+#define LLVM_LIBC_SRC_MATH_FMODBF16_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+bfloat16 fmodbf16(bfloat16 x, bfloat16 y);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_FMODBF16_H
diff --git a/libc/src/math/generic/CMakeLists.txt
b/libc/src/math/generic/CMakeLists.txt
index b1fcbf356777a..b9ef116e3dbb9 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -4015,6 +4015,20 @@ add_entrypoint_object(
libc.src.__support.FPUtil.generic.fmod
)
+add_entrypoint_object(
+ fmodbf16
+ SRCS
+fmodbf16.cpp
+ HDRS
+../fmodbf16.h
+ DEPENDS
+libc.src.__support.common
+libc.src.__support.macros.config
+libc.src.__support.macros.properties.types
+libc.src.__support.FPUtil.bfloat16
+libc.src.__support.FPUtil.generic.fmod
+)
+
add_entrypoint_object(
fromfp
SRCS
diff --git a/libc/src/math/generic/fmodbf16.cpp
b/libc/src/math/generic/fmodbf16.cpp
new file mode 100644
index 0..436ccd1d37f7d
--- /dev/null
+++ b/libc/src/math/generic/fmodbf16.cpp
@@ -0,0 +1,21 @@
+//===-- Implementation of fmodbf16 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/fmodbf16.h"
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/FPUtil/generic/FMod.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(bfloat16, fmodbf16, (bfloat16 x, bfloat16 y)) {
+ return fputil::generic::FMod::eval(x, y);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
>From a77279072840ad095dc551576a9c6d612f33a1b5 Mon Sep 17 00:00:00 2001
From: Krishna Pandey
Date: Wed, 27 Aug 2025 14:07:02 +0530
Subject: [PATCH 2/6] chore: add smoke tests for fmodbf16 math function
Signed-off-by: Krishna Pandey
---
libc/test/src/math/smoke/CMakeLists.txt| 17 +++
libc/test/src/math/smoke/FModTest.h| 25 +++---
libc/test/src/math/smoke/fmodbf16_test.cpp | 14
3 files changed, 44 insertions(+), 12 deletions(-)
create mode 100644 libc/test/src/math/smoke/fmodbf16_test.cpp
diff --git a/libc/test/src/math/smoke/CMakeLists.txt
b/libc/test/src/math/smoke/CMakeLists.txt
index 226ef2ee71866..7cf463596022f 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -4503,6 +4503,23 @@ add_fp_unittest(
UNIT_TEST_ONLY
)
+add_fp_unittest(
+ fmodbf16_test
+ SUITE
+libc-math-smoke-tests
+ SRCS
+fmodbf16_test.cpp
+ HDRS
+FModTest.h
+ DEPENDS
+libc.hdr.fenv_macros
+libc.src.errno.errno
+libc.src.math.fmodbf16
+libc.src.__support.FPUtil.bfloat16
+libc.src.__support.FPUtil.fenv_impl
+ UNIT_TEST_ONLY
+)
+
add_fp_unittest(
coshf_test
SUITE
diff --git a/libc/test/src/math/smoke/FModTest.h
b/libc/test/src/math/smoke/FModTest.h
index 0
[llvm-branch-commits] [libc] [libc][math][c++23] Add fmodbf16 math function (PR #155575)
https://github.com/krishna2803 updated
https://github.com/llvm/llvm-project/pull/155575
>From d7930ac1d1d79b0aaf197857abd77f64ab7f3679 Mon Sep 17 00:00:00 2001
From: Krishna Pandey
Date: Wed, 27 Aug 2025 14:06:39 +0530
Subject: [PATCH 1/7] feat: implement fmodbf16 math function
Signed-off-by: Krishna Pandey
---
libc/src/math/CMakeLists.txt | 1 +
libc/src/math/fmodbf16.h | 21 +
libc/src/math/generic/CMakeLists.txt | 14 ++
libc/src/math/generic/fmodbf16.cpp | 21 +
4 files changed, 57 insertions(+)
create mode 100644 libc/src/math/fmodbf16.h
create mode 100644 libc/src/math/generic/fmodbf16.cpp
diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index 4b325f773b35f..d2fba849f7e27 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -306,6 +306,7 @@ add_math_entrypoint_object(fmodf)
add_math_entrypoint_object(fmodl)
add_math_entrypoint_object(fmodf16)
add_math_entrypoint_object(fmodf128)
+add_math_entrypoint_object(fmodbf16)
add_math_entrypoint_object(frexp)
add_math_entrypoint_object(frexpf)
diff --git a/libc/src/math/fmodbf16.h b/libc/src/math/fmodbf16.h
new file mode 100644
index 0..176dbcc83eda0
--- /dev/null
+++ b/libc/src/math/fmodbf16.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for fmodbf16 --*- 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_FMODBF16_H
+#define LLVM_LIBC_SRC_MATH_FMODBF16_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+bfloat16 fmodbf16(bfloat16 x, bfloat16 y);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_FMODBF16_H
diff --git a/libc/src/math/generic/CMakeLists.txt
b/libc/src/math/generic/CMakeLists.txt
index b1fcbf356777a..b9ef116e3dbb9 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -4015,6 +4015,20 @@ add_entrypoint_object(
libc.src.__support.FPUtil.generic.fmod
)
+add_entrypoint_object(
+ fmodbf16
+ SRCS
+fmodbf16.cpp
+ HDRS
+../fmodbf16.h
+ DEPENDS
+libc.src.__support.common
+libc.src.__support.macros.config
+libc.src.__support.macros.properties.types
+libc.src.__support.FPUtil.bfloat16
+libc.src.__support.FPUtil.generic.fmod
+)
+
add_entrypoint_object(
fromfp
SRCS
diff --git a/libc/src/math/generic/fmodbf16.cpp
b/libc/src/math/generic/fmodbf16.cpp
new file mode 100644
index 0..436ccd1d37f7d
--- /dev/null
+++ b/libc/src/math/generic/fmodbf16.cpp
@@ -0,0 +1,21 @@
+//===-- Implementation of fmodbf16 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/fmodbf16.h"
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/FPUtil/generic/FMod.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(bfloat16, fmodbf16, (bfloat16 x, bfloat16 y)) {
+ return fputil::generic::FMod::eval(x, y);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
>From a77279072840ad095dc551576a9c6d612f33a1b5 Mon Sep 17 00:00:00 2001
From: Krishna Pandey
Date: Wed, 27 Aug 2025 14:07:02 +0530
Subject: [PATCH 2/7] chore: add smoke tests for fmodbf16 math function
Signed-off-by: Krishna Pandey
---
libc/test/src/math/smoke/CMakeLists.txt| 17 +++
libc/test/src/math/smoke/FModTest.h| 25 +++---
libc/test/src/math/smoke/fmodbf16_test.cpp | 14
3 files changed, 44 insertions(+), 12 deletions(-)
create mode 100644 libc/test/src/math/smoke/fmodbf16_test.cpp
diff --git a/libc/test/src/math/smoke/CMakeLists.txt
b/libc/test/src/math/smoke/CMakeLists.txt
index 226ef2ee71866..7cf463596022f 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -4503,6 +4503,23 @@ add_fp_unittest(
UNIT_TEST_ONLY
)
+add_fp_unittest(
+ fmodbf16_test
+ SUITE
+libc-math-smoke-tests
+ SRCS
+fmodbf16_test.cpp
+ HDRS
+FModTest.h
+ DEPENDS
+libc.hdr.fenv_macros
+libc.src.errno.errno
+libc.src.math.fmodbf16
+libc.src.__support.FPUtil.bfloat16
+libc.src.__support.FPUtil.fenv_impl
+ UNIT_TEST_ONLY
+)
+
add_fp_unittest(
coshf_test
SUITE
diff --git a/libc/test/src/math/smoke/FModTest.h
b/libc/test/src/math/smoke/FModTest.h
index 0
