Skip to content

Commit

Permalink
[libc][math] Add C23 math function fabsf128. (#77825)
Browse files Browse the repository at this point in the history
  • Loading branch information
lntue committed Jan 12, 2024
1 parent 8cd9561 commit 1048b59
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 0 deletions.
8 changes: 8 additions & 0 deletions libc/config/linux/aarch64/entrypoints.txt
Original file line number Diff line number Diff line change
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,13 @@ 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.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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 1048b59

Please sign in to comment.