Skip to content

Commit 436f115

Browse files
committed
[libc][math][c23] Add f16sqrtf128 C23 math function
1 parent 60f802b commit 436f115

File tree

10 files changed

+94
-1
lines changed

10 files changed

+94
-1
lines changed

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,13 @@ if(LIBC_TYPES_HAS_FLOAT16)
559559
libc.src.math.ufromfpf16
560560
libc.src.math.ufromfpxf16
561561
)
562+
563+
if(LIBC_TYPES_HAS_FLOAT128)
564+
list(APPEND TARGET_LIBM_ENTRYPOINTS
565+
# math.h C23 mixed _Float16 and _Float128 entrypoints
566+
libc.src.math.f16sqrtf128
567+
)
568+
endif()
562569
endif()
563570

564571
if(LIBC_TYPES_HAS_FLOAT128)

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,13 @@ if(LIBC_TYPES_HAS_FLOAT16)
588588
libc.src.math.ufromfpf16
589589
libc.src.math.ufromfpxf16
590590
)
591+
592+
if(LIBC_TYPES_HAS_FLOAT128)
593+
list(APPEND TARGET_LIBM_ENTRYPOINTS
594+
# math.h C23 mixed _Float16 and _Float128 entrypoints
595+
libc.src.math.f16sqrtf128
596+
)
597+
endif()
591598
endif()
592599

593600
if(LIBC_TYPES_HAS_FLOAT128)

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 | | 7.12.14.6 | F.10.11 |
295+
| f16sqrt | |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<"f16sqrtf128", RetValSpec<Float16Type>, [ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT16_AND_FLOAT128">,
733734
]
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(f16sqrtf128)
108109

109110
add_math_entrypoint_object(fabs)
110111
add_math_entrypoint_object(fabsf)

libc/src/math/f16sqrtf128.h

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

libc/src/math/generic/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3782,3 +3782,16 @@ add_entrypoint_object(
37823782
COMPILE_OPTIONS
37833783
-O3
37843784
)
3785+
3786+
add_entrypoint_object(
3787+
f16sqrtf128
3788+
SRCS
3789+
f16sqrtf128.cpp
3790+
HDRS
3791+
../f16sqrtf128.h
3792+
DEPENDS
3793+
libc.src.__support.macros.properties.types
3794+
libc.src.__support.FPUtil.sqrt
3795+
COMPILE_OPTIONS
3796+
-O3
3797+
)

libc/src/math/generic/f16sqrtf128.cpp

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

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

0 commit comments

Comments
 (0)