Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[libc][math] Add C23 math function fabsf128. #77825

Merged
merged 2 commits into from Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions libc/config/linux/aarch64/entrypoints.txt
Expand Up @@ -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
Expand Down Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should copysign be a distinct commit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

libc.src.math.fabsf128
)
endif()

if(LLVM_LIBC_FULL_BUILD)
list(APPEND TARGET_LIBC_ENTRYPOINTS
# compiler entrypoints (no corresponding header)
Expand Down
1 change: 1 addition & 0 deletions libc/config/linux/x86_64/entrypoints.txt
Expand Up @@ -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()

Expand Down
2 changes: 2 additions & 0 deletions libc/docs/math/index.rst
Expand Up @@ -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| | | | |
Expand Down
1 change: 1 addition & 0 deletions libc/spec/stdc.td
Expand Up @@ -367,6 +367,7 @@ def StdC : StandardSpec<"stdc"> {
FunctionSpec<"fabs", RetValSpec<DoubleType>, [ArgSpec<DoubleType>]>,
FunctionSpec<"fabsf", RetValSpec<FloatType>, [ArgSpec<FloatType>]>,
FunctionSpec<"fabsl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>]>,
FunctionSpec<"fabsf128", RetValSpec<Float128Type>, [ArgSpec<Float128Type>]>,

FunctionSpec<"fdim", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>]>,
FunctionSpec<"fdimf", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<FloatType>]>,
Expand Down
1 change: 1 addition & 0 deletions libc/src/math/CMakeLists.txt
Expand Up @@ -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)
Expand Down
20 changes: 20 additions & 0 deletions 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
12 changes: 12 additions & 0 deletions libc/src/math/generic/CMakeLists.txt
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions 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
16 changes: 16 additions & 0 deletions libc/test/src/math/smoke/CMakeLists.txt
Expand Up @@ -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
Expand All @@ -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(
Expand Down
13 changes: 13 additions & 0 deletions 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)