-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[libc][math][c++23] Add {get,set}payloadbf16 and setpayloadsigbf16 math functions #153994
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]>
@llvm/pr-subscribers-backend-amdgpu @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 33.42 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/153994.diff 29 Files Affected:
diff --git a/libc/config/baremetal/aarch64/entrypoints.txt b/libc/config/baremetal/aarch64/entrypoints.txt
index 26ee82d99192f..5f72793beecb4 100644
--- a/libc/config/baremetal/aarch64/entrypoints.txt
+++ b/libc/config/baremetal/aarch64/entrypoints.txt
@@ -787,12 +787,15 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_numbf16
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
+ libc.src.math.getpayloadbf16
libc.src.math.nextafterbf16
libc.src.math.nextdownbf16
libc.src.math.nexttowardbf16
libc.src.math.nextupbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
+ libc.src.math.setpayloadbf16
+ libc.src.math.setpayloadsigbf16
libc.src.math.truncbf16
libc.src.math.ufromfpbf16
libc.src.math.ufromfpxbf16
diff --git a/libc/config/baremetal/arm/entrypoints.txt b/libc/config/baremetal/arm/entrypoints.txt
index 00025d324fc2c..244dd2e87b1fd 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -790,12 +790,15 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_numbf16
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
+ libc.src.math.getpayloadbf16
libc.src.math.nextafterbf16
libc.src.math.nextdownbf16
libc.src.math.nexttowardbf16
libc.src.math.nextupbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
+ libc.src.math.setpayloadbf16
+ libc.src.math.setpayloadsigbf16
libc.src.math.truncbf16
libc.src.math.ufromfpbf16
libc.src.math.ufromfpxbf16
diff --git a/libc/config/baremetal/riscv/entrypoints.txt b/libc/config/baremetal/riscv/entrypoints.txt
index c0ab0cf903c41..32980c4a1d222 100644
--- a/libc/config/baremetal/riscv/entrypoints.txt
+++ b/libc/config/baremetal/riscv/entrypoints.txt
@@ -790,12 +790,15 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_numbf16
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
+ libc.src.math.getpayloadbf16
libc.src.math.nextafterbf16
libc.src.math.nextdownbf16
libc.src.math.nexttowardbf16
libc.src.math.nextupbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
+ libc.src.math.setpayloadbf16
+ libc.src.math.setpayloadsigbf16
libc.src.math.truncbf16
libc.src.math.ufromfpbf16
libc.src.math.ufromfpxbf16
diff --git a/libc/config/darwin/aarch64/entrypoints.txt b/libc/config/darwin/aarch64/entrypoints.txt
index cd81756770ed4..3684713474cbc 100644
--- a/libc/config/darwin/aarch64/entrypoints.txt
+++ b/libc/config/darwin/aarch64/entrypoints.txt
@@ -620,12 +620,15 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_numbf16
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
+ libc.src.math.getpayloadbf16
libc.src.math.nextafterbf16
libc.src.math.nextdownbf16
libc.src.math.nexttowardbf16
libc.src.math.nextupbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
+ libc.src.math.setpayloadbf16
+ libc.src.math.setpayloadsigbf16
libc.src.math.truncbf16
libc.src.math.ufromfpbf16
libc.src.math.ufromfpxbf16
diff --git a/libc/config/darwin/x86_64/entrypoints.txt b/libc/config/darwin/x86_64/entrypoints.txt
index 3aa54e027a42d..7482a80c37d33 100644
--- a/libc/config/darwin/x86_64/entrypoints.txt
+++ b/libc/config/darwin/x86_64/entrypoints.txt
@@ -263,12 +263,15 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_numbf16
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
+ libc.src.math.getpayloadbf16
libc.src.math.nextafterbf16
libc.src.math.nextdownbf16
libc.src.math.nexttowardbf16
libc.src.math.nextupbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
+ libc.src.math.setpayloadbf16
+ libc.src.math.setpayloadsigbf16
libc.src.math.truncbf16
libc.src.math.ufromfpbf16
libc.src.math.ufromfpxbf16
diff --git a/libc/config/gpu/amdgpu/entrypoints.txt b/libc/config/gpu/amdgpu/entrypoints.txt
index 3b42c0fd71547..a88c74be2997a 100644
--- a/libc/config/gpu/amdgpu/entrypoints.txt
+++ b/libc/config/gpu/amdgpu/entrypoints.txt
@@ -646,12 +646,15 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_numbf16
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
+ libc.src.math.getpayloadbf16
libc.src.math.nextafterbf16
libc.src.math.nextdownbf16
libc.src.math.nexttowardbf16
libc.src.math.nextupbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
+ libc.src.math.setpayloadbf16
+ libc.src.math.setpayloadsigbf16
libc.src.math.truncbf16
libc.src.math.ufromfpbf16
libc.src.math.ufromfpxbf16
diff --git a/libc/config/gpu/nvptx/entrypoints.txt b/libc/config/gpu/nvptx/entrypoints.txt
index b569327409849..08e6c7dc34b07 100644
--- a/libc/config/gpu/nvptx/entrypoints.txt
+++ b/libc/config/gpu/nvptx/entrypoints.txt
@@ -647,12 +647,15 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_numbf16
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
+ libc.src.math.getpayloadbf16
libc.src.math.nextafterbf16
libc.src.math.nextdownbf16
libc.src.math.nexttowardbf16
libc.src.math.nextupbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
+ libc.src.math.setpayloadbf16
+ libc.src.math.setpayloadsigbf16
libc.src.math.truncbf16
libc.src.math.ufromfpbf16
libc.src.math.ufromfpxbf16
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 4058e7155f34a..ea7e2065b2216 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -874,12 +874,15 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_numbf16
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
+ libc.src.math.getpayloadbf16
libc.src.math.nextafterbf16
libc.src.math.nextdownbf16
libc.src.math.nexttowardbf16
libc.src.math.nextupbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
+ libc.src.math.setpayloadbf16
+ libc.src.math.setpayloadsigbf16
libc.src.math.truncbf16
libc.src.math.ufromfpbf16
libc.src.math.ufromfpxbf16
diff --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt
index 9002bd12d6733..8f21976e9e88e 100644
--- a/libc/config/linux/arm/entrypoints.txt
+++ b/libc/config/linux/arm/entrypoints.txt
@@ -490,12 +490,15 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_numbf16
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
+ libc.src.math.getpayloadbf16
libc.src.math.nextafterbf16
libc.src.math.nextdownbf16
libc.src.math.nexttowardbf16
libc.src.math.nextupbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
+ libc.src.math.setpayloadbf16
+ libc.src.math.setpayloadsigbf16
libc.src.math.truncbf16
libc.src.math.ufromfpbf16
libc.src.math.ufromfpxbf16
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 77d5bae188a3c..69d7519118198 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -893,12 +893,15 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_numbf16
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
+ libc.src.math.getpayloadbf16
libc.src.math.nextafterbf16
libc.src.math.nextdownbf16
libc.src.math.nexttowardbf16
libc.src.math.nextupbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
+ libc.src.math.setpayloadbf16
+ libc.src.math.setpayloadsigbf16
libc.src.math.truncbf16
libc.src.math.ufromfpbf16
libc.src.math.ufromfpxbf16
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index b811fe79c174d..75dcfd6382f1b 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -925,12 +925,15 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_numbf16
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
+ libc.src.math.getpayloadbf16
libc.src.math.nextafterbf16
libc.src.math.nextdownbf16
libc.src.math.nexttowardbf16
libc.src.math.nextupbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
+ libc.src.math.setpayloadbf16
+ libc.src.math.setpayloadsigbf16
libc.src.math.truncbf16
libc.src.math.ufromfpbf16
libc.src.math.ufromfpxbf16
diff --git a/libc/config/windows/entrypoints.txt b/libc/config/windows/entrypoints.txt
index ec2fde253e898..541d9fee1adf5 100644
--- a/libc/config/windows/entrypoints.txt
+++ b/libc/config/windows/entrypoints.txt
@@ -336,12 +336,15 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.fminimum_numbf16
libc.src.math.fromfpbf16
libc.src.math.fromfpxbf16
+ libc.src.math.getpayloadbf16
libc.src.math.nextafterbf16
libc.src.math.nextdownbf16
libc.src.math.nexttowardbf16
libc.src.math.nextupbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
+ libc.src.math.setpayloadbf16
+ libc.src.math.setpayloadsigbf16
libc.src.math.truncbf16
libc.src.math.ufromfpbf16
libc.src.math.ufromfpxbf16
diff --git a/libc/docs/headers/math/index.rst b/libc/docs/headers/math/index.rst
index 591295659c3d4..d8921b985b1f2 100644
--- a/libc/docs/headers/math/index.rst
+++ b/libc/docs/headers/math/index.rst
@@ -187,7 +187,7 @@ Basic Operations
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
| fsub | N/A | |check| | |check| | N/A | |check|\* | N/A | 7.12.14.2 | F.10.11 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| getpayload | |check| | |check| | |check| | |check| | |check| | | F.10.13.1 | N/A |
+| 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 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
@@ -237,9 +237,9 @@ Basic Operations
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
| scalbn | |check| | |check| | |check| | |check| | |check| | | 7.12.6.19 | F.10.3.19 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| setpayload | |check| | |check| | |check| | |check| | |check| | | F.10.13.2 | N/A |
+| setpayload | |check| | |check| | |check| | |check| | |check| | |check| | F.10.13.2 | N/A |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| setpayloadsig | |check| | |check| | |check| | |check| | |check| | | F.10.13.3 | N/A |
+| setpayloadsig | |check| | |check| | |check| | |check| | |check| | |check| | F.10.13.3 | N/A |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
| totalorder | |check| | |check| | |check| | |check| | |check| | | F.10.12.1 | N/A |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
diff --git a/libc/src/__support/FPUtil/BasicOperations.h b/libc/src/__support/FPUtil/BasicOperations.h
index 2357b053b60b8..994237ba8492e 100644
--- a/libc/src/__support/FPUtil/BasicOperations.h
+++ b/libc/src/__support/FPUtil/BasicOperations.h
@@ -354,7 +354,10 @@ LIBC_INLINE cpp::enable_if_t<cpp::is_floating_point_v<T>, T> getpayload(T x) {
return static_cast<T>(payload_dfloat);
} else {
- return static_cast<T>(payload);
+ if constexpr (cpp::is_same_v<T, bfloat16>)
+ return T(static_cast<int>(payload));
+ else
+ return static_cast<T>(payload);
}
}
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 0000000000000..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, (const bfloat16 *x)) {
+ return fputil::getpayload(*x);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/setpayloadbf16.cpp b/libc/src/math/generic/setpayloadbf16.cpp
new file mode 100644
index 0000000000000..49f9b9cabd6a2
--- /dev/null
+++ b/libc/src/math/generic/setpayloadbf16.cpp
@@ -0,0 +1,21 @@
+//===-- Implementation of setpayloadbf16 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/setpayloadbf16.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, setpayloadbf16, (bfloat16 * res, bfloat16 pl)) {
+ return static_cast<int>(fputil::setpayload</*IsSignaling=*/false>(*res, pl));
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/setpayloadsigbf16.cpp b/libc/src/math/generic/setpayloadsigbf16.cpp
new file mode 100644
index 0000000000000..7a2b7c7dc66dd
--- /dev/null
+++ b/libc/src/math/generic/setpayloadsigbf16.cpp
@@ -0,0 +1,21 @@
+//===-- Implementation of setpayloadsigbf16 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/setpayloadsigbf16.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, setpayloadsigbf16, (bfloat16 * res, bfloat16 pl)) {
+ return static_cast<int>(fputil::setpayload</*IsSignaling=*/true>(*res, pl));
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/getpayloadbf16.h b/libc/src/math/getpayloadbf16.h
new file mode 100644
index 0000000000000..e4767f0728139
--- /dev/null
+++ b/libc/src/math/getpayloadbf16.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for getpayloadbf16 ----------------*- 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_GETPAYLOADBF16_H
+#define LLVM_LIBC_SRC_MATH_GETPAYLOADBF16_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+bfloat16 getpayloadb...
[truncated]
|
return static_cast<T>(payload); | ||
if constexpr (cpp::is_same_v<T, bfloat16>) | ||
return T(static_cast<int>(payload)); | ||
else | ||
return static_cast<T>(payload); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we have the BFloat16(uint16_t bits)
constructor again? Removing it makes this change unnecessary and libc-math-smoke-tests
and libc.test.src.__support.FPUtil.bfloat16_test.__unit__
still pass.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added it in case we might need to construct bfloat16 directly using uint16 values to be able to set its bits directly, but I think it can be removed as we don't use it anywhere. I will run all tests locally to confirm this.
This reverts commit 8ea9354.
Signed-off-by: Krishna Pandey <[email protected]>
EXPECT_FP_EQ(T(0x123.0p+0), funcWrapper(func, neg_qnan_123)); | ||
EXPECT_FP_EQ(T(0x123.0p+0), funcWrapper(func, snan_123)); | ||
EXPECT_FP_EQ(T(0x123.0p+0), funcWrapper(func, neg_snan_123)); | ||
if constexpr (FPBits::FRACTION_LEN - 1 >= 6) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: it's a bit weird that you guard both 6-bit and 5-bit payload test cases with a single FRACTION_LEN - 1 >= 6
check but you guard 7-bit and 9-bit payload test cases with separate FRACTION_LEN - 1 >= 7
and >= 9
checks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added another if for 5 bits in b310e151
This PR adds the following basic math functions for BFloat16 type along with the tests: