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

via libc-commits libc-commits at lists.llvm.org
Sat Sep 6 02:06:06 PDT 2025


Author: Krishna Pandey
Date: 2025-09-06T14:36:02+05:30
New Revision: 8dda18f83611803588c470be5e2c3c1203d3ae2b

URL: https://github.com/llvm/llvm-project/commit/8dda18f83611803588c470be5e2c3c1203d3ae2b
DIFF: https://github.com/llvm/llvm-project/commit/8dda18f83611803588c470be5e2c3c1203d3ae2b.diff

LOG: [libc][math][c++23] Add sqrtbf16 math function (#156654)

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

---------

Signed-off-by: Krishna Pandey <kpandey81930 at gmail.com>

Added: 
    libc/src/math/generic/sqrtbf16.cpp
    libc/src/math/sqrtbf16.h
    libc/test/src/math/smoke/sqrtbf16_test.cpp
    libc/test/src/math/sqrtbf16_test.cpp

Modified: 
    libc/config/baremetal/aarch64/entrypoints.txt
    libc/config/baremetal/arm/entrypoints.txt
    libc/config/baremetal/riscv/entrypoints.txt
    libc/config/darwin/aarch64/entrypoints.txt
    libc/config/darwin/x86_64/entrypoints.txt
    libc/config/gpu/amdgpu/entrypoints.txt
    libc/config/gpu/nvptx/entrypoints.txt
    libc/config/linux/aarch64/entrypoints.txt
    libc/config/linux/arm/entrypoints.txt
    libc/config/linux/riscv/entrypoints.txt
    libc/config/linux/x86_64/entrypoints.txt
    libc/config/windows/entrypoints.txt
    libc/docs/headers/math/index.rst
    libc/src/math/CMakeLists.txt
    libc/src/math/generic/CMakeLists.txt
    libc/test/src/math/CMakeLists.txt
    libc/test/src/math/smoke/CMakeLists.txt
    libc/utils/MPFRWrapper/MPFRUtils.cpp

Removed: 
    


################################################################################
diff  --git a/libc/config/baremetal/aarch64/entrypoints.txt b/libc/config/baremetal/aarch64/entrypoints.txt
index cacecf08042e0..685a80b4002a3 100644
--- a/libc/config/baremetal/aarch64/entrypoints.txt
+++ b/libc/config/baremetal/aarch64/entrypoints.txt
@@ -822,6 +822,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.scalbnbf16
   libc.src.math.setpayloadbf16
   libc.src.math.setpayloadsigbf16
+  libc.src.math.sqrtbf16
   libc.src.math.truncbf16
   libc.src.math.totalorderbf16
   libc.src.math.totalordermagbf16

diff  --git a/libc/config/baremetal/arm/entrypoints.txt b/libc/config/baremetal/arm/entrypoints.txt
index f112c2b36fdf3..8ec972fc58411 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -822,6 +822,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.scalbnbf16
   libc.src.math.setpayloadbf16
   libc.src.math.setpayloadsigbf16
+  libc.src.math.sqrtbf16
   libc.src.math.truncbf16
   libc.src.math.totalorderbf16
   libc.src.math.totalordermagbf16

diff  --git a/libc/config/baremetal/riscv/entrypoints.txt b/libc/config/baremetal/riscv/entrypoints.txt
index 53e5914b9ec32..2f1d930497734 100644
--- a/libc/config/baremetal/riscv/entrypoints.txt
+++ b/libc/config/baremetal/riscv/entrypoints.txt
@@ -822,6 +822,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.scalbnbf16
   libc.src.math.setpayloadbf16
   libc.src.math.setpayloadsigbf16
+  libc.src.math.sqrtbf16
   libc.src.math.truncbf16
   libc.src.math.totalorderbf16
   libc.src.math.totalordermagbf16

diff  --git a/libc/config/darwin/aarch64/entrypoints.txt b/libc/config/darwin/aarch64/entrypoints.txt
index b4e210ad3ae0b..3af3f7ff66874 100644
--- a/libc/config/darwin/aarch64/entrypoints.txt
+++ b/libc/config/darwin/aarch64/entrypoints.txt
@@ -652,6 +652,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.scalbnbf16
   libc.src.math.setpayloadbf16
   libc.src.math.setpayloadsigbf16
+  libc.src.math.sqrtbf16
   libc.src.math.truncbf16
   libc.src.math.totalorderbf16
   libc.src.math.totalordermagbf16

diff  --git a/libc/config/darwin/x86_64/entrypoints.txt b/libc/config/darwin/x86_64/entrypoints.txt
index 95392f7718849..a0881e5b02fe8 100644
--- a/libc/config/darwin/x86_64/entrypoints.txt
+++ b/libc/config/darwin/x86_64/entrypoints.txt
@@ -295,6 +295,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.scalbnbf16
   libc.src.math.setpayloadbf16
   libc.src.math.setpayloadsigbf16
+  libc.src.math.sqrtbf16
   libc.src.math.truncbf16
   libc.src.math.totalorderbf16
   libc.src.math.totalordermagbf16

diff  --git a/libc/config/gpu/amdgpu/entrypoints.txt b/libc/config/gpu/amdgpu/entrypoints.txt
index 737d1bb3ac61c..7e4b1ab6d253f 100644
--- a/libc/config/gpu/amdgpu/entrypoints.txt
+++ b/libc/config/gpu/amdgpu/entrypoints.txt
@@ -678,6 +678,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.scalbnbf16
   libc.src.math.setpayloadbf16
   libc.src.math.setpayloadsigbf16
+  libc.src.math.sqrtbf16
   libc.src.math.truncbf16
   libc.src.math.totalorderbf16
   libc.src.math.totalordermagbf16

diff  --git a/libc/config/gpu/nvptx/entrypoints.txt b/libc/config/gpu/nvptx/entrypoints.txt
index c06d63576bbd3..72a6257283475 100644
--- a/libc/config/gpu/nvptx/entrypoints.txt
+++ b/libc/config/gpu/nvptx/entrypoints.txt
@@ -680,6 +680,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.scalbnbf16
   libc.src.math.setpayloadbf16
   libc.src.math.setpayloadsigbf16
+  libc.src.math.sqrtbf16
   libc.src.math.truncbf16
   libc.src.math.totalorderbf16
   libc.src.math.totalordermagbf16

diff  --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 9aeb6a7361cd5..840d4cec14bbf 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -907,6 +907,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.scalbnbf16
   libc.src.math.setpayloadbf16
   libc.src.math.setpayloadsigbf16
+  libc.src.math.sqrtbf16
   libc.src.math.truncbf16
   libc.src.math.totalorderbf16
   libc.src.math.totalordermagbf16

diff  --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt
index 591c57d479dc2..97857986d3874 100644
--- a/libc/config/linux/arm/entrypoints.txt
+++ b/libc/config/linux/arm/entrypoints.txt
@@ -522,6 +522,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.scalbnbf16
   libc.src.math.setpayloadbf16
   libc.src.math.setpayloadsigbf16
+  libc.src.math.sqrtbf16
   libc.src.math.truncbf16
   libc.src.math.totalorderbf16
   libc.src.math.totalordermagbf16

diff  --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index b2cd511506607..653282c7d3935 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -925,6 +925,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.scalbnbf16
   libc.src.math.setpayloadbf16
   libc.src.math.setpayloadsigbf16
+  libc.src.math.sqrtbf16
   libc.src.math.truncbf16
   libc.src.math.totalorderbf16
   libc.src.math.totalordermagbf16

diff  --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 35425eb32c795..1fef16f190af6 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -960,6 +960,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.scalbnbf16
   libc.src.math.setpayloadbf16
   libc.src.math.setpayloadsigbf16
+  libc.src.math.sqrtbf16
   libc.src.math.truncbf16
   libc.src.math.totalorderbf16
   libc.src.math.totalordermagbf16

diff  --git a/libc/config/windows/entrypoints.txt b/libc/config/windows/entrypoints.txt
index 2da48c32d0af3..b7e6f7be128c4 100644
--- a/libc/config/windows/entrypoints.txt
+++ b/libc/config/windows/entrypoints.txt
@@ -368,6 +368,7 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS
   libc.src.math.scalbnbf16
   libc.src.math.setpayloadbf16
   libc.src.math.setpayloadsigbf16
+  libc.src.math.sqrtbf16
   libc.src.math.truncbf16
   libc.src.math.totalorderbf16
   libc.src.math.totalordermagbf16

diff  --git a/libc/docs/headers/math/index.rst b/libc/docs/headers/math/index.rst
index ae5fe78d038ee..6c0e2190808df 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    |                  |                 |                        | |check|              |                        | 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\*    |                  |                 |                        |                      |                        |                        |                            |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| pown      |                  |                 |                        |                      |                        | 7.12.7.6               | F.10.4.6                   |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| powr      |                  |                 |                        |                      |                        | 7.12.7.7               | F.10.4.7                   |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| rootn     |                  |                 |                        |                      |                        | 7.12.7.8               | F.10.4.8                   |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| rsqrt     |                  |                 |                        |                      |                        | 7.12.7.9               | F.10.4.9                   |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| sin       | |check|          | |check|         |                        | |check|              |                        | 7.12.4.6               | F.10.1.6                   |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| sincos    | |check|          | |check|         |                        |                      |                        |                        |                            |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| sinh      | |check|          |                 |                        | |check|              |                        | 7.12.5.5               | F.10.2.5                   |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| sinpi     | |check|          |                 |                        |  |check|             |                        | 7.12.4.13              | F.10.1.13                  |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| sqrt      | |check|          | |check|         | |check|                | |check|              | |check|                | 7.12.7.10              | F.10.4.10                  |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| tan       | |check|          | |check|         |                        | |check|              |                        | 7.12.4.7               | F.10.1.7                   |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| tanh      | |check|          |                 |                        | |check|              |                        | 7.12.5.6               | F.10.2.6                   |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| tanpi     | |check|          |                 |                        | |check|              |                        | 7.12.4.14              | F.10.1.14                  |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| tgamma    |                  |                 |                        |                      |                        | 7.12.8.4               | F.10.5.4                   |
-+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
++-----------+------------------+-----------------+------------------------+----------------------+------------------------+----------++------------+------------------------+----------------------------+
+| <Func>    | <Func_f> (float) | <Func> (double) | <Func_l> (long double) | <Func_f16> (float16) | <Func_f128> (float128) | <Func_bf16> (bfloat16) | 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    |                  |                 |                        | |check|              |                        |                        | 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\*    |                  |                 |                        |                      |                        |                        |                        |                            |
++-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
+| pown      |                  |                 |                        |                      |                        |                        | 7.12.7.6               | F.10.4.6                   |
++-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
+| powr      |                  |                 |                        |                      |                        |                        | 7.12.7.7               | F.10.4.7                   |
++-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
+| rootn     |                  |                 |                        |                      |                        |                        | 7.12.7.8               | F.10.4.8                   |
++-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
+| rsqrt     |                  |                 |                        |                      |                        |                        | 7.12.7.9               | F.10.4.9                   |
++-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
+| sin       | |check|          | |check|         |                        | |check|              |                        |                        | 7.12.4.6               | F.10.1.6                   |
++-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
+| sincos    | |check|          | |check|         |                        |                      |                        |                        |                        |                            |
++-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
+| sinh      | |check|          |                 |                        | |check|              |                        |                        | 7.12.5.5               | F.10.2.5                   |
++-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
+| sinpi     | |check|          |                 |                        |  |check|             |                        |                        | 7.12.4.13              | F.10.1.13                  |
++-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
+| sqrt      | |check|          | |check|         | |check|                | |check|              | |check|                | |check|                | 7.12.7.10              | F.10.4.10                  |
++-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
+| tan       | |check|          | |check|         |                        | |check|              |                        |                        | 7.12.4.7               | F.10.1.7                   |
++-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
+| tanh      | |check|          |                 |                        | |check|              |                        |                        | 7.12.5.6               | F.10.2.6                   |
++-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
+| tanpi     | |check|          |                 |                        | |check|              |                        |                        | 7.12.4.14              | F.10.1.14                  |
++-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
+| tgamma    |                  |                 |                        |                      |                        |                        | 7.12.8.4               | F.10.5.4                   |
++-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
 
 Legends:
 

diff  --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index 3e7d9ec03fabc..e418a8b0e24b9 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -562,6 +562,7 @@ add_math_entrypoint_object(sqrtf)
 add_math_entrypoint_object(sqrtl)
 add_math_entrypoint_object(sqrtf16)
 add_math_entrypoint_object(sqrtf128)
+add_math_entrypoint_object(sqrtbf16)
 
 add_math_entrypoint_object(tan)
 add_math_entrypoint_object(tanf)

diff  --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index a1f5de7f740fc..263c5dfd0832b 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -3255,7 +3255,21 @@ add_entrypoint_object(
     libc.src.__support.macros.optimization
     libc.src.__support.macros.properties.types
     libc.src.__support.FPUtil.sqrt
-  )
+)
+
+add_entrypoint_object(
+  sqrtbf16
+  SRCS
+    sqrtbf16.cpp
+  HDRS
+    ../sqrtbf16.h
+  DEPENDS
+    libc.src.__support.common
+    libc.src.__support.FPUtil.bfloat16
+    libc.src.__support.FPUtil.sqrt
+    libc.src.__support.macros.config
+    libc.src.__support.macros.properties.types
+)
 
 add_entrypoint_object(
   remquof

diff  --git a/libc/src/math/generic/sqrtbf16.cpp b/libc/src/math/generic/sqrtbf16.cpp
new file mode 100644
index 0000000000000..061e5522a4d8f
--- /dev/null
+++ b/libc/src/math/generic/sqrtbf16.cpp
@@ -0,0 +1,21 @@
+//===-- Implementation of sqrtbf16 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/sqrtbf16.h"
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/FPUtil/sqrt.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(bfloat16, sqrtbf16, (bfloat16 x)) {
+  return fputil::sqrt<bfloat16>(x);
+}
+
+} // namespace LIBC_NAMESPACE_DECL

diff  --git a/libc/src/math/sqrtbf16.h b/libc/src/math/sqrtbf16.h
new file mode 100644
index 0000000000000..4300e9cab6ad3
--- /dev/null
+++ b/libc/src/math/sqrtbf16.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for sqrtbf16 ----------------------*- 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_SQRTBF16_H
+#define LLVM_LIBC_SRC_MATH_SQRTBF16_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+bfloat16 sqrtbf16(bfloat16 x);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_SQRTBF16_H

diff  --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt
index 4e5563b92c673..945bc259573c2 100644
--- a/libc/test/src/math/CMakeLists.txt
+++ b/libc/test/src/math/CMakeLists.txt
@@ -1705,6 +1705,18 @@ add_fp_unittest(
     libc.src.math.sqrtf128
 )
 
+add_fp_unittest(
+  sqrtbf16_test
+  NEED_MPFR
+  SUITE
+    libc-math-unittests
+  SRCS
+    sqrtbf16_test.cpp
+  DEPENDS
+    libc.src.math.sqrtbf16
+    libc.src.__support.FPUtil.bfloat16
+)
+
 add_fp_unittest(
   generic_sqrtf_test
   NEED_MPFR

diff  --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index 152f38d55ca21..c9cbd8b413967 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -3527,6 +3527,19 @@ add_fp_unittest(
     libc.src.math.sqrtf128
 )
 
+add_fp_unittest(
+  sqrtbf16_test
+  SUITE
+    libc-math-smoke-tests
+  SRCS
+    sqrtbf16_test.cpp
+  HDRS
+    SqrtTest.h
+  DEPENDS
+    libc.src.math.sqrtbf16
+    libc.src.__support.FPUtil.bfloat16
+)
+
 add_fp_unittest(
   generic_sqrtf_test
   SUITE

diff  --git a/libc/test/src/math/smoke/sqrtbf16_test.cpp b/libc/test/src/math/smoke/sqrtbf16_test.cpp
new file mode 100644
index 0000000000000..25629347fee3e
--- /dev/null
+++ b/libc/test/src/math/smoke/sqrtbf16_test.cpp
@@ -0,0 +1,14 @@
+//===-- Unittests for sqrtbf16 --------------------------------------------===//
+//
+// 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 "SqrtTest.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/sqrtbf16.h"
+
+LIST_SQRT_TESTS(bfloat16, LIBC_NAMESPACE::sqrtbf16);

diff  --git a/libc/test/src/math/sqrtbf16_test.cpp b/libc/test/src/math/sqrtbf16_test.cpp
new file mode 100644
index 0000000000000..186ddd5487133
--- /dev/null
+++ b/libc/test/src/math/sqrtbf16_test.cpp
@@ -0,0 +1,29 @@
+//===-- Exhaustive test for sqrtbf16 --------------------------------------===//
+//
+// 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/__support/FPUtil/bfloat16.h"
+#include "src/math/sqrtbf16.h"
+#include "test/UnitTest/FPMatcher.h"
+#include "test/UnitTest/Test.h"
+#include "utils/MPFRWrapper/MPFRUtils.h"
+
+using LlvmLibcSqrtf16Test = LIBC_NAMESPACE::testing::FPTest<bfloat16>;
+
+namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
+
+// range: [0, inf]
+static constexpr uint16_t POS_START = 0x0000U;
+static constexpr uint16_t POS_STOP = 0x7f80U;
+
+TEST_F(LlvmLibcSqrtf16Test, PositiveRange) {
+  for (uint16_t v = POS_START; v <= POS_STOP; ++v) {
+    bfloat16 x = FPBits(v).get_val();
+    EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Sqrt, x,
+                                   LIBC_NAMESPACE::sqrtbf16(x), 0.5);
+  }
+}

diff  --git a/libc/utils/MPFRWrapper/MPFRUtils.cpp b/libc/utils/MPFRWrapper/MPFRUtils.cpp
index ed749f1222a08..144a4ec25d213 100644
--- a/libc/utils/MPFRWrapper/MPFRUtils.cpp
+++ b/libc/utils/MPFRWrapper/MPFRUtils.cpp
@@ -274,6 +274,10 @@ template void explain_unary_operation_single_output_error(Operation op,
                                                           double, RoundingMode);
 #endif // LIBC_TYPES_FLOAT128_IS_NOT_LONG_DOUBLE
 
+template void explain_unary_operation_single_output_error(Operation op,
+                                                          bfloat16, bfloat16,
+                                                          double, RoundingMode);
+
 template <typename T>
 void explain_unary_operation_two_outputs_error(
     Operation op, T input, const BinaryOutput<T> &libc_result,
@@ -561,6 +565,9 @@ template bool compare_unary_operation_single_output(Operation, float128,
                                                     long double, double,
                                                     RoundingMode);
 #endif // LIBC_TYPES_FLOAT128_IS_NOT_LONG_DOUBLE
+template bool compare_unary_operation_single_output(Operation, bfloat16,
+                                                    bfloat16, double,
+                                                    RoundingMode);
 
 template <typename T>
 bool compare_unary_operation_two_outputs(Operation op, T input,


        


More information about the libc-commits mailing list