[libc-commits] [libc] 777eb35 - [libc] Add sqrtf128 implementation for Linux x86_64. (#79195)

via libc-commits libc-commits at lists.llvm.org
Wed Jan 24 07:16:16 PST 2024


Author: felixh5678
Date: 2024-01-24T10:16:12-05:00
New Revision: 777eb35614eff30f8fe8ca7729b9c04846a09476

URL: https://github.com/llvm/llvm-project/commit/777eb35614eff30f8fe8ca7729b9c04846a09476
DIFF: https://github.com/llvm/llvm-project/commit/777eb35614eff30f8fe8ca7729b9c04846a09476.diff

LOG: [libc] Add sqrtf128 implementation for Linux x86_64. (#79195)

Co-authored-by: Tue Ly <lntue at google.com>
Co-authored-by: Felix <felix at Dirks-MacBook-Pro.local>

Added: 
    libc/src/math/generic/sqrtf128.cpp
    libc/src/math/sqrtf128.h
    libc/test/src/math/smoke/generic_sqrtf128_test.cpp
    libc/test/src/math/smoke/sqrtf128_test.cpp

Modified: 
    libc/config/linux/x86_64/entrypoints.txt
    libc/docs/math/index.rst
    libc/spec/stdc.td
    libc/src/math/CMakeLists.txt
    libc/src/math/generic/CMakeLists.txt
    libc/test/src/math/smoke/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index d5ab891674a2d86..a1486ac689812b4 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -374,6 +374,7 @@ if(LIBC_COMPILER_HAS_FLOAT128)
     # math.h C23 _Float128 entrypoints
     libc.src.math.copysignf128
     libc.src.math.fabsf128
+    libc.src.math.sqrtf128
   )
 endif()
 

diff  --git a/libc/docs/math/index.rst b/libc/docs/math/index.rst
index 49593dfe01c810c..e28b8e87988441a 100644
--- a/libc/docs/math/index.rst
+++ b/libc/docs/math/index.rst
@@ -452,6 +452,8 @@ Higher Math Functions
 +------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
 | sqrtl      | |check| | |check| | |check| | |check| | |check| |         |         | |check| | |check| | |check| |         |         |
 +------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
+| sqrtf128   | |check| |         |         |         |         |         |         |         |         |         |         |         |
++------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
 | tan        | |check| |         |         |         |         |         |         |         |         |         |         |         |
 +------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
 | tanf       | |check| | |check| | |check| | |check| | |check| |         |         | |check| | |check| | |check| |         |         |
@@ -475,9 +477,9 @@ Higher Math Functions
 Accuracy of Higher Math Functions
 =================================
 
-============== ================ =============== ======================
-<Func>         <Func_f> (float) <Func> (double) <Func_l> (long double)
-============== ================ =============== ======================
+============== ================ =============== ====================== ======================
+<Func>         <Func_f> (float) <Func> (double) <Func_l> (long double) <Func_f128> (float128)
+============== ================ =============== ====================== ======================
 acos           |check|
 acosh          |check|
 asin           |check|
@@ -501,10 +503,10 @@ pow            |check|
 sin            |check|          large
 sincos         |check|          large
 sinh           |check|
-sqrt           |check|          |check|         |check|
+sqrt           |check|          |check|         |check|                |check|
 tan            |check|
 tanh           |check|
-============== ================ =============== ======================
+============== ================ =============== ====================== ======================
 
 
 Legends:

diff  --git a/libc/spec/stdc.td b/libc/spec/stdc.td
index 99e9b3ca65ca59b..8c2feba23adbf3a 100644
--- a/libc/spec/stdc.td
+++ b/libc/spec/stdc.td
@@ -480,6 +480,7 @@ def StdC : StandardSpec<"stdc"> {
           FunctionSpec<"sqrt", RetValSpec<DoubleType>, [ArgSpec<DoubleType>]>,
           FunctionSpec<"sqrtf", RetValSpec<FloatType>, [ArgSpec<FloatType>]>,
           FunctionSpec<"sqrtl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>]>,
+          FunctionSpec<"sqrtf128", RetValSpec<Float128Type>, [ArgSpec<Float128Type>]>, 
 
           FunctionSpec<"trunc", RetValSpec<DoubleType>, [ArgSpec<DoubleType>]>,
           FunctionSpec<"truncf", RetValSpec<FloatType>, [ArgSpec<FloatType>]>,

diff  --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index a8d3fbd475f07f7..3097c4b3a82cc48 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -231,6 +231,7 @@ add_math_entrypoint_object(sinhf)
 add_math_entrypoint_object(sqrt)
 add_math_entrypoint_object(sqrtf)
 add_math_entrypoint_object(sqrtl)
+add_math_entrypoint_object(sqrtf128)
 
 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 887a8e6038a49d3..8b32a3296bb87f6 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -1315,6 +1315,18 @@ add_entrypoint_object(
     -O3
 )
 
+add_entrypoint_object(
+  sqrtf128
+  SRCS
+    sqrtf128.cpp
+  HDRS
+    ../sqrtf128.h
+  DEPENDS
+    libc.src.__support.FPUtil.sqrt 
+  COMPILE_OPTIONS
+    -O3
+  )
+
 add_entrypoint_object(
   remquof
   SRCS

diff  --git a/libc/src/math/generic/sqrtf128.cpp b/libc/src/math/generic/sqrtf128.cpp
new file mode 100644
index 000000000000000..0196c3e0a96ae5e
--- /dev/null
+++ b/libc/src/math/generic/sqrtf128.cpp
@@ -0,0 +1,17 @@
+//===-- Implementation of sqrtf128 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/sqrtf128.h"
+#include "src/__support/FPUtil/sqrt.h"
+#include "src/__support/common.h"
+
+namespace LIBC_NAMESPACE {
+
+LLVM_LIBC_FUNCTION(float128, sqrtf128, (float128 x)) { return fputil::sqrt(x); }
+
+} // namespace LIBC_NAMESPACE

diff  --git a/libc/src/math/sqrtf128.h b/libc/src/math/sqrtf128.h
new file mode 100644
index 000000000000000..bccb6bbb6332dae
--- /dev/null
+++ b/libc/src/math/sqrtf128.h
@@ -0,0 +1,20 @@
+//===-- Implementation header for sqrtf128 ----------------------*- 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_SQRTF128_H
+#define LLVM_LIBC_SRC_MATH_SQRTF128_H
+
+#include "src/__support/macros/properties/float.h"
+
+namespace LIBC_NAMESPACE {
+
+float128 sqrtf128(float128 x);
+
+} // namespace LIBC_NAMESPACE
+
+#endif // LLVM_LIBC_SRC_MATH_SQRTF128_H

diff  --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index 163fa924b243ac9..03526e019c3e9ff 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -1102,6 +1102,20 @@ add_fp_unittest(
   UNIT_TEST_ONLY
 )
 
+add_fp_unittest(
+  sqrtf128_test
+  SUITE
+    libc-math-smoke-tests
+  SRCS
+    sqrtf128_test.cpp
+  DEPENDS
+    libc.include.math
+    libc.src.math.sqrtf128
+    libc.src.__support.FPUtil.fp_bits
+  # FIXME: Currently fails on the GPU build.
+  UNIT_TEST_ONLY
+)
+
 add_fp_unittest(
   generic_sqrtf_test
   SUITE
@@ -1150,6 +1164,22 @@ add_fp_unittest(
   UNIT_TEST_ONLY
 )
 
+add_fp_unittest(
+  generic_sqrtf128_test
+  SUITE
+    libc-math-smoke-tests
+  SRCS
+    generic_sqrtf128_test.cpp
+  DEPENDS
+    libc.src.math.sqrtf128
+    libc.src.__support.FPUtil.fp_bits
+    libc.src.__support.FPUtil.generic.sqrt
+  COMPILE_OPTIONS
+    -O3
+  # FIXME: Currently fails on the GPU build.
+  UNIT_TEST_ONLY
+)
+
 add_fp_unittest(
   remquof_test
   SUITE

diff  --git a/libc/test/src/math/smoke/generic_sqrtf128_test.cpp b/libc/test/src/math/smoke/generic_sqrtf128_test.cpp
new file mode 100644
index 000000000000000..edba114adf06cf3
--- /dev/null
+++ b/libc/test/src/math/smoke/generic_sqrtf128_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for generic implementation of sqrtf128-------------------===//
+//
+// 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/generic/sqrt.h"
+
+LIST_SQRT_TESTS(float128, LIBC_NAMESPACE::fputil::sqrt<float128>)

diff  --git a/libc/test/src/math/smoke/sqrtf128_test.cpp b/libc/test/src/math/smoke/sqrtf128_test.cpp
new file mode 100644
index 000000000000000..23397b0623ce53d
--- /dev/null
+++ b/libc/test/src/math/smoke/sqrtf128_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for sqrtf128---------------------------------------------===//
+//
+// 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/math/sqrtf128.h"
+
+LIST_SQRT_TESTS(float128, LIBC_NAMESPACE::sqrtf128)


        


More information about the libc-commits mailing list