Skip to content

Commit cedb6d7

Browse files
committed
[libc][math][c23] Add f16subl C23 math function
1 parent 32f5177 commit cedb6d7

File tree

11 files changed

+109
-1
lines changed

11 files changed

+109
-1
lines changed

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
547547
libc.src.math.f16sqrtf
548548
libc.src.math.f16sub
549549
libc.src.math.f16subf
550+
libc.src.math.f16subl
550551
libc.src.math.fabsf16
551552
libc.src.math.fdimf16
552553
libc.src.math.floorf16

libc/docs/math/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ Basic Operations
130130
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
131131
| f16fma | |check| | |check| | |check| | N/A | |check| | 7.12.14.5 | F.10.11 |
132132
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
133-
| f16sub | |check| | |check| | | N/A | |check| | 7.12.14.2 | F.10.11 |
133+
| f16sub | |check| | |check| | |check| | N/A | |check| | 7.12.14.2 | F.10.11 |
134134
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
135135
| fabs | |check| | |check| | |check| | |check| | |check| | 7.12.7.3 | F.10.4.3 |
136136
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+

libc/spec/stdc.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,7 @@ def StdC : StandardSpec<"stdc"> {
736736

737737
GuardedFunctionSpec<"f16sub", RetValSpec<Float16Type>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>], "LIBC_TYPES_HAS_FLOAT16">,
738738
GuardedFunctionSpec<"f16subf", RetValSpec<Float16Type>, [ArgSpec<FloatType>, ArgSpec<FloatType>], "LIBC_TYPES_HAS_FLOAT16">,
739+
GuardedFunctionSpec<"f16subl", RetValSpec<Float16Type>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>], "LIBC_TYPES_HAS_FLOAT16">,
739740
GuardedFunctionSpec<"f16subf128", RetValSpec<Float16Type>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT16_AND_FLOAT128">,
740741

741742
GuardedFunctionSpec<"f16divf", RetValSpec<Float16Type>, [ArgSpec<FloatType>, ArgSpec<FloatType>], "LIBC_TYPES_HAS_FLOAT16">,

libc/src/math/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ add_math_entrypoint_object(f16sqrtf)
115115

116116
add_math_entrypoint_object(f16sub)
117117
add_math_entrypoint_object(f16subf)
118+
add_math_entrypoint_object(f16subl)
118119
add_math_entrypoint_object(f16subf128)
119120

120121
add_math_entrypoint_object(fabs)

libc/src/math/f16subl.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===-- Implementation header for f16subl -----------------------*- 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_F16SUBL_H
10+
#define LLVM_LIBC_SRC_MATH_F16SUBL_H
11+
12+
#include "src/__support/macros/properties/types.h"
13+
14+
namespace LIBC_NAMESPACE {
15+
16+
float16 f16subl(long double x, long double y);
17+
18+
} // namespace LIBC_NAMESPACE
19+
20+
#endif // LLVM_LIBC_SRC_MATH_F16SUBL_H

libc/src/math/generic/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3854,6 +3854,19 @@ add_entrypoint_object(
38543854
-O3
38553855
)
38563856

3857+
add_entrypoint_object(
3858+
f16subl
3859+
SRCS
3860+
f16subl.cpp
3861+
HDRS
3862+
../f16subl.h
3863+
DEPENDS
3864+
libc.src.__support.macros.properties.types
3865+
libc.src.__support.FPUtil.generic.add_sub
3866+
COMPILE_OPTIONS
3867+
-O3
3868+
)
3869+
38573870
add_entrypoint_object(
38583871
f16subf128
38593872
SRCS

libc/src/math/generic/f16subl.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===-- Implementation of f16subl 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/f16subl.h"
10+
#include "src/__support/FPUtil/generic/add_sub.h"
11+
#include "src/__support/common.h"
12+
13+
namespace LIBC_NAMESPACE {
14+
15+
LLVM_LIBC_FUNCTION(float16, f16subl, (long double x, long double y)) {
16+
return fputil::generic::sub<float16>(x, y);
17+
}
18+
19+
} // namespace LIBC_NAMESPACE

libc/test/src/math/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1967,6 +1967,19 @@ add_fp_unittest(
19671967
libc.src.math.f16subf
19681968
)
19691969

1970+
add_fp_unittest(
1971+
f16subl_test
1972+
NEED_MPFR
1973+
SUITE
1974+
libc-math-unittests
1975+
SRCS
1976+
f16subl_test.cpp
1977+
HDRS
1978+
SubTest.h
1979+
DEPENDS
1980+
libc.src.math.f16subl
1981+
)
1982+
19701983
add_fp_unittest(
19711984
f16divf_test
19721985
NEED_MPFR

libc/test/src/math/f16subl_test.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//===-- Unittests for f16subl ---------------------------------------------===//
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 "SubTest.h"
10+
11+
#include "src/math/f16subl.h"
12+
13+
LIST_SUB_TESTS(float16, long double, LIBC_NAMESPACE::f16subl)

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3718,6 +3718,20 @@ add_fp_unittest(
37183718
libc.src.math.f16subf
37193719
)
37203720

3721+
add_fp_unittest(
3722+
f16subl_test
3723+
SUITE
3724+
libc-math-smoke-tests
3725+
SRCS
3726+
f16subl_test.cpp
3727+
HDRS
3728+
SubTest.h
3729+
DEPENDS
3730+
libc.hdr.fenv_macros
3731+
libc.src.__support.FPUtil.basic_operations
3732+
libc.src.math.f16subl
3733+
)
3734+
37213735
add_fp_unittest(
37223736
f16subf128_test
37233737
SUITE
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//===-- Unittests for f16subl ---------------------------------------------===//
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 "SubTest.h"
10+
11+
#include "src/math/f16subl.h"
12+
13+
LIST_SUB_TESTS(float16, long double, LIBC_NAMESPACE::f16subl)

0 commit comments

Comments
 (0)