Skip to content

Commit ecf4315

Browse files
committed
[libc][math][c23] Add f16sqrtl C23 math function
1 parent 436f115 commit ecf4315

File tree

13 files changed

+114
-1
lines changed

13 files changed

+114
-1
lines changed

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
509509
libc.src.math.f16fmaf
510510
libc.src.math.f16sqrt
511511
libc.src.math.f16sqrtf
512+
libc.src.math.f16sqrtl
512513
libc.src.math.fabsf16
513514
libc.src.math.fdimf16
514515
libc.src.math.floorf16

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
540540
libc.src.math.f16fmaf
541541
libc.src.math.f16sqrt
542542
libc.src.math.f16sqrtf
543+
libc.src.math.f16sqrtl
543544
libc.src.math.fabsf16
544545
libc.src.math.fdimf16
545546
libc.src.math.floorf16

libc/docs/math/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ Higher Math Functions
292292
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
293293
| fma | |check| | |check| | | | | 7.12.13.1 | F.10.10.1 |
294294
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
295-
| f16sqrt | |check| | |check| | | N/A | |check| | 7.12.14.6 | F.10.11 |
295+
| f16sqrt | |check| | |check| | |check| | N/A | |check| | 7.12.14.6 | F.10.11 |
296296
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
297297
| fsqrt | N/A | | | N/A | | 7.12.14.6 | F.10.11 |
298298
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+

libc/spec/stdc.td

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

731731
GuardedFunctionSpec<"f16sqrt", RetValSpec<Float16Type>, [ArgSpec<DoubleType>], "LIBC_TYPES_HAS_FLOAT16">,
732732
GuardedFunctionSpec<"f16sqrtf", RetValSpec<Float16Type>, [ArgSpec<FloatType>], "LIBC_TYPES_HAS_FLOAT16">,
733+
GuardedFunctionSpec<"f16sqrtl", RetValSpec<Float16Type>, [ArgSpec<LongDoubleType>], "LIBC_TYPES_HAS_FLOAT16">,
733734
GuardedFunctionSpec<"f16sqrtf128", RetValSpec<Float16Type>, [ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT16_AND_FLOAT128">,
734735
]
735736
>;

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(f16fmaf)
105105

106106
add_math_entrypoint_object(f16sqrt)
107107
add_math_entrypoint_object(f16sqrtf)
108+
add_math_entrypoint_object(f16sqrtl)
108109
add_math_entrypoint_object(f16sqrtf128)
109110

110111
add_math_entrypoint_object(fabs)

libc/src/math/f16sqrtl.h

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

libc/src/math/generic/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3783,6 +3783,19 @@ add_entrypoint_object(
37833783
-O3
37843784
)
37853785

3786+
add_entrypoint_object(
3787+
f16sqrtl
3788+
SRCS
3789+
f16sqrtl.cpp
3790+
HDRS
3791+
../f16sqrtl.h
3792+
DEPENDS
3793+
libc.src.__support.macros.properties.types
3794+
libc.src.__support.FPUtil.sqrt
3795+
COMPILE_OPTIONS
3796+
-O3
3797+
)
3798+
37863799
add_entrypoint_object(
37873800
f16sqrtf128
37883801
SRCS

libc/src/math/generic/f16sqrtl.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===-- Implementation of f16sqrtl 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/f16sqrtl.h"
10+
#include "src/__support/FPUtil/sqrt.h"
11+
#include "src/__support/common.h"
12+
13+
namespace LIBC_NAMESPACE {
14+
15+
LLVM_LIBC_FUNCTION(float16, f16sqrtl, (long double x)) {
16+
return fputil::sqrt<float16>(x);
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
@@ -1922,6 +1922,19 @@ add_fp_unittest(
19221922
libc.src.math.f16sqrt
19231923
)
19241924

1925+
add_fp_unittest(
1926+
f16sqrtl_test
1927+
NEED_MPFR
1928+
SUITE
1929+
libc-math-unittests
1930+
SRCS
1931+
f16sqrtl_test.cpp
1932+
HDRS
1933+
SqrtTest.h
1934+
DEPENDS
1935+
libc.src.math.f16sqrtl
1936+
)
1937+
19251938
add_fp_unittest(
19261939
f16fmaf_test
19271940
NEED_MPFR

libc/test/src/math/f16sqrtl_test.cpp

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

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3680,6 +3680,18 @@ add_fp_unittest(
36803680
libc.src.math.f16sqrtf
36813681
)
36823682

3683+
add_fp_unittest(
3684+
f16sqrtl_test
3685+
SUITE
3686+
libc-math-smoke-tests
3687+
SRCS
3688+
f16sqrtl_test.cpp
3689+
HDRS
3690+
SqrtTest.h
3691+
DEPENDS
3692+
libc.src.math.f16sqrtl
3693+
)
3694+
36833695
add_fp_unittest(
36843696
f16sqrtf128_test
36853697
SUITE
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//===-- Unittests for f16sqrtl --------------------------------------------===//
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 "SqrtTest.h"
10+
11+
#include "src/math/f16sqrtl.h"
12+
13+
LIST_NARROWING_SQRT_TESTS(float16, long double, LIBC_NAMESPACE::f16sqrtl)

libc/utils/MPFRWrapper/MPFRUtils.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,9 @@ template void explain_unary_operation_single_output_error(Operation op, float,
813813
template void explain_unary_operation_single_output_error(Operation op, double,
814814
float16, double,
815815
RoundingMode);
816+
template void explain_unary_operation_single_output_error(Operation op,
817+
long double, float16,
818+
double, RoundingMode);
816819
#endif
817820

818821
template <typename T>
@@ -1008,6 +1011,9 @@ template bool compare_unary_operation_single_output(Operation, float, float16,
10081011
double, RoundingMode);
10091012
template bool compare_unary_operation_single_output(Operation, double, float16,
10101013
double, RoundingMode);
1014+
template bool compare_unary_operation_single_output(Operation, long double,
1015+
float16, double,
1016+
RoundingMode);
10111017
#endif
10121018

10131019
template <typename T>

0 commit comments

Comments
 (0)