[libc-commits] [libc] [libc][math][c++23] Add sqrtbf16 math function (PR #156654)

via libc-commits libc-commits at lists.llvm.org
Wed Sep 3 09:03:08 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: Krishna Pandey (krishna2803)

<details>
<summary>Changes</summary>

This PR adds sqrtbf16 higher math function for BFloat16 type along with the tests.

---

Patch is 53.59 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/156654.diff


22 Files Affected:

- (modified) libc/config/baremetal/aarch64/entrypoints.txt (+1) 
- (modified) libc/config/baremetal/arm/entrypoints.txt (+1) 
- (modified) libc/config/baremetal/riscv/entrypoints.txt (+1) 
- (modified) libc/config/darwin/aarch64/entrypoints.txt (+1) 
- (modified) libc/config/darwin/x86_64/entrypoints.txt (+1) 
- (modified) libc/config/gpu/amdgpu/entrypoints.txt (+1) 
- (modified) libc/config/gpu/nvptx/entrypoints.txt (+1) 
- (modified) libc/config/linux/aarch64/entrypoints.txt (+1) 
- (modified) libc/config/linux/arm/entrypoints.txt (+1) 
- (modified) libc/config/linux/riscv/entrypoints.txt (+1) 
- (modified) libc/config/linux/x86_64/entrypoints.txt (+1) 
- (modified) libc/config/windows/entrypoints.txt (+1) 
- (modified) libc/docs/headers/math/index.rst (+107-107) 
- (modified) libc/src/math/CMakeLists.txt (+1) 
- (modified) libc/src/math/generic/CMakeLists.txt (+15-1) 
- (added) libc/src/math/generic/sqrtbf16.cpp (+21) 
- (added) libc/src/math/sqrtbf16.h (+21) 
- (modified) libc/test/src/math/CMakeLists.txt (+12) 
- (modified) libc/test/src/math/smoke/CMakeLists.txt (+13) 
- (added) libc/test/src/math/smoke/sqrtbf16_test.cpp (+14) 
- (added) libc/test/src/math/sqrtbf16_test.cpp (+29) 
- (modified) libc/utils/MPFRWrapper/MPFRUtils.cpp (+7) 


``````````diff
diff --git a/libc/config/baremetal/aarch64/entrypoints.txt b/libc/config/baremetal/aarch64/entrypoints.txt
index c2e4c337f199a..df9f61ca6c108 100644
--- a/libc/config/baremetal/aarch64/entrypoints.txt
+++ b/libc/config/baremetal/aarch64/entrypoints.txt
@@ -811,6 +811,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.roundevenbf16
   libc.src.math.setpayloadbf16
   libc.src.math.setpayloadsigbf16
+  libc.src.math.sqrtbf16
   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 c4f3a87659b23..779f37be1859c 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -814,6 +814,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.roundevenbf16
   libc.src.math.setpayloadbf16
   libc.src.math.setpayloadsigbf16
+  libc.src.math.sqrtbf16
   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 380ca57ea8aa9..d0ced09111f9f 100644
--- a/libc/config/baremetal/riscv/entrypoints.txt
+++ b/libc/config/baremetal/riscv/entrypoints.txt
@@ -814,6 +814,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.roundevenbf16
   libc.src.math.setpayloadbf16
   libc.src.math.setpayloadsigbf16
+  libc.src.math.sqrtbf16
   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 1f4318fc88389..a9ae541f8ed44 100644
--- a/libc/config/darwin/aarch64/entrypoints.txt
+++ b/libc/config/darwin/aarch64/entrypoints.txt
@@ -644,6 +644,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.roundevenbf16
   libc.src.math.setpayloadbf16
   libc.src.math.setpayloadsigbf16
+  libc.src.math.sqrtbf16
   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 0cba22016c960..120d98a4a6160 100644
--- a/libc/config/darwin/x86_64/entrypoints.txt
+++ b/libc/config/darwin/x86_64/entrypoints.txt
@@ -287,6 +287,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.roundevenbf16
   libc.src.math.setpayloadbf16
   libc.src.math.setpayloadsigbf16
+  libc.src.math.sqrtbf16
   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 e08b028865bfc..66d0b618fb7cb 100644
--- a/libc/config/gpu/amdgpu/entrypoints.txt
+++ b/libc/config/gpu/amdgpu/entrypoints.txt
@@ -670,6 +670,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.roundevenbf16
   libc.src.math.setpayloadbf16
   libc.src.math.setpayloadsigbf16
+  libc.src.math.sqrtbf16
   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 88c8fc91ebb77..395c7985feee7 100644
--- a/libc/config/gpu/nvptx/entrypoints.txt
+++ b/libc/config/gpu/nvptx/entrypoints.txt
@@ -672,6 +672,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.roundevenbf16
   libc.src.math.setpayloadbf16
   libc.src.math.setpayloadsigbf16
+  libc.src.math.sqrtbf16
   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 20924e9047c69..079466c3b8d81 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -899,6 +899,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.roundevenbf16
   libc.src.math.setpayloadbf16
   libc.src.math.setpayloadsigbf16
+  libc.src.math.sqrtbf16
   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 f2e8ddfe8e91a..116f554a6374b 100644
--- a/libc/config/linux/arm/entrypoints.txt
+++ b/libc/config/linux/arm/entrypoints.txt
@@ -514,6 +514,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.roundevenbf16
   libc.src.math.setpayloadbf16
   libc.src.math.setpayloadsigbf16
+  libc.src.math.sqrtbf16
   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 0ad36a667232a..e5665a7cd139b 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -917,6 +917,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.roundevenbf16
   libc.src.math.setpayloadbf16
   libc.src.math.setpayloadsigbf16
+  libc.src.math.sqrtbf16
   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 c060e900472eb..73ad93d3fdf18 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -950,6 +950,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.roundevenbf16
   libc.src.math.setpayloadbf16
   libc.src.math.setpayloadsigbf16
+  libc.src.math.sqrtbf16
   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 9e45b800b10a3..c742d88f8c90d 100644
--- a/libc/config/windows/entrypoints.txt
+++ b/libc/config/windows/entrypoints.txt
@@ -360,6 +360,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.roundevenbf16
   libc.src.math.setpayloadbf16
   libc.src.math.setpayloadsigbf16
+  libc.src.math.sqrtbf16
   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 b329bf031312d..016d96ce69d4b 100644
--- a/libc/docs/headers/math/index.rst
+++ b/libc/docs/headers/math/index.rst
@@ -255,113 +255,113 @@ Basic Operations
 Higher Math Functions
 =====================
 
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| <Func>    | <Func_f> (float) | <Func> (double) | <Func_l> (long double) | <Func_f16> (float16) | <Func_f128> (float128) | C23 Definition Section | C23 Error Handling Section |
-+===========+==================+=================+========================+======================+========================+========================+============================+
-| acos      | |check|          | |check|         |                        | |check|              |                        | 7.12.4.1               | F.10.1.1                   |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| acosh     | |check|          |                 |                        | |check|              |                        | 7.12.5.1               | F.10.2.1                   |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| acospi    |                  |                 |                        | |check|              |                        | 7.12.4.8               | F.10.1.8                   |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| asin      | |check|          | |check|         |                        | |check|              |                        | 7.12.4.2               | F.10.1.2                   |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| asinh     | |check|          |                 |                        | |check|              |                        | 7.12.5.2               | F.10.2.2                   |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| asinpi    |                  |                 |                        | |check|              |                        | 7.12.4.9               | F.10.1.9                   |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| atan      | |check|          | 1 ULP           |                        | |check|              |                        | 7.12.4.3               | F.10.1.3                   |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| atan2     | |check|          | 1 ULP           |                        |                      | 1 ULP                  | 7.12.4.4               | F.10.1.4                   |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| atan2pi   |                  |                 |                        |                      |                        | 7.12.4.11              | F.10.1.11                  |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| atanh     | |check|          |                 |                        | |check|              |                        | 7.12.5.3               | F.10.2.3                   |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| atanpi    |                  |                 |                        |                      |                        | 7.12.4.10              | F.10.1.10                  |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| cbrt      | |check|          | |check|         |                        |                      |                        | 7.12.7.1               | F.10.4.1                   |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| compoundn |                  |                 |                        |                      |                        | 7.12.7.2               | F.10.4.2                   |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| cos       | |check|          | |check|         |                        | |check|              |                        | 7.12.4.5               | F.10.1.5                   |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| cosh      | |check|          |                 |                        | |check|              |                        | 7.12.5.4               | F.10.2.4                   |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| cospi     | |check|          |                 |                        | |check|              |                        | 7.12.4.12              | F.10.1.12                  |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| dsqrt     | N/A              | N/A             |   |check|              | N/A                  |       |check|\*        | 7.12.14.6              | F.10.11                    |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| erf       | |check|          |                 |                        |                      |                        | 7.12.8.1               | F.10.5.1                   |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| erfc      |                  |                 |                        |                      |                        | 7.12.8.2               | F.10.5.2                   |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| exp       | |check|          | |check|         |                        | |check|              |                        | 7.12.6.1               | F.10.3.1                   |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| exp10     | |check|          | |check|         |                        | |check|              |                        | 7.12.6.2               | F.10.3.2                   |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| exp10m1   | |check|          |                 |                        | |check|              |                        | 7.12.6.3               | F.10.3.3                   |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| exp2      | |check|          | |check|         |                        | |check|              |                        | 7.12.6.4               | F.10.3.4                   |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| exp2m1    | |check|          |                 |                        | |check|              |                        | 7.12.6.5               | F.10.3.5                   |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| expm1     | |check|          | |check|         |                        | |check|              |                        | 7.12.6.6               | F.10.3.6                   |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| fma       | |check|          | |check|         |                        | |check|              |                        | 7.12.13.1              | F.10.10.1                  |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| f16sqrt   | |check|\*        | |check|\*       | |check|\*              | N/A                  | |check|                | 7.12.14.6              | F.10.11                    |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| fsqrt     | N/A              | |check|         |  |check|               | N/A                  | |check|\*              | 7.12.14.6              | F.10.11                    |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| hypot     | |check|          | |check|         |                        | |check|              |                        | 7.12.7.4               | F.10.4.4                   |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| lgamma    |                  |                 |                        |                      |                        | 7.12.8.3               | F.10.5.3                   |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| log       | |check|          | |check|         |                        | |check|              |                        | 7.12.6.11              | F.10.3.11                  |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| log10     | |check|          | |check|         |                        | |check|              |                        | 7.12.6.12              | F.10.3.12                  |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| log10p1   |                  |                 |                        |                      |                        | 7.12.6.13              | F.10.3.13                  |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| log1p     | |check|          | |check|         |                        |                      |                        | 7.12.6.14              | F.10.3.14                  |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| log2      | |check|          | |check|         |                        | |check|              |                        | 7.12.6.15              | F.10.3.15                  |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| log2p1    |                  |                 |                        |                      |                        | 7.12.6.16              | F.10.3.16                  |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| logp1     |                  |                 |                        |                      |                        | 7.12.6.14              | F.10.3.14                  |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| pow       | |check|          | 1 ULP           |                        |                      |                        | 7.12.7.5               | F.10.4.5                   |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| powi\*    |                  |                 |              ...
[truncated]

``````````

</details>


https://github.com/llvm/llvm-project/pull/156654


More information about the libc-commits mailing list