llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-risc-v

Author: Krishna Pandey (krishna2803)

<details>
<summary>Changes</summary>

This PR adds the following basic math functions for BFloat16 type along with 
the tests:
- scalbnbf16
- scalblnbf16



---
Full diff: https://github.com/llvm/llvm-project/pull/155569.diff


22 Files Affected:

- (modified) libc/config/baremetal/aarch64/entrypoints.txt (+2) 
- (modified) libc/config/baremetal/arm/entrypoints.txt (+2) 
- (modified) libc/config/baremetal/riscv/entrypoints.txt (+2) 
- (modified) libc/config/darwin/aarch64/entrypoints.txt (+2) 
- (modified) libc/config/darwin/x86_64/entrypoints.txt (+2) 
- (modified) libc/config/gpu/amdgpu/entrypoints.txt (+2) 
- (modified) libc/config/gpu/nvptx/entrypoints.txt (+2) 
- (modified) libc/config/linux/aarch64/entrypoints.txt (+2) 
- (modified) libc/config/linux/arm/entrypoints.txt (+2) 
- (modified) libc/config/linux/riscv/entrypoints.txt (+2) 
- (modified) libc/config/linux/x86_64/entrypoints.txt (+2) 
- (modified) libc/config/windows/entrypoints.txt (+2) 
- (modified) libc/docs/headers/math/index.rst (+2-2) 
- (modified) libc/src/math/CMakeLists.txt (+2) 
- (modified) libc/src/math/generic/CMakeLists.txt (+28) 
- (added) libc/src/math/generic/scalblnbf16.cpp (+21) 
- (added) libc/src/math/generic/scalbnbf16.cpp (+21) 
- (added) libc/src/math/scalblnbf16.h (+21) 
- (added) libc/src/math/scalbnbf16.h (+21) 
- (modified) libc/test/src/math/smoke/CMakeLists.txt (+32) 
- (added) libc/test/src/math/smoke/scalblnbf16_test.cpp (+14) 
- (added) libc/test/src/math/smoke/scalbnbf16_test.cpp (+14) 


``````````diff
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)

``````````

</details>


https://github.com/llvm/llvm-project/pull/155569
_______________________________________________
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to