Skip to content

Commit 0ba2000

Browse files
committed
[libc][math][c23] Add f16subf128 C23 math function
1 parent 43fd804 commit 0ba2000

File tree

9 files changed

+83
-1
lines changed

9 files changed

+83
-1
lines changed

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
604604
libc.src.math.f16addf128
605605
libc.src.math.f16divf128
606606
libc.src.math.f16fmaf128
607+
libc.src.math.f16subf128
607608
)
608609
endif()
609610
endif()

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 | | 7.12.14.2 | F.10.11 |
133+
| f16sub | |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
@@ -734,6 +734,7 @@ def StdC : StandardSpec<"stdc"> {
734734
GuardedFunctionSpec<"f16addf128", RetValSpec<Float16Type>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT16_AND_FLOAT128">,
735735

736736
GuardedFunctionSpec<"f16sub", RetValSpec<Float16Type>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>], "LIBC_TYPES_HAS_FLOAT16">,
737+
GuardedFunctionSpec<"f16subf128", RetValSpec<Float16Type>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT16_AND_FLOAT128">,
737738

738739
GuardedFunctionSpec<"f16divf128", RetValSpec<Float16Type>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT16_AND_FLOAT128">,
739740

libc/src/math/CMakeLists.txt

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

119119
add_math_entrypoint_object(f16sub)
120120
add_math_entrypoint_object(f16subf)
121+
add_math_entrypoint_object(f16subf128)
121122

122123
add_math_entrypoint_object(fabs)
123124
add_math_entrypoint_object(fabsf)

libc/src/math/f16subf128.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===-- Implementation header for f16subf128 --------------------*- 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_F16SUBF128_H
10+
#define LLVM_LIBC_SRC_MATH_F16SUBF128_H
11+
12+
#include "src/__support/macros/properties/types.h"
13+
14+
namespace LIBC_NAMESPACE {
15+
16+
float16 f16subf128(float128 x, float128 y);
17+
18+
} // namespace LIBC_NAMESPACE
19+
20+
#endif // LLVM_LIBC_SRC_MATH_F16SUBF128_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+
f16subf128
3859+
SRCS
3860+
f16subf128.cpp
3861+
HDRS
3862+
../f16subf128.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
f16div
38593872
SRCS

libc/src/math/generic/f16subf128.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===-- Implementation of f16subf128 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/f16subf128.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, f16subf128, (float128 x, float128 y)) {
16+
return fputil::generic::sub<float16>(x, y);
17+
}
18+
19+
} // namespace LIBC_NAMESPACE

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+
f16subf128_test
3723+
SUITE
3724+
libc-math-smoke-tests
3725+
SRCS
3726+
f16subf128_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.f16subf128
3733+
)
3734+
37213735
add_fp_unittest(
37223736
f16div_test
37233737
SUITE
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//===-- Unittests for f16subf128 ------------------------------------------===//
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/f16subf128.h"
12+
13+
LIST_SUB_TESTS(float16, float128, LIBC_NAMESPACE::f16subf128)

0 commit comments

Comments
 (0)