Repository navigation
[libc][math][c++23] Add scalb{,l}nbf16 math functions - #155569
Merged
Merged
Conversation
…f16 math functions Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
…signaling}bf16 math functions Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
…th functions Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
Member
|
@llvm/pr-subscribers-libc @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:
Full diff: https://github.com/llvm/llvm-project/pull/155569.diff 22 Files Affected:
diff --git a/libc/config/baremetal/aarch64/entrypoints.txt b/libc/config/baremetal/aarch64/entrypoints.txt
index ff3a6bfa8a2fc..637be4f19d5b7 100644
--- a/libc/config/baremetal/aarch64/entrypoints.txt
+++ b/libc/config/baremetal/aarch64/entrypoints.txt
@@ -814,6 +814,8 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.rintbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
+ libc.src.math.scalblnbf16
+ libc.src.math.scalbnbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
libc.src.math.truncbf16
diff --git a/libc/config/baremetal/arm/entrypoints.txt b/libc/config/baremetal/arm/entrypoints.txt
index f8916d71f86aa..19aedb0a8677d 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -817,6 +817,8 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.rintbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
+ libc.src.math.scalblnbf16
+ libc.src.math.scalbnbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
libc.src.math.truncbf16
diff --git a/libc/config/baremetal/riscv/entrypoints.txt b/libc/config/baremetal/riscv/entrypoints.txt
index 8a72fa6692869..cfbb598cbe4bf 100644
--- a/libc/config/baremetal/riscv/entrypoints.txt
+++ b/libc/config/baremetal/riscv/entrypoints.txt
@@ -817,6 +817,8 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.rintbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
+ libc.src.math.scalblnbf16
+ libc.src.math.scalbnbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
libc.src.math.truncbf16
diff --git a/libc/config/darwin/aarch64/entrypoints.txt b/libc/config/darwin/aarch64/entrypoints.txt
index 796c0d3c8a4ff..26e97d8993039 100644
--- a/libc/config/darwin/aarch64/entrypoints.txt
+++ b/libc/config/darwin/aarch64/entrypoints.txt
@@ -647,6 +647,8 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.rintbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
+ libc.src.math.scalblnbf16
+ libc.src.math.scalbnbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
libc.src.math.truncbf16
diff --git a/libc/config/darwin/x86_64/entrypoints.txt b/libc/config/darwin/x86_64/entrypoints.txt
index fa1d8def8936c..0556a6f7a4715 100644
--- a/libc/config/darwin/x86_64/entrypoints.txt
+++ b/libc/config/darwin/x86_64/entrypoints.txt
@@ -290,6 +290,8 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.rintbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
+ libc.src.math.scalblnbf16
+ libc.src.math.scalbnbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
libc.src.math.truncbf16
diff --git a/libc/config/gpu/amdgpu/entrypoints.txt b/libc/config/gpu/amdgpu/entrypoints.txt
index 49c41411cb5d2..8817972480aac 100644
--- a/libc/config/gpu/amdgpu/entrypoints.txt
+++ b/libc/config/gpu/amdgpu/entrypoints.txt
@@ -673,6 +673,8 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.rintbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
+ libc.src.math.scalblnbf16
+ libc.src.math.scalbnbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
libc.src.math.truncbf16
diff --git a/libc/config/gpu/nvptx/entrypoints.txt b/libc/config/gpu/nvptx/entrypoints.txt
index 06a2c9addb7fb..db762ed5c74d6 100644
--- a/libc/config/gpu/nvptx/entrypoints.txt
+++ b/libc/config/gpu/nvptx/entrypoints.txt
@@ -675,6 +675,8 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.rintbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
+ libc.src.math.scalblnbf16
+ libc.src.math.scalbnbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
libc.src.math.truncbf16
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index feea7ff69c166..0a2ebfa3f8720 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -902,6 +902,8 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.rintbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
+ libc.src.math.scalblnbf16
+ libc.src.math.scalbnbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
libc.src.math.truncbf16
diff --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt
index 8e92fac863c6b..ea1c5c0558272 100644
--- a/libc/config/linux/arm/entrypoints.txt
+++ b/libc/config/linux/arm/entrypoints.txt
@@ -517,6 +517,8 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.rintbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
+ libc.src.math.scalblnbf16
+ libc.src.math.scalbnbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
libc.src.math.truncbf16
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index fb08cfe7bd3f8..d5180b77c3af0 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -920,6 +920,8 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.rintbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
+ libc.src.math.scalblnbf16
+ libc.src.math.scalbnbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
libc.src.math.truncbf16
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 37af75454daa3..c64db2cc3548f 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -953,6 +953,8 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.rintbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
+ libc.src.math.scalblnbf16
+ libc.src.math.scalbnbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
libc.src.math.truncbf16
diff --git a/libc/config/windows/entrypoints.txt b/libc/config/windows/entrypoints.txt
index c09e6b259fa42..9f825bdf657e9 100644
--- a/libc/config/windows/entrypoints.txt
+++ b/libc/config/windows/entrypoints.txt
@@ -363,6 +363,8 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.rintbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
+ libc.src.math.scalblnbf16
+ libc.src.math.scalbnbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
libc.src.math.truncbf16
diff --git a/libc/docs/headers/math/index.rst b/libc/docs/headers/math/index.rst
index 89624460c3af5..a707b37894afc 100644
--- a/libc/docs/headers/math/index.rst
+++ b/libc/docs/headers/math/index.rst
@@ -233,9 +233,9 @@ Basic Operations
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
| roundeven | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.9.8 | F.10.6.8 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| scalbln | |check| | |check| | |check| | |check| | |check| | | 7.12.6.19 | F.10.3.19 |
+| scalbln | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.6.19 | F.10.3.19 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| scalbn | |check| | |check| | |check| | |check| | |check| | | 7.12.6.19 | F.10.3.19 |
+| scalbn | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.6.19 | F.10.3.19 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
| setpayload | |check| | |check| | |check| | |check| | |check| | |check| | F.10.13.2 | N/A |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
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 0000000000000..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 0000000000000..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 file mode 100644
index 0000000000000..10aad05fc6b1f
--- /dev/null
+++ b/libc/src/math/scalblnbf16.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for scalblnbf16 -------------------*- 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_SCALBLNBF16_H
+#define LLVM_LIBC_SRC_MATH_SCALBLNBF16_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+bfloat16 scalblnbf16(bfloat16 x, long n);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_SCALBLNBF16_H
diff --git a/libc/src/math/scalbnbf16.h b/libc/src/math/scalbnbf16.h
new file mode 100644
index 0000000000000..67efa338fe630
--- /dev/null
+++ b/libc/src/math/scalbnbf16.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for scalbnbf16 --------------------*- 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_SCALBNBF16_H
+#define LLVM_LIBC_SRC_MATH_SCALBNBF16_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+bfloat16 scalbnbf16(bfloat16 x, int n);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_SCALBNBF16_H
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index 166802fd9f9cc..226ef2ee71866 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -4881,6 +4881,22 @@ add_fp_unittest(
libc.src.__support.FPUtil.normal_float
)
+add_fp_unittest(
+ scalblnbf16_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ scalblnbf16_test.cpp
+ HDRS
+ ScalbnTest.h
+ DEPENDS
+ libc.src.math.scalblnbf16
+ libc.src.__support.CPP.limits
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.fp_bits
+ libc.src.__support.FPUtil.normal_float
+)
+
add_fp_unittest(
scalbn_test
SUITE
@@ -4956,6 +4972,22 @@ add_fp_unittest(
libc.src.__support.FPUtil.normal_float
)
+add_fp_unittest(
+ scalbnbf16_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ scalbnbf16_test.cpp
+ HDRS
+ ScalbnTest.h
+ DEPENDS
+ libc.src.math.scalbnbf16
+ libc.src.__support.CPP.limits
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.fp_bits
+ libc.src.__support.FPUtil.normal_float
+)
+
add_fp_unittest(
erff_test
SUITE
diff --git a/libc/test/src/math/smoke/scalblnbf16_test.cpp b/libc/test/src/math/smoke/scalblnbf16_test.cpp
new file mode 100644
index 0000000000000..c6fc3aac5e744
--- /dev/null
+++ b/libc/test/src/math/smoke/scalblnbf16_test.cpp
@@ -0,0 +1,14 @@
+//===-- Unittests for scalblnbf16 -----------------------------------------===//
+//
+// 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 "ScalbnTest.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/scalblnbf16.h"
+
+LIST_SCALBN_TESTS(bfloat16, long, LIBC_NAMESPACE::scalblnbf16)
diff --git a/libc/test/src/math/smoke/scalbnbf16_test.cpp b/libc/test/src/math/smoke/scalbnbf16_test.cpp
new file mode 100644
index 0000000000000..855fd75e6e8f9
--- /dev/null
+++ b/libc/test/src/math/smoke/scalbnbf16_test.cpp
@@ -0,0 +1,14 @@
+//===-- Unittests for scalbnbf16 ------------------------------------------===//
+//
+// 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 "ScalbnTest.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/scalbnbf16.h"
+
+LIST_SCALBN_TESTS(bfloat16, int, LIBC_NAMESPACE::scalbnbf16)
|
Member
|
@llvm/pr-subscribers-backend-amdgpu Author: Krishna Pandey (krishna2803) ChangesThis PR adds the following basic math functions for BFloat16 type along with the tests:
Full diff: https://github.com/llvm/llvm-project/pull/155569.diff 22 Files Affected:
diff --git a/libc/config/baremetal/aarch64/entrypoints.txt b/libc/config/baremetal/aarch64/entrypoints.txt
index ff3a6bfa8a2fc..637be4f19d5b7 100644
--- a/libc/config/baremetal/aarch64/entrypoints.txt
+++ b/libc/config/baremetal/aarch64/entrypoints.txt
@@ -814,6 +814,8 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.rintbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
+ libc.src.math.scalblnbf16
+ libc.src.math.scalbnbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
libc.src.math.truncbf16
diff --git a/libc/config/baremetal/arm/entrypoints.txt b/libc/config/baremetal/arm/entrypoints.txt
index f8916d71f86aa..19aedb0a8677d 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -817,6 +817,8 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.rintbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
+ libc.src.math.scalblnbf16
+ libc.src.math.scalbnbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
libc.src.math.truncbf16
diff --git a/libc/config/baremetal/riscv/entrypoints.txt b/libc/config/baremetal/riscv/entrypoints.txt
index 8a72fa6692869..cfbb598cbe4bf 100644
--- a/libc/config/baremetal/riscv/entrypoints.txt
+++ b/libc/config/baremetal/riscv/entrypoints.txt
@@ -817,6 +817,8 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.rintbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
+ libc.src.math.scalblnbf16
+ libc.src.math.scalbnbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
libc.src.math.truncbf16
diff --git a/libc/config/darwin/aarch64/entrypoints.txt b/libc/config/darwin/aarch64/entrypoints.txt
index 796c0d3c8a4ff..26e97d8993039 100644
--- a/libc/config/darwin/aarch64/entrypoints.txt
+++ b/libc/config/darwin/aarch64/entrypoints.txt
@@ -647,6 +647,8 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.rintbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
+ libc.src.math.scalblnbf16
+ libc.src.math.scalbnbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
libc.src.math.truncbf16
diff --git a/libc/config/darwin/x86_64/entrypoints.txt b/libc/config/darwin/x86_64/entrypoints.txt
index fa1d8def8936c..0556a6f7a4715 100644
--- a/libc/config/darwin/x86_64/entrypoints.txt
+++ b/libc/config/darwin/x86_64/entrypoints.txt
@@ -290,6 +290,8 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.rintbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
+ libc.src.math.scalblnbf16
+ libc.src.math.scalbnbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
libc.src.math.truncbf16
diff --git a/libc/config/gpu/amdgpu/entrypoints.txt b/libc/config/gpu/amdgpu/entrypoints.txt
index 49c41411cb5d2..8817972480aac 100644
--- a/libc/config/gpu/amdgpu/entrypoints.txt
+++ b/libc/config/gpu/amdgpu/entrypoints.txt
@@ -673,6 +673,8 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.rintbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
+ libc.src.math.scalblnbf16
+ libc.src.math.scalbnbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
libc.src.math.truncbf16
diff --git a/libc/config/gpu/nvptx/entrypoints.txt b/libc/config/gpu/nvptx/entrypoints.txt
index 06a2c9addb7fb..db762ed5c74d6 100644
--- a/libc/config/gpu/nvptx/entrypoints.txt
+++ b/libc/config/gpu/nvptx/entrypoints.txt
@@ -675,6 +675,8 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.rintbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
+ libc.src.math.scalblnbf16
+ libc.src.math.scalbnbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
libc.src.math.truncbf16
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index feea7ff69c166..0a2ebfa3f8720 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -902,6 +902,8 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.rintbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
+ libc.src.math.scalblnbf16
+ libc.src.math.scalbnbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
libc.src.math.truncbf16
diff --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt
index 8e92fac863c6b..ea1c5c0558272 100644
--- a/libc/config/linux/arm/entrypoints.txt
+++ b/libc/config/linux/arm/entrypoints.txt
@@ -517,6 +517,8 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.rintbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
+ libc.src.math.scalblnbf16
+ libc.src.math.scalbnbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
libc.src.math.truncbf16
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index fb08cfe7bd3f8..d5180b77c3af0 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -920,6 +920,8 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.rintbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
+ libc.src.math.scalblnbf16
+ libc.src.math.scalbnbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
libc.src.math.truncbf16
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 37af75454daa3..c64db2cc3548f 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -953,6 +953,8 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.rintbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
+ libc.src.math.scalblnbf16
+ libc.src.math.scalbnbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
libc.src.math.truncbf16
diff --git a/libc/config/windows/entrypoints.txt b/libc/config/windows/entrypoints.txt
index c09e6b259fa42..9f825bdf657e9 100644
--- a/libc/config/windows/entrypoints.txt
+++ b/libc/config/windows/entrypoints.txt
@@ -363,6 +363,8 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
libc.src.math.rintbf16
libc.src.math.roundbf16
libc.src.math.roundevenbf16
+ libc.src.math.scalblnbf16
+ libc.src.math.scalbnbf16
libc.src.math.setpayloadbf16
libc.src.math.setpayloadsigbf16
libc.src.math.truncbf16
diff --git a/libc/docs/headers/math/index.rst b/libc/docs/headers/math/index.rst
index 89624460c3af5..a707b37894afc 100644
--- a/libc/docs/headers/math/index.rst
+++ b/libc/docs/headers/math/index.rst
@@ -233,9 +233,9 @@ Basic Operations
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
| roundeven | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.9.8 | F.10.6.8 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| scalbln | |check| | |check| | |check| | |check| | |check| | | 7.12.6.19 | F.10.3.19 |
+| scalbln | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.6.19 | F.10.3.19 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| scalbn | |check| | |check| | |check| | |check| | |check| | | 7.12.6.19 | F.10.3.19 |
+| scalbn | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.6.19 | F.10.3.19 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
| setpayload | |check| | |check| | |check| | |check| | |check| | |check| | F.10.13.2 | N/A |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
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 0000000000000..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 0000000000000..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 file mode 100644
index 0000000000000..10aad05fc6b1f
--- /dev/null
+++ b/libc/src/math/scalblnbf16.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for scalblnbf16 -------------------*- 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_SCALBLNBF16_H
+#define LLVM_LIBC_SRC_MATH_SCALBLNBF16_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+bfloat16 scalblnbf16(bfloat16 x, long n);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_SCALBLNBF16_H
diff --git a/libc/src/math/scalbnbf16.h b/libc/src/math/scalbnbf16.h
new file mode 100644
index 0000000000000..67efa338fe630
--- /dev/null
+++ b/libc/src/math/scalbnbf16.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for scalbnbf16 --------------------*- 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_SCALBNBF16_H
+#define LLVM_LIBC_SRC_MATH_SCALBNBF16_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+bfloat16 scalbnbf16(bfloat16 x, int n);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_SCALBNBF16_H
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index 166802fd9f9cc..226ef2ee71866 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -4881,6 +4881,22 @@ add_fp_unittest(
libc.src.__support.FPUtil.normal_float
)
+add_fp_unittest(
+ scalblnbf16_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ scalblnbf16_test.cpp
+ HDRS
+ ScalbnTest.h
+ DEPENDS
+ libc.src.math.scalblnbf16
+ libc.src.__support.CPP.limits
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.fp_bits
+ libc.src.__support.FPUtil.normal_float
+)
+
add_fp_unittest(
scalbn_test
SUITE
@@ -4956,6 +4972,22 @@ add_fp_unittest(
libc.src.__support.FPUtil.normal_float
)
+add_fp_unittest(
+ scalbnbf16_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ scalbnbf16_test.cpp
+ HDRS
+ ScalbnTest.h
+ DEPENDS
+ libc.src.math.scalbnbf16
+ libc.src.__support.CPP.limits
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.fp_bits
+ libc.src.__support.FPUtil.normal_float
+)
+
add_fp_unittest(
erff_test
SUITE
diff --git a/libc/test/src/math/smoke/scalblnbf16_test.cpp b/libc/test/src/math/smoke/scalblnbf16_test.cpp
new file mode 100644
index 0000000000000..c6fc3aac5e744
--- /dev/null
+++ b/libc/test/src/math/smoke/scalblnbf16_test.cpp
@@ -0,0 +1,14 @@
+//===-- Unittests for scalblnbf16 -----------------------------------------===//
+//
+// 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 "ScalbnTest.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/scalblnbf16.h"
+
+LIST_SCALBN_TESTS(bfloat16, long, LIBC_NAMESPACE::scalblnbf16)
diff --git a/libc/test/src/math/smoke/scalbnbf16_test.cpp b/libc/test/src/math/smoke/scalbnbf16_test.cpp
new file mode 100644
index 0000000000000..855fd75e6e8f9
--- /dev/null
+++ b/libc/test/src/math/smoke/scalbnbf16_test.cpp
@@ -0,0 +1,14 @@
+//===-- Unittests for scalbnbf16 ------------------------------------------===//
+//
+// 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 "ScalbnTest.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/scalbnbf16.h"
+
+LIST_SCALBN_TESTS(bfloat16, int, LIBC_NAMESPACE::scalbnbf16)
|
overmighty
requested changes
Aug 27, 2025
Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
overmighty
approved these changes
Aug 27, 2025
rupprecht
added a commit
that referenced
this pull request
Aug 28, 2025
These are redefined/shadowed by the `if constexpr (FPBits::FRACTION_LEN - 1 >= 5)` case below. Added by #155569
rupprecht
added a commit
that referenced
this pull request
Aug 28, 2025
llvm-sync Bot
pushed a commit
to arm/arm-toolchain
that referenced
this pull request
Aug 28, 2025
These are redefined/shadowed by the if constexpr (FPBits::FRACTION_LEN - 1 >= 5) case below. Added by llvm/llvm-project#155569. I missed these ones in #155894.
TheArchitectOrigin
pushed a commit
to XSLabs/fuchsia
that referenced
this pull request
Sep 1, 2025
…iables (#155925) These are redefined/shadowed by the if constexpr (FPBits::FRACTION_LEN - 1 >= 5) case below. Added by llvm/llvm-project#155569. I missed these ones in #155894. GitOrigin-RevId: 3ea7956fd326defab6d1b9a97d9bbd80b5ca3505 Original-Revision: b40c9b8d009430302e7d1917a4e37b9120fe982b Rolled-Repo: https://llvm.googlesource.com/llvm-project/libc Rolled-Commits: be3c2eaf490158..b40c9b8d009430 Roller-URL: https://cr-buildbucket.appspot.com/build/8705226799329368289 CQ-Do-Not-Cancel-Tryjobs: true Cq-Include-Trybots: luci.turquoise.global.try:run-postsubmit-tryjobs Change-Id: I138c8e2d8835555b5d99c05d32a284c2cded00de Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/1356900 Commit-Queue: GI Roller <global-integration-roller@fuchsia-infra.iam.gserviceaccount.com>
markrvmurray
pushed a commit
to markrvmurray/llvm-mc6809
that referenced
this pull request
Jun 14, 2026
These are redefined/shadowed by the if constexpr (FPBits::FRACTION_LEN - 1 >= 5) case below. Added by llvm/llvm-project#155569. I missed these ones in #155894.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds the following basic math functions for BFloat16 type along with the tests: