Skip to content

Commit 07c7061

Browse files
committed
[libc][math][c23] Add f16sub C23 math function
1 parent c394283 commit 07c7061

File tree

12 files changed

+110
-1
lines changed

12 files changed

+110
-1
lines changed

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
512512
libc.src.math.f16divf
513513
libc.src.math.f16fmaf
514514
libc.src.math.f16sqrtf
515+
libc.src.math.f16sub
515516
libc.src.math.f16subf
516517
libc.src.math.fabsf16
517518
libc.src.math.fdimf16

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
545545
libc.src.math.f16fmaf
546546
libc.src.math.f16fmal
547547
libc.src.math.f16sqrtf
548+
libc.src.math.f16sub
548549
libc.src.math.f16subf
549550
libc.src.math.fabsf16
550551
libc.src.math.fdimf16

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| | | | N/A | | 7.12.14.2 | F.10.11 |
133+
| f16sub | |check| | |check| | | N/A | | 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<"f16addl", RetValSpec<Float16Type>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>], "LIBC_TYPES_HAS_FLOAT16">,
735735
GuardedFunctionSpec<"f16addf128", RetValSpec<Float16Type>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT16_AND_FLOAT128">,
736736

737+
GuardedFunctionSpec<"f16sub", RetValSpec<Float16Type>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>], "LIBC_TYPES_HAS_FLOAT16">,
737738
GuardedFunctionSpec<"f16subf", RetValSpec<Float16Type>, [ArgSpec<FloatType>, ArgSpec<FloatType>], "LIBC_TYPES_HAS_FLOAT16">,
738739

739740
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
@@ -113,6 +113,7 @@ add_math_entrypoint_object(f16fmaf128)
113113

114114
add_math_entrypoint_object(f16sqrtf)
115115

116+
add_math_entrypoint_object(f16sub)
116117
add_math_entrypoint_object(f16subf)
117118

118119
add_math_entrypoint_object(fabs)

libc/src/math/f16sub.h

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

libc/src/math/generic/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3828,6 +3828,19 @@ add_entrypoint_object(
38283828
-O3
38293829
)
38303830

3831+
add_entrypoint_object(
3832+
f16sub
3833+
SRCS
3834+
f16sub.cpp
3835+
HDRS
3836+
../f16sub.h
3837+
DEPENDS
3838+
libc.src.__support.macros.properties.types
3839+
libc.src.__support.FPUtil.generic.add_sub
3840+
COMPILE_OPTIONS
3841+
-O3
3842+
)
3843+
38313844
add_entrypoint_object(
38323845
f16subf
38333846
SRCS

libc/src/math/generic/f16sub.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===-- Implementation of f16sub 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/f16sub.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, f16sub, (double x, 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
@@ -1941,6 +1941,19 @@ add_fp_unittest(
19411941
libc.src.math.f16addl
19421942
)
19431943

1944+
add_fp_unittest(
1945+
f16sub_test
1946+
NEED_MPFR
1947+
SUITE
1948+
libc-math-unittests
1949+
SRCS
1950+
f16sub_test.cpp
1951+
HDRS
1952+
SubTest.h
1953+
DEPENDS
1954+
libc.src.math.f16sub
1955+
)
1956+
19441957
add_fp_unittest(
19451958
f16subf_test
19461959
NEED_MPFR

libc/test/src/math/f16sub_test.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//===-- Unittests for f16sub ----------------------------------------------===/
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/f16sub.h"
12+
13+
LIST_SUB_TESTS(float16, double, LIBC_NAMESPACE::f16sub)

0 commit comments

Comments
 (0)