Skip to content

Commit 74ec474

Browse files
committed
[libc][math][c23] Add f16sqrtl C23 math function
1 parent cf7430a commit 74ec474

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
@@ -511,6 +511,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
511511
libc.src.math.f16fmaf
512512
libc.src.math.f16sqrt
513513
libc.src.math.f16sqrtf
514+
libc.src.math.f16sqrtl
514515
libc.src.math.fabsf16
515516
libc.src.math.fdimf16
516517
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
@@ -543,6 +543,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
543543
libc.src.math.f16fmal
544544
libc.src.math.f16sqrt
545545
libc.src.math.f16sqrtf
546+
libc.src.math.f16sqrtl
546547
libc.src.math.fabsf16
547548
libc.src.math.fdimf16
548549
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
@@ -733,6 +733,7 @@ def StdC : StandardSpec<"stdc"> {
733733

734734
GuardedFunctionSpec<"f16sqrt", RetValSpec<Float16Type>, [ArgSpec<DoubleType>], "LIBC_TYPES_HAS_FLOAT16">,
735735
GuardedFunctionSpec<"f16sqrtf", RetValSpec<Float16Type>, [ArgSpec<FloatType>], "LIBC_TYPES_HAS_FLOAT16">,
736+
GuardedFunctionSpec<"f16sqrtl", RetValSpec<Float16Type>, [ArgSpec<LongDoubleType>], "LIBC_TYPES_HAS_FLOAT16">,
736737
GuardedFunctionSpec<"f16sqrtf128", RetValSpec<Float16Type>, [ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT16_AND_FLOAT128">,
737738
]
738739
>;

libc/src/math/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ add_math_entrypoint_object(f16fmaf128)
108108

109109
add_math_entrypoint_object(f16sqrt)
110110
add_math_entrypoint_object(f16sqrtf)
111+
add_math_entrypoint_object(f16sqrtl)
111112
add_math_entrypoint_object(f16sqrtf128)
112113

113114
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
@@ -3867,6 +3867,19 @@ add_entrypoint_object(
38673867
-O3
38683868
)
38693869

3870+
add_entrypoint_object(
3871+
f16sqrtl
3872+
SRCS
3873+
f16sqrtl.cpp
3874+
HDRS
3875+
../f16sqrtl.h
3876+
DEPENDS
3877+
libc.src.__support.macros.properties.types
3878+
libc.src.__support.FPUtil.sqrt
3879+
COMPILE_OPTIONS
3880+
-O3
3881+
)
3882+
38703883
add_entrypoint_object(
38713884
f16sqrtf128
38723885
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
@@ -1936,6 +1936,19 @@ add_fp_unittest(
19361936
libc.src.stdlib.srand
19371937
)
19381938

1939+
add_fp_unittest(
1940+
f16sqrtl_test
1941+
NEED_MPFR
1942+
SUITE
1943+
libc-math-unittests
1944+
SRCS
1945+
f16sqrtl_test.cpp
1946+
HDRS
1947+
SqrtTest.h
1948+
DEPENDS
1949+
libc.src.math.f16sqrtl
1950+
)
1951+
19391952
add_fp_unittest(
19401953
f16fmaf_test
19411954
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
@@ -3716,6 +3716,18 @@ add_fp_unittest(
37163716
libc.src.math.f16sqrtf
37173717
)
37183718

3719+
add_fp_unittest(
3720+
f16sqrtl_test
3721+
SUITE
3722+
libc-math-smoke-tests
3723+
SRCS
3724+
f16sqrtl_test.cpp
3725+
HDRS
3726+
SqrtTest.h
3727+
DEPENDS
3728+
libc.src.math.f16sqrtl
3729+
)
3730+
37193731
add_fp_unittest(
37203732
f16sqrtf128_test
37213733
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>
@@ -1016,6 +1019,9 @@ template bool compare_unary_operation_single_output(Operation, float, float16,
10161019
double, RoundingMode);
10171020
template bool compare_unary_operation_single_output(Operation, double, float16,
10181021
double, RoundingMode);
1022+
template bool compare_unary_operation_single_output(Operation, long double,
1023+
float16, double,
1024+
RoundingMode);
10191025
#endif
10201026

10211027
template <typename T>

0 commit comments

Comments
 (0)