-
Notifications
You must be signed in to change notification settings - Fork 14.8k
[libc][math][c++23] Add {frexp,ilogb,ldexp,llogb,logb}bf16 math functions #154427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Signed-off-by: Krishna Pandey <[email protected]>
Signed-off-by: Krishna Pandey <[email protected]>
Signed-off-by: Krishna Pandey <[email protected]>
Signed-off-by: Krishna Pandey <[email protected]>
Signed-off-by: Krishna Pandey <[email protected]>
Signed-off-by: Krishna Pandey <[email protected]>
Signed-off-by: Krishna Pandey <[email protected]>
Signed-off-by: Krishna Pandey <[email protected]>
…ions Signed-off-by: Krishna Pandey <[email protected]>
…igbf16 math functions Signed-off-by: Krishna Pandey <[email protected]>
Signed-off-by: Krishna Pandey <[email protected]>
Signed-off-by: Krishna Pandey <[email protected]>
Signed-off-by: Krishna Pandey <[email protected]>
Signed-off-by: Krishna Pandey <[email protected]>
Signed-off-by: Krishna Pandey <[email protected]>
Signed-off-by: Krishna Pandey <[email protected]>
Signed-off-by: Krishna Pandey <[email protected]>
Signed-off-by: Krishna Pandey <[email protected]>
…nctions Signed-off-by: Krishna Pandey <[email protected]>
Signed-off-by: Krishna Pandey <[email protected]>
Signed-off-by: Krishna Pandey <[email protected]>
Signed-off-by: Krishna Pandey <[email protected]>
@llvm/pr-subscribers-libc @llvm/pr-subscribers-backend-amdgpu Author: Krishna Pandey (krishna2803) ChangesThis PR adds the following basic math functions for BFloat16 type along with the tests:
Patch is 36.49 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/154427.diff 33 Files Affected:
diff --git a/libc/config/baremetal/aarch64/entrypoints.txt b/libc/config/baremetal/aarch64/entrypoints.txt
index c4ec03fc146e8..10d5b3a591d0d 100644
--- a/libc/config/baremetal/aarch64/entrypoints.txt
+++ b/libc/config/baremetal/aarch64/entrypoints.txt
@@ -785,9 +785,14 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_magbf16
libc.src.math.fminimum_mag_numbf16
libc.src.math.fminimum_numbf16
+ libc.src.math.frexpbf16
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
+ libc.src.math.ilogbbf16
+ libc.src.math.ldexpbf16
+ libc.src.math.llogbbf16
+ libc.src.math.logbbf16
libc.src.math.nanbf16
libc.src.math.nextafterbf16
libc.src.math.nextdownbf16
diff --git a/libc/config/baremetal/arm/entrypoints.txt b/libc/config/baremetal/arm/entrypoints.txt
index d9e173a71e47a..785b84163701f 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -788,9 +788,14 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_magbf16
libc.src.math.fminimum_mag_numbf16
libc.src.math.fminimum_numbf16
+ libc.src.math.frexpbf16
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
+ libc.src.math.ilogbbf16
+ libc.src.math.ldexpbf16
+ libc.src.math.llogbbf16
+ libc.src.math.logbbf16
libc.src.math.nanbf16
libc.src.math.nextafterbf16
libc.src.math.nextdownbf16
diff --git a/libc/config/baremetal/riscv/entrypoints.txt b/libc/config/baremetal/riscv/entrypoints.txt
index 9b0cf14037fae..2038f3e4952cf 100644
--- a/libc/config/baremetal/riscv/entrypoints.txt
+++ b/libc/config/baremetal/riscv/entrypoints.txt
@@ -788,9 +788,14 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_magbf16
libc.src.math.fminimum_mag_numbf16
libc.src.math.fminimum_numbf16
+ libc.src.math.frexpbf16
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
+ libc.src.math.ilogbbf16
+ libc.src.math.ldexpbf16
+ libc.src.math.llogbbf16
+ libc.src.math.logbbf16
libc.src.math.nanbf16
libc.src.math.nextafterbf16
libc.src.math.nextdownbf16
diff --git a/libc/config/darwin/aarch64/entrypoints.txt b/libc/config/darwin/aarch64/entrypoints.txt
index 2a634852a2ed0..707e8b1d43658 100644
--- a/libc/config/darwin/aarch64/entrypoints.txt
+++ b/libc/config/darwin/aarch64/entrypoints.txt
@@ -618,9 +618,14 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_magbf16
libc.src.math.fminimum_mag_numbf16
libc.src.math.fminimum_numbf16
+ libc.src.math.frexpbf16
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
+ libc.src.math.ilogbbf16
+ libc.src.math.ldexpbf16
+ libc.src.math.llogbbf16
+ libc.src.math.logbbf16
libc.src.math.nanbf16
libc.src.math.nextafterbf16
libc.src.math.nextdownbf16
diff --git a/libc/config/darwin/x86_64/entrypoints.txt b/libc/config/darwin/x86_64/entrypoints.txt
index 6a18d557f86fb..db3b305d376b0 100644
--- a/libc/config/darwin/x86_64/entrypoints.txt
+++ b/libc/config/darwin/x86_64/entrypoints.txt
@@ -261,9 +261,14 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_magbf16
libc.src.math.fminimum_mag_numbf16
libc.src.math.fminimum_numbf16
+ libc.src.math.frexpbf16
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
+ libc.src.math.ilogbbf16
+ libc.src.math.ldexpbf16
+ libc.src.math.llogbbf16
+ libc.src.math.logbbf16
libc.src.math.nanbf16
libc.src.math.nextafterbf16
libc.src.math.nextdownbf16
diff --git a/libc/config/gpu/amdgpu/entrypoints.txt b/libc/config/gpu/amdgpu/entrypoints.txt
index 008f7c7bd642c..76bda91f3b229 100644
--- a/libc/config/gpu/amdgpu/entrypoints.txt
+++ b/libc/config/gpu/amdgpu/entrypoints.txt
@@ -644,9 +644,14 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_magbf16
libc.src.math.fminimum_mag_numbf16
libc.src.math.fminimum_numbf16
+ libc.src.math.frexpbf16
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
+ libc.src.math.ilogbbf16
+ libc.src.math.ldexpbf16
+ libc.src.math.llogbbf16
+ libc.src.math.logbbf16
libc.src.math.nanbf16
libc.src.math.nextafterbf16
libc.src.math.nextdownbf16
diff --git a/libc/config/gpu/nvptx/entrypoints.txt b/libc/config/gpu/nvptx/entrypoints.txt
index ae434117eb8e2..cae9d593b056d 100644
--- a/libc/config/gpu/nvptx/entrypoints.txt
+++ b/libc/config/gpu/nvptx/entrypoints.txt
@@ -645,9 +645,14 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_magbf16
libc.src.math.fminimum_mag_numbf16
libc.src.math.fminimum_numbf16
+ libc.src.math.frexpbf16
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
+ libc.src.math.ilogbbf16
+ libc.src.math.ldexpbf16
+ libc.src.math.llogbbf16
+ libc.src.math.logbbf16
libc.src.math.nanbf16
libc.src.math.nextafterbf16
libc.src.math.nextdownbf16
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 88438247643f6..18853de2c13c1 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -872,9 +872,14 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_magbf16
libc.src.math.fminimum_mag_numbf16
libc.src.math.fminimum_numbf16
+ libc.src.math.frexpbf16
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
+ libc.src.math.ilogbbf16
+ libc.src.math.ldexpbf16
+ libc.src.math.llogbbf16
+ libc.src.math.logbbf16
libc.src.math.nanbf16
libc.src.math.nextafterbf16
libc.src.math.nextdownbf16
diff --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt
index 865392a918624..150e34a1fb195 100644
--- a/libc/config/linux/arm/entrypoints.txt
+++ b/libc/config/linux/arm/entrypoints.txt
@@ -488,9 +488,14 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_magbf16
libc.src.math.fminimum_mag_numbf16
libc.src.math.fminimum_numbf16
+ libc.src.math.frexpbf16
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
+ libc.src.math.ilogbbf16
+ libc.src.math.ldexpbf16
+ libc.src.math.llogbbf16
+ libc.src.math.logbbf16
libc.src.math.nanbf16
libc.src.math.nextafterbf16
libc.src.math.nextdownbf16
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 207608c431a9b..937ec4253299a 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -891,9 +891,14 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_magbf16
libc.src.math.fminimum_mag_numbf16
libc.src.math.fminimum_numbf16
+ libc.src.math.frexpbf16
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
+ libc.src.math.ilogbbf16
+ libc.src.math.ldexpbf16
+ libc.src.math.llogbbf16
+ libc.src.math.logbbf16
libc.src.math.nanbf16
libc.src.math.nextafterbf16
libc.src.math.nextdownbf16
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 44f5f2d03db0a..23871c406d236 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -923,9 +923,14 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_magbf16
libc.src.math.fminimum_mag_numbf16
libc.src.math.fminimum_numbf16
+ libc.src.math.frexpbf16
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
+ libc.src.math.ilogbbf16
+ libc.src.math.ldexpbf16
+ libc.src.math.llogbbf16
+ libc.src.math.logbbf16
libc.src.math.nanbf16
libc.src.math.nextafterbf16
libc.src.math.nextdownbf16
diff --git a/libc/config/windows/entrypoints.txt b/libc/config/windows/entrypoints.txt
index 32a6a578aae13..cc7c655280213 100644
--- a/libc/config/windows/entrypoints.txt
+++ b/libc/config/windows/entrypoints.txt
@@ -334,9 +334,14 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_magbf16
libc.src.math.fminimum_mag_numbf16
libc.src.math.fminimum_numbf16
+ libc.src.math.frexpbf16
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
+ libc.src.math.ilogbbf16
+ libc.src.math.ldexpbf16
+ libc.src.math.llogbbf16
+ libc.src.math.logbbf16
libc.src.math.nanbf16
libc.src.math.nextafterbf16
libc.src.math.nextdownbf16
diff --git a/libc/docs/headers/math/index.rst b/libc/docs/headers/math/index.rst
index 9efbce06920b5..5049ab65d00af 100644
--- a/libc/docs/headers/math/index.rst
+++ b/libc/docs/headers/math/index.rst
@@ -179,7 +179,7 @@ Basic Operations
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
| fmul | N/A | |check| | |check| | N/A | |check|\* | N/A | 7.12.14.3 | F.10.11 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| frexp | |check| | |check| | |check| | |check| | |check| | | 7.12.6.7 | F.10.3.7 |
+| frexp | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.6.7 | F.10.3.7 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
| fromfp | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.9.10 | F.10.6.10 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
@@ -189,21 +189,21 @@ Basic Operations
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
| getpayload | |check| | |check| | |check| | |check| | |check| | |check| | F.10.13.1 | N/A |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| ilogb | |check| | |check| | |check| | |check| | |check| | | 7.12.6.8 | F.10.3.8 |
+| ilogb | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.6.8 | F.10.3.8 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
| iscanonical | |check| | |check| | |check| | |check| | |check| | | 7.12.3.2 | N/A |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
| issignaling | |check| | |check| | |check| | |check| | |check| | | 7.12.3.8 | N/A |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| ldexp | |check| | |check| | |check| | |check| | |check| | | 7.12.6.9 | F.10.3.9 |
+| ldexp | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.6.9 | F.10.3.9 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| llogb | |check| | |check| | |check| | |check| | |check| | | 7.12.6.10 | F.10.3.10 |
+| llogb | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.6.10 | F.10.3.10 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
| llrint | |check| | |check| | |check| | |check| | |check| | | 7.12.9.5 | F.10.6.5 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
| llround | |check| | |check| | |check| | |check| | |check| | | 7.12.9.7 | F.10.6.7 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| logb | |check| | |check| | |check| | |check| | |check| | | 7.12.6.17 | F.10.3.17 |
+| logb | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.6.17 | F.10.3.17 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
| lrint | |check| | |check| | |check| | |check| | |check| | | 7.12.9.5 | F.10.6.5 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
diff --git a/libc/src/__support/FPUtil/bfloat16.h b/libc/src/__support/FPUtil/bfloat16.h
index 3fab2b80317de..89d06a06f2dcf 100644
--- a/libc/src/__support/FPUtil/bfloat16.h
+++ b/libc/src/__support/FPUtil/bfloat16.h
@@ -48,6 +48,8 @@ struct BFloat16 {
xd(sign, 0, value);
bits = xd.template as<bfloat16, /*ShouldSignalExceptions=*/true>().bits;
+ } else if constexpr (cpp::is_convertible_v<T, BFloat16>) {
+ bits = value.operator BFloat16().bits;
} else {
bits = fputil::cast<bfloat16>(static_cast<float>(value)).bits;
}
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 0000000000000..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.macros.config
+ libc.src.__support.macros.properties.types
+)
+
add_entrypoint_object(
llogb
SRCS
@@ -1836,6 +1864,20 @@ add_entrypoint_object(
libc.src.__support.FPUtil.manipulation_functions
)
+add_entrypoint_object(
+ llogbbf16
+ SRCS
+ llogbbf16.cpp
+ HDRS
+ ../llogbbf16.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(
ldexp
SRCS
@@ -1886,6 +1928,20 @@ add_entrypoint_object(
libc.src.__support.math.ldexpf128
)
+add_entrypoint_object(
+ ldexpbf16
+ SRCS
+ ldexpbf16.cpp
+ HDRS
+ ../ldexpbf16.h
+ DE...
[truncated]
|
@llvm/pr-subscribers-backend-risc-v Author: Krishna Pandey (krishna2803) ChangesThis PR adds the following basic math functions for BFloat16 type along with the tests:
Patch is 36.49 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/154427.diff 33 Files Affected:
diff --git a/libc/config/baremetal/aarch64/entrypoints.txt b/libc/config/baremetal/aarch64/entrypoints.txt
index c4ec03fc146e8..10d5b3a591d0d 100644
--- a/libc/config/baremetal/aarch64/entrypoints.txt
+++ b/libc/config/baremetal/aarch64/entrypoints.txt
@@ -785,9 +785,14 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_magbf16
libc.src.math.fminimum_mag_numbf16
libc.src.math.fminimum_numbf16
+ libc.src.math.frexpbf16
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
+ libc.src.math.ilogbbf16
+ libc.src.math.ldexpbf16
+ libc.src.math.llogbbf16
+ libc.src.math.logbbf16
libc.src.math.nanbf16
libc.src.math.nextafterbf16
libc.src.math.nextdownbf16
diff --git a/libc/config/baremetal/arm/entrypoints.txt b/libc/config/baremetal/arm/entrypoints.txt
index d9e173a71e47a..785b84163701f 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -788,9 +788,14 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_magbf16
libc.src.math.fminimum_mag_numbf16
libc.src.math.fminimum_numbf16
+ libc.src.math.frexpbf16
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
+ libc.src.math.ilogbbf16
+ libc.src.math.ldexpbf16
+ libc.src.math.llogbbf16
+ libc.src.math.logbbf16
libc.src.math.nanbf16
libc.src.math.nextafterbf16
libc.src.math.nextdownbf16
diff --git a/libc/config/baremetal/riscv/entrypoints.txt b/libc/config/baremetal/riscv/entrypoints.txt
index 9b0cf14037fae..2038f3e4952cf 100644
--- a/libc/config/baremetal/riscv/entrypoints.txt
+++ b/libc/config/baremetal/riscv/entrypoints.txt
@@ -788,9 +788,14 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_magbf16
libc.src.math.fminimum_mag_numbf16
libc.src.math.fminimum_numbf16
+ libc.src.math.frexpbf16
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
+ libc.src.math.ilogbbf16
+ libc.src.math.ldexpbf16
+ libc.src.math.llogbbf16
+ libc.src.math.logbbf16
libc.src.math.nanbf16
libc.src.math.nextafterbf16
libc.src.math.nextdownbf16
diff --git a/libc/config/darwin/aarch64/entrypoints.txt b/libc/config/darwin/aarch64/entrypoints.txt
index 2a634852a2ed0..707e8b1d43658 100644
--- a/libc/config/darwin/aarch64/entrypoints.txt
+++ b/libc/config/darwin/aarch64/entrypoints.txt
@@ -618,9 +618,14 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_magbf16
libc.src.math.fminimum_mag_numbf16
libc.src.math.fminimum_numbf16
+ libc.src.math.frexpbf16
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
+ libc.src.math.ilogbbf16
+ libc.src.math.ldexpbf16
+ libc.src.math.llogbbf16
+ libc.src.math.logbbf16
libc.src.math.nanbf16
libc.src.math.nextafterbf16
libc.src.math.nextdownbf16
diff --git a/libc/config/darwin/x86_64/entrypoints.txt b/libc/config/darwin/x86_64/entrypoints.txt
index 6a18d557f86fb..db3b305d376b0 100644
--- a/libc/config/darwin/x86_64/entrypoints.txt
+++ b/libc/config/darwin/x86_64/entrypoints.txt
@@ -261,9 +261,14 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_magbf16
libc.src.math.fminimum_mag_numbf16
libc.src.math.fminimum_numbf16
+ libc.src.math.frexpbf16
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
+ libc.src.math.ilogbbf16
+ libc.src.math.ldexpbf16
+ libc.src.math.llogbbf16
+ libc.src.math.logbbf16
libc.src.math.nanbf16
libc.src.math.nextafterbf16
libc.src.math.nextdownbf16
diff --git a/libc/config/gpu/amdgpu/entrypoints.txt b/libc/config/gpu/amdgpu/entrypoints.txt
index 008f7c7bd642c..76bda91f3b229 100644
--- a/libc/config/gpu/amdgpu/entrypoints.txt
+++ b/libc/config/gpu/amdgpu/entrypoints.txt
@@ -644,9 +644,14 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_magbf16
libc.src.math.fminimum_mag_numbf16
libc.src.math.fminimum_numbf16
+ libc.src.math.frexpbf16
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
+ libc.src.math.ilogbbf16
+ libc.src.math.ldexpbf16
+ libc.src.math.llogbbf16
+ libc.src.math.logbbf16
libc.src.math.nanbf16
libc.src.math.nextafterbf16
libc.src.math.nextdownbf16
diff --git a/libc/config/gpu/nvptx/entrypoints.txt b/libc/config/gpu/nvptx/entrypoints.txt
index ae434117eb8e2..cae9d593b056d 100644
--- a/libc/config/gpu/nvptx/entrypoints.txt
+++ b/libc/config/gpu/nvptx/entrypoints.txt
@@ -645,9 +645,14 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_magbf16
libc.src.math.fminimum_mag_numbf16
libc.src.math.fminimum_numbf16
+ libc.src.math.frexpbf16
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
+ libc.src.math.ilogbbf16
+ libc.src.math.ldexpbf16
+ libc.src.math.llogbbf16
+ libc.src.math.logbbf16
libc.src.math.nanbf16
libc.src.math.nextafterbf16
libc.src.math.nextdownbf16
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 88438247643f6..18853de2c13c1 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -872,9 +872,14 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_magbf16
libc.src.math.fminimum_mag_numbf16
libc.src.math.fminimum_numbf16
+ libc.src.math.frexpbf16
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
+ libc.src.math.ilogbbf16
+ libc.src.math.ldexpbf16
+ libc.src.math.llogbbf16
+ libc.src.math.logbbf16
libc.src.math.nanbf16
libc.src.math.nextafterbf16
libc.src.math.nextdownbf16
diff --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt
index 865392a918624..150e34a1fb195 100644
--- a/libc/config/linux/arm/entrypoints.txt
+++ b/libc/config/linux/arm/entrypoints.txt
@@ -488,9 +488,14 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_magbf16
libc.src.math.fminimum_mag_numbf16
libc.src.math.fminimum_numbf16
+ libc.src.math.frexpbf16
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
+ libc.src.math.ilogbbf16
+ libc.src.math.ldexpbf16
+ libc.src.math.llogbbf16
+ libc.src.math.logbbf16
libc.src.math.nanbf16
libc.src.math.nextafterbf16
libc.src.math.nextdownbf16
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 207608c431a9b..937ec4253299a 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -891,9 +891,14 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_magbf16
libc.src.math.fminimum_mag_numbf16
libc.src.math.fminimum_numbf16
+ libc.src.math.frexpbf16
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
+ libc.src.math.ilogbbf16
+ libc.src.math.ldexpbf16
+ libc.src.math.llogbbf16
+ libc.src.math.logbbf16
libc.src.math.nanbf16
libc.src.math.nextafterbf16
libc.src.math.nextdownbf16
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 44f5f2d03db0a..23871c406d236 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -923,9 +923,14 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_magbf16
libc.src.math.fminimum_mag_numbf16
libc.src.math.fminimum_numbf16
+ libc.src.math.frexpbf16
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
+ libc.src.math.ilogbbf16
+ libc.src.math.ldexpbf16
+ libc.src.math.llogbbf16
+ libc.src.math.logbbf16
libc.src.math.nanbf16
libc.src.math.nextafterbf16
libc.src.math.nextdownbf16
diff --git a/libc/config/windows/entrypoints.txt b/libc/config/windows/entrypoints.txt
index 32a6a578aae13..cc7c655280213 100644
--- a/libc/config/windows/entrypoints.txt
+++ b/libc/config/windows/entrypoints.txt
@@ -334,9 +334,14 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_magbf16
libc.src.math.fminimum_mag_numbf16
libc.src.math.fminimum_numbf16
+ libc.src.math.frexpbf16
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
libc.src.math.getpayloadbf16
+ libc.src.math.ilogbbf16
+ libc.src.math.ldexpbf16
+ libc.src.math.llogbbf16
+ libc.src.math.logbbf16
libc.src.math.nanbf16
libc.src.math.nextafterbf16
libc.src.math.nextdownbf16
diff --git a/libc/docs/headers/math/index.rst b/libc/docs/headers/math/index.rst
index 9efbce06920b5..5049ab65d00af 100644
--- a/libc/docs/headers/math/index.rst
+++ b/libc/docs/headers/math/index.rst
@@ -179,7 +179,7 @@ Basic Operations
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
| fmul | N/A | |check| | |check| | N/A | |check|\* | N/A | 7.12.14.3 | F.10.11 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| frexp | |check| | |check| | |check| | |check| | |check| | | 7.12.6.7 | F.10.3.7 |
+| frexp | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.6.7 | F.10.3.7 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
| fromfp | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.9.10 | F.10.6.10 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
@@ -189,21 +189,21 @@ Basic Operations
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
| getpayload | |check| | |check| | |check| | |check| | |check| | |check| | F.10.13.1 | N/A |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| ilogb | |check| | |check| | |check| | |check| | |check| | | 7.12.6.8 | F.10.3.8 |
+| ilogb | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.6.8 | F.10.3.8 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
| iscanonical | |check| | |check| | |check| | |check| | |check| | | 7.12.3.2 | N/A |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
| issignaling | |check| | |check| | |check| | |check| | |check| | | 7.12.3.8 | N/A |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| ldexp | |check| | |check| | |check| | |check| | |check| | | 7.12.6.9 | F.10.3.9 |
+| ldexp | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.6.9 | F.10.3.9 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| llogb | |check| | |check| | |check| | |check| | |check| | | 7.12.6.10 | F.10.3.10 |
+| llogb | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.6.10 | F.10.3.10 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
| llrint | |check| | |check| | |check| | |check| | |check| | | 7.12.9.5 | F.10.6.5 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
| llround | |check| | |check| | |check| | |check| | |check| | | 7.12.9.7 | F.10.6.7 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| logb | |check| | |check| | |check| | |check| | |check| | | 7.12.6.17 | F.10.3.17 |
+| logb | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.6.17 | F.10.3.17 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
| lrint | |check| | |check| | |check| | |check| | |check| | | 7.12.9.5 | F.10.6.5 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
diff --git a/libc/src/__support/FPUtil/bfloat16.h b/libc/src/__support/FPUtil/bfloat16.h
index 3fab2b80317de..89d06a06f2dcf 100644
--- a/libc/src/__support/FPUtil/bfloat16.h
+++ b/libc/src/__support/FPUtil/bfloat16.h
@@ -48,6 +48,8 @@ struct BFloat16 {
xd(sign, 0, value);
bits = xd.template as<bfloat16, /*ShouldSignalExceptions=*/true>().bits;
+ } else if constexpr (cpp::is_convertible_v<T, BFloat16>) {
+ bits = value.operator BFloat16().bits;
} else {
bits = fputil::cast<bfloat16>(static_cast<float>(value)).bits;
}
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 0000000000000..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.macros.config
+ libc.src.__support.macros.properties.types
+)
+
add_entrypoint_object(
llogb
SRCS
@@ -1836,6 +1864,20 @@ add_entrypoint_object(
libc.src.__support.FPUtil.manipulation_functions
)
+add_entrypoint_object(
+ llogbbf16
+ SRCS
+ llogbbf16.cpp
+ HDRS
+ ../llogbbf16.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(
ldexp
SRCS
@@ -1886,6 +1928,20 @@ add_entrypoint_object(
libc.src.__support.math.ldexpf128
)
+add_entrypoint_object(
+ ldexpbf16
+ SRCS
+ ldexpbf16.cpp
+ HDRS
+ ../ldexpbf16.h
+ DE...
[truncated]
|
Signed-off-by: Krishna Pandey <[email protected]>
Signed-off-by: Krishna Pandey <[email protected]>
Signed-off-by: Krishna Pandey <[email protected]>
Signed-off-by: Krishna Pandey <[email protected]>
This PR adds the following basic math functions for BFloat16 type along with the tests: