diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt index d5ab891674a2d8..a1486ac689812b 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 49593dfe01c810..e28b8e87988441 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 ================================= -============== ================ =============== ====================== - (float) (double) (long double) -============== ================ =============== ====================== +============== ================ =============== ====================== ====================== + (float) (double) (long double) (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 99e9b3ca65ca59..8c2feba23adbf3 100644 --- a/libc/spec/stdc.td +++ b/libc/spec/stdc.td @@ -480,6 +480,7 @@ def StdC : StandardSpec<"stdc"> { FunctionSpec<"sqrt", RetValSpec, [ArgSpec]>, FunctionSpec<"sqrtf", RetValSpec, [ArgSpec]>, FunctionSpec<"sqrtl", RetValSpec, [ArgSpec]>, + FunctionSpec<"sqrtf128", RetValSpec, [ArgSpec]>, FunctionSpec<"trunc", RetValSpec, [ArgSpec]>, FunctionSpec<"truncf", RetValSpec, [ArgSpec]>, diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt index a8d3fbd475f07f..3097c4b3a82cc4 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 887a8e6038a49d..8b32a3296bb87f 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 00000000000000..0196c3e0a96ae5 --- /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 00000000000000..bccb6bbb6332da --- /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 163fa924b243ac..03526e019c3e9f 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 00000000000000..edba114adf06cf --- /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) 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 00000000000000..23397b0623ce53 --- /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)