From efb2cfae39e13566c93865456a329b0e9d17c411 Mon Sep 17 00:00:00 2001 From: Tue Ly Date: Thu, 11 Jan 2024 20:09:52 +0000 Subject: [PATCH 1/2] [libc][math] Add C23 math function fabsf128. --- libc/config/linux/aarch64/entrypoints.txt | 9 +++++++++ libc/config/linux/x86_64/entrypoints.txt | 1 + libc/docs/math/index.rst | 2 ++ libc/spec/stdc.td | 1 + libc/src/math/CMakeLists.txt | 1 + libc/src/math/fabsf128.h | 20 ++++++++++++++++++++ libc/src/math/generic/CMakeLists.txt | 12 ++++++++++++ libc/src/math/generic/fabsf128.cpp | 17 +++++++++++++++++ libc/test/src/math/smoke/CMakeLists.txt | 16 ++++++++++++++++ libc/test/src/math/smoke/fabsf128_test.cpp | 13 +++++++++++++ 10 files changed, 92 insertions(+) create mode 100644 libc/src/math/fabsf128.h create mode 100644 libc/src/math/generic/fabsf128.cpp create mode 100644 libc/test/src/math/smoke/fabsf128_test.cpp diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt index ce3f5eb40e38a..81a6217ba680d 100644 --- a/libc/config/linux/aarch64/entrypoints.txt +++ b/libc/config/linux/aarch64/entrypoints.txt @@ -260,6 +260,7 @@ set(TARGET_LIBM_ENTRYPOINTS libc.src.math.fabs libc.src.math.fabsf libc.src.math.fabsl + libc.src.math.fabs128 libc.src.math.fdim libc.src.math.fdimf libc.src.math.fdiml @@ -354,6 +355,14 @@ set(TARGET_LIBM_ENTRYPOINTS libc.src.math.truncl ) +if(LIBC_COMPILER_HAS_FLOAT128) + list(APPEND TARGET_LIBM_ENTRYPOINTS + # math.h C23 _Float128 entrypoints + libc.src.math.copysignf128 + libc.src.math.fabsf128 + ) +endif() + if(LLVM_LIBC_FULL_BUILD) list(APPEND TARGET_LIBC_ENTRYPOINTS # compiler entrypoints (no corresponding header) diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt index 30900de365bf9..094bdde2e1589 100644 --- a/libc/config/linux/x86_64/entrypoints.txt +++ b/libc/config/linux/x86_64/entrypoints.txt @@ -370,6 +370,7 @@ if(LIBC_COMPILER_HAS_FLOAT128) list(APPEND TARGET_LIBM_ENTRYPOINTS # math.h C23 _Float128 entrypoints libc.src.math.copysignf128 + libc.src.math.fabsf128 ) endif() diff --git a/libc/docs/math/index.rst b/libc/docs/math/index.rst index 3668524af03c2..724ad19dbe442 100644 --- a/libc/docs/math/index.rst +++ b/libc/docs/math/index.rst @@ -128,6 +128,8 @@ Basic Operations +--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+ | fabsl | |check| | |check| | |check| | |check| | |check| | | | |check| | |check| | | | | +--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+ +| fabsf128 | |check| | |check| | | | | | | | | | | | ++--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+ | fdim | |check| | |check| | |check| | |check| | |check| | | | |check| | |check| | | | | +--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+ | fdimf | |check| | |check| | |check| | |check| | |check| | | | |check| | |check| | | | | diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td index 78095eb23f071..714dc21f95ba5 100644 --- a/libc/spec/stdc.td +++ b/libc/spec/stdc.td @@ -367,6 +367,7 @@ def StdC : StandardSpec<"stdc"> { FunctionSpec<"fabs", RetValSpec, [ArgSpec]>, FunctionSpec<"fabsf", RetValSpec, [ArgSpec]>, FunctionSpec<"fabsl", RetValSpec, [ArgSpec]>, + FunctionSpec<"fabsf128", RetValSpec, [ArgSpec]>, FunctionSpec<"fdim", RetValSpec, [ArgSpec, ArgSpec]>, FunctionSpec<"fdimf", RetValSpec, [ArgSpec, ArgSpec]>, diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt index e2b1026fcad7e..a8d3fbd475f07 100644 --- a/libc/src/math/CMakeLists.txt +++ b/libc/src/math/CMakeLists.txt @@ -105,6 +105,7 @@ add_math_entrypoint_object(expm1f) add_math_entrypoint_object(fabs) add_math_entrypoint_object(fabsf) add_math_entrypoint_object(fabsl) +add_math_entrypoint_object(fabsf128) add_math_entrypoint_object(fdim) add_math_entrypoint_object(fdimf) diff --git a/libc/src/math/fabsf128.h b/libc/src/math/fabsf128.h new file mode 100644 index 0000000000000..5999757decfda --- /dev/null +++ b/libc/src/math/fabsf128.h @@ -0,0 +1,20 @@ +//===-- Implementation header for fabsf128 ----------------------*- 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_FABSF128_H +#define LLVM_LIBC_SRC_MATH_FABSF128_H + +#include "src/__support/macros/properties/float.h" + +namespace LIBC_NAMESPACE { + +float128 fabsf128(float128 x); + +} // namespace LIBC_NAMESPACE + +#endif // LLVM_LIBC_SRC_MATH_FABSF128_H diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt index eeb09652961fd..887a8e6038a49 100644 --- a/libc/src/math/generic/CMakeLists.txt +++ b/libc/src/math/generic/CMakeLists.txt @@ -196,6 +196,18 @@ add_entrypoint_object( -O2 ) +add_entrypoint_object( + fabsf128 + SRCS + fabsf128.cpp + HDRS + ../fabsf128.h + DEPENDS + libc.src.__support.FPUtil.basic_operations + COMPILE_OPTIONS + -O3 +) + add_entrypoint_object( trunc SRCS diff --git a/libc/src/math/generic/fabsf128.cpp b/libc/src/math/generic/fabsf128.cpp new file mode 100644 index 0000000000000..615b13f862399 --- /dev/null +++ b/libc/src/math/generic/fabsf128.cpp @@ -0,0 +1,17 @@ +//===-- Implementation of fabsf128 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/fabsf128.h" +#include "src/__support/FPUtil/BasicOperations.h" +#include "src/__support/common.h" + +namespace LIBC_NAMESPACE { + +LLVM_LIBC_FUNCTION(float128, fabsf128, (float128 x)) { return fputil::abs(x); } + +} // namespace LIBC_NAMESPACE diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt index 87b72e2a8eca2..163fa924b243a 100644 --- a/libc/test/src/math/smoke/CMakeLists.txt +++ b/libc/test/src/math/smoke/CMakeLists.txt @@ -87,6 +87,8 @@ add_fp_unittest( add_fp_unittest( fabsl_test + # FIXME: Currently fails on the GPU build. + UNIT_TEST_ONLY SUITE libc-math-smoke-tests SRCS @@ -97,8 +99,22 @@ add_fp_unittest( libc.include.math libc.src.math.fabsl libc.src.__support.FPUtil.fp_bits +) + +add_fp_unittest( + fabsf128_test # FIXME: Currently fails on the GPU build. UNIT_TEST_ONLY + SUITE + libc-math-smoke-tests + SRCS + fabsf128_test.cpp + HDRS + FAbsTest.h + DEPENDS + libc.include.math + libc.src.math.fabsf128 + libc.src.__support.FPUtil.fp_bits ) add_fp_unittest( diff --git a/libc/test/src/math/smoke/fabsf128_test.cpp b/libc/test/src/math/smoke/fabsf128_test.cpp new file mode 100644 index 0000000000000..9807179efa990 --- /dev/null +++ b/libc/test/src/math/smoke/fabsf128_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for fabsf128 --------------------------------------------===// +// +// 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 "FAbsTest.h" + +#include "src/math/fabsf128.h" + +LIST_FABS_TESTS(float128, LIBC_NAMESPACE::fabsf128) From 8753422f6def05d34468bb91c095a8803f8cbc3c Mon Sep 17 00:00:00 2001 From: Tue Ly Date: Fri, 12 Jan 2024 16:08:43 +0000 Subject: [PATCH 2/2] Move copysignf128 for aarch64 to another patch. --- libc/config/linux/aarch64/entrypoints.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt index 81a6217ba680d..0148e76d65380 100644 --- a/libc/config/linux/aarch64/entrypoints.txt +++ b/libc/config/linux/aarch64/entrypoints.txt @@ -358,7 +358,6 @@ set(TARGET_LIBM_ENTRYPOINTS if(LIBC_COMPILER_HAS_FLOAT128) list(APPEND TARGET_LIBM_ENTRYPOINTS # math.h C23 _Float128 entrypoints - libc.src.math.copysignf128 libc.src.math.fabsf128 ) endif()