Skip to content

Commit 1048b59

Browse files
authored
[libc][math] Add C23 math function fabsf128. (#77825)
1 parent 8cd9561 commit 1048b59

File tree

10 files changed

+91
-0
lines changed

10 files changed

+91
-0
lines changed

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ set(TARGET_LIBM_ENTRYPOINTS
260260
libc.src.math.fabs
261261
libc.src.math.fabsf
262262
libc.src.math.fabsl
263+
libc.src.math.fabs128
263264
libc.src.math.fdim
264265
libc.src.math.fdimf
265266
libc.src.math.fdiml
@@ -354,6 +355,13 @@ set(TARGET_LIBM_ENTRYPOINTS
354355
libc.src.math.truncl
355356
)
356357

358+
if(LIBC_COMPILER_HAS_FLOAT128)
359+
list(APPEND TARGET_LIBM_ENTRYPOINTS
360+
# math.h C23 _Float128 entrypoints
361+
libc.src.math.fabsf128
362+
)
363+
endif()
364+
357365
if(LLVM_LIBC_FULL_BUILD)
358366
list(APPEND TARGET_LIBC_ENTRYPOINTS
359367
# compiler entrypoints (no corresponding header)

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ if(LIBC_COMPILER_HAS_FLOAT128)
370370
list(APPEND TARGET_LIBM_ENTRYPOINTS
371371
# math.h C23 _Float128 entrypoints
372372
libc.src.math.copysignf128
373+
libc.src.math.fabsf128
373374
)
374375
endif()
375376

libc/docs/math/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ Basic Operations
128128
+--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
129129
| fabsl | |check| | |check| | |check| | |check| | |check| | | | |check| | |check| | | | |
130130
+--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
131+
| fabsf128 | |check| | |check| | | | | | | | | | | |
132+
+--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
131133
| fdim | |check| | |check| | |check| | |check| | |check| | | | |check| | |check| | | | |
132134
+--------------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
133135
| fdimf | |check| | |check| | |check| | |check| | |check| | | | |check| | |check| | | | |

libc/spec/stdc.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ def StdC : StandardSpec<"stdc"> {
367367
FunctionSpec<"fabs", RetValSpec<DoubleType>, [ArgSpec<DoubleType>]>,
368368
FunctionSpec<"fabsf", RetValSpec<FloatType>, [ArgSpec<FloatType>]>,
369369
FunctionSpec<"fabsl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>]>,
370+
FunctionSpec<"fabsf128", RetValSpec<Float128Type>, [ArgSpec<Float128Type>]>,
370371

371372
FunctionSpec<"fdim", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>]>,
372373
FunctionSpec<"fdimf", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<FloatType>]>,

libc/src/math/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ add_math_entrypoint_object(expm1f)
105105
add_math_entrypoint_object(fabs)
106106
add_math_entrypoint_object(fabsf)
107107
add_math_entrypoint_object(fabsl)
108+
add_math_entrypoint_object(fabsf128)
108109

109110
add_math_entrypoint_object(fdim)
110111
add_math_entrypoint_object(fdimf)

libc/src/math/fabsf128.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===-- Implementation header for fabsf128 ----------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_SRC_MATH_FABSF128_H
10+
#define LLVM_LIBC_SRC_MATH_FABSF128_H
11+
12+
#include "src/__support/macros/properties/float.h"
13+
14+
namespace LIBC_NAMESPACE {
15+
16+
float128 fabsf128(float128 x);
17+
18+
} // namespace LIBC_NAMESPACE
19+
20+
#endif // LLVM_LIBC_SRC_MATH_FABSF128_H

libc/src/math/generic/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,18 @@ add_entrypoint_object(
196196
-O2
197197
)
198198

199+
add_entrypoint_object(
200+
fabsf128
201+
SRCS
202+
fabsf128.cpp
203+
HDRS
204+
../fabsf128.h
205+
DEPENDS
206+
libc.src.__support.FPUtil.basic_operations
207+
COMPILE_OPTIONS
208+
-O3
209+
)
210+
199211
add_entrypoint_object(
200212
trunc
201213
SRCS

libc/src/math/generic/fabsf128.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//===-- Implementation of fabsf128 function -------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "src/math/fabsf128.h"
10+
#include "src/__support/FPUtil/BasicOperations.h"
11+
#include "src/__support/common.h"
12+
13+
namespace LIBC_NAMESPACE {
14+
15+
LLVM_LIBC_FUNCTION(float128, fabsf128, (float128 x)) { return fputil::abs(x); }
16+
17+
} // namespace LIBC_NAMESPACE

libc/test/src/math/smoke/CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ add_fp_unittest(
8787

8888
add_fp_unittest(
8989
fabsl_test
90+
# FIXME: Currently fails on the GPU build.
91+
UNIT_TEST_ONLY
9092
SUITE
9193
libc-math-smoke-tests
9294
SRCS
@@ -97,8 +99,22 @@ add_fp_unittest(
9799
libc.include.math
98100
libc.src.math.fabsl
99101
libc.src.__support.FPUtil.fp_bits
102+
)
103+
104+
add_fp_unittest(
105+
fabsf128_test
100106
# FIXME: Currently fails on the GPU build.
101107
UNIT_TEST_ONLY
108+
SUITE
109+
libc-math-smoke-tests
110+
SRCS
111+
fabsf128_test.cpp
112+
HDRS
113+
FAbsTest.h
114+
DEPENDS
115+
libc.include.math
116+
libc.src.math.fabsf128
117+
libc.src.__support.FPUtil.fp_bits
102118
)
103119

104120
add_fp_unittest(
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//===-- Unittests for fabsf128 --------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "FAbsTest.h"
10+
11+
#include "src/math/fabsf128.h"
12+
13+
LIST_FABS_TESTS(float128, LIBC_NAMESPACE::fabsf128)

0 commit comments

Comments
 (0)