Skip to content

Commit af0f58c

Browse files
author
Job Henandez Lara
authored
[libc][math][c23] Add entrypoints and tests for fsqrt{,l,f128} (#99669)
1 parent c8c0b18 commit af0f58c

File tree

20 files changed

+309
-1
lines changed

20 files changed

+309
-1
lines changed

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,8 @@ set(TARGET_LIBM_ENTRYPOINTS
448448
libc.src.math.fromfpx
449449
libc.src.math.fromfpxf
450450
libc.src.math.fromfpxl
451+
libc.src.math.fsqrt
452+
libc.src.math.fsqrtl
451453
libc.src.math.hypot
452454
libc.src.math.hypotf
453455
libc.src.math.ilogb
@@ -659,6 +661,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
659661
libc.src.math.frexpf128
660662
libc.src.math.fromfpf128
661663
libc.src.math.fromfpxf128
664+
libc.src.math.fsqrtf128
662665
libc.src.math.ilogbf128
663666
libc.src.math.ldexpf128
664667
libc.src.math.llogbf128

libc/docs/math/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ Higher Math Functions
300300
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
301301
| f16sqrt | |check|\* | |check|\* | |check|\* | N/A | |check| | 7.12.14.6 | F.10.11 |
302302
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
303-
| fsqrt | N/A | | | N/A | | 7.12.14.6 | F.10.11 |
303+
| fsqrt | N/A | |check| | |check| | N/A | |check|\* | 7.12.14.6 | F.10.11 |
304304
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
305305
| hypot | |check| | |check| | | | | 7.12.7.4 | F.10.4.4 |
306306
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+

libc/spec/llvm_libc_ext.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ def LLVMLibcExt : StandardSpec<"llvm_libc_ext"> {
8585
GuardedFunctionSpec<"f16sqrtf", RetValSpec<Float16Type>, [ArgSpec<FloatType>], "LIBC_TYPES_HAS_FLOAT16">,
8686
GuardedFunctionSpec<"f16sqrtl", RetValSpec<Float16Type>, [ArgSpec<LongDoubleType>], "LIBC_TYPES_HAS_FLOAT16">,
8787

88+
GuardedFunctionSpec<"fsqrtf128", RetValSpec<FloatType>, [ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
89+
8890
FunctionSpec<"powi", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<IntType>]>,
8991
FunctionSpec<"powif", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<IntType>]>,
9092
]

libc/spec/stdc.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,9 @@ def StdC : StandardSpec<"stdc"> {
739739

740740
GuardedFunctionSpec<"f16mulf128", RetValSpec<Float16Type>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT16_AND_FLOAT128">,
741741

742+
FunctionSpec<"fsqrt", RetValSpec<FloatType>, [ArgSpec<DoubleType>]>,
743+
FunctionSpec<"fsqrtl", RetValSpec<FloatType>, [ArgSpec<LongDoubleType>]>,
744+
742745
GuardedFunctionSpec<"f16divf128", RetValSpec<Float16Type>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT16_AND_FLOAT128">,
743746

744747
GuardedFunctionSpec<"f16sqrtf128", RetValSpec<Float16Type>, [ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT16_AND_FLOAT128">,

libc/src/math/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ add_math_entrypoint_object(f16sqrtf)
131131
add_math_entrypoint_object(f16sqrtl)
132132
add_math_entrypoint_object(f16sqrtf128)
133133

134+
add_math_entrypoint_object(fsqrt)
135+
add_math_entrypoint_object(fsqrtl)
136+
add_math_entrypoint_object(fsqrtf128)
137+
134138
add_math_entrypoint_object(f16sub)
135139
add_math_entrypoint_object(f16subf)
136140
add_math_entrypoint_object(f16subl)

libc/src/math/fsqrt.h

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

libc/src/math/fsqrtf128.h

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

libc/src/math/fsqrtl.h

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

libc/src/math/generic/CMakeLists.txt

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4201,6 +4201,43 @@ add_entrypoint_object(
42014201
-O3
42024202
)
42034203

4204+
add_entrypoint_object(
4205+
fsqrt
4206+
SRCS
4207+
fsqrt.cpp
4208+
HDRS
4209+
../fsqrt.h
4210+
DEPENDS
4211+
libc.src.__support.FPUtil.generic.sqrt
4212+
COMPILE_OPTIONS
4213+
-O3
4214+
)
4215+
4216+
add_entrypoint_object(
4217+
fsqrtl
4218+
SRCS
4219+
fsqrtl.cpp
4220+
HDRS
4221+
../fsqrtl.h
4222+
DEPENDS
4223+
libc.src.__support.FPUtil.generic.sqrt
4224+
COMPILE_OPTIONS
4225+
-O3
4226+
)
4227+
4228+
add_entrypoint_object(
4229+
fsqrtf128
4230+
SRCS
4231+
fsqrtf128.cpp
4232+
HDRS
4233+
../fsqrtf128.h
4234+
DEPENDS
4235+
libc.src.__support.macros.properties.types
4236+
libc.src.__support.FPUtil.generic.sqrt
4237+
COMPILE_OPTIONS
4238+
-O3
4239+
)
4240+
42044241
add_entrypoint_object(
42054242
cbrtf
42064243
SRCS

libc/src/math/generic/fsqrt.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//===-- Implementation of fsqrt 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/fsqrt.h"
10+
#include "src/__support/FPUtil/generic/sqrt.h"
11+
#include "src/__support/common.h"
12+
#include "src/__support/macros/config.h"
13+
14+
namespace LIBC_NAMESPACE_DECL {
15+
16+
LLVM_LIBC_FUNCTION(float, fsqrt, (double x)) { return fputil::sqrt<float>(x); }
17+
18+
} // namespace LIBC_NAMESPACE_DECL

libc/src/math/generic/fsqrtf128.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===-- Implementation of fsqrt128 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/fsqrtf128.h"
10+
#include "src/__support/FPUtil/generic/sqrt.h"
11+
#include "src/__support/common.h"
12+
#include "src/__support/macros/config.h"
13+
14+
namespace LIBC_NAMESPACE_DECL {
15+
16+
LLVM_LIBC_FUNCTION(float, fsqrtf128, (float128 x)) {
17+
return fputil::sqrt<float>(x);
18+
}
19+
20+
} // namespace LIBC_NAMESPACE_DECL

libc/src/math/generic/fsqrtl.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===-- Implementation of fsqrtl 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/fsqrtl.h"
10+
#include "src/__support/FPUtil/generic/sqrt.h"
11+
#include "src/__support/common.h"
12+
#include "src/__support/macros/config.h"
13+
14+
namespace LIBC_NAMESPACE_DECL {
15+
16+
LLVM_LIBC_FUNCTION(float, fsqrtl, (long double x)) {
17+
return fputil::sqrt<float>(x);
18+
}
19+
20+
} // namespace LIBC_NAMESPACE_DECL

libc/test/src/math/CMakeLists.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2245,6 +2245,32 @@ add_fp_unittest(
22452245
libc.src.math.f16sqrtl
22462246
)
22472247

2248+
add_fp_unittest(
2249+
fsqrt_test
2250+
NEED_MPFR
2251+
SUITE
2252+
libc-math-unittests
2253+
SRCS
2254+
fsqrt_test.cpp
2255+
HDRS
2256+
SqrtTest.h
2257+
DEPENDS
2258+
libc.src.math.fsqrt
2259+
)
2260+
2261+
add_fp_unittest(
2262+
fsqrtl_test
2263+
NEED_MPFR
2264+
SUITE
2265+
libc-math-unittests
2266+
SRCS
2267+
fsqrtl_test.cpp
2268+
HDRS
2269+
SqrtTest.h
2270+
DEPENDS
2271+
libc.src.math.fsqrtl
2272+
)
2273+
22482274
add_fp_unittest(
22492275
cbrtf_test
22502276
NEED_MPFR

libc/test/src/math/fsqrt_test.cpp

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

libc/test/src/math/fsqrtl_test.cpp

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

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3959,6 +3959,43 @@ add_fp_unittest(
39593959
libc.src.math.f16sqrtf128
39603960
)
39613961

3962+
add_fp_unittest(
3963+
fsqrt_test
3964+
SUITE
3965+
libc-math-smoke-tests
3966+
SRCS
3967+
fsqrt_test.cpp
3968+
HDRS
3969+
SqrtTest.h
3970+
DEPENDS
3971+
libc.src.math.fsqrt
3972+
)
3973+
3974+
3975+
add_fp_unittest(
3976+
fsqrtl_test
3977+
SUITE
3978+
libc-math-smoke-tests
3979+
SRCS
3980+
fsqrtl_test.cpp
3981+
HDRS
3982+
SqrtTest.h
3983+
DEPENDS
3984+
libc.src.math.fsqrtl
3985+
)
3986+
3987+
add_fp_unittest(
3988+
fsqrtf128_test
3989+
SUITE
3990+
libc-math-smoke-tests
3991+
SRCS
3992+
fsqrtf128_test.cpp
3993+
HDRS
3994+
SqrtTest.h
3995+
DEPENDS
3996+
libc.src.math.fsqrtf128
3997+
)
3998+
39623999
add_fp_unittest(
39634000
sin_test
39644001
SUITE
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//===-- Unittests for fsqrt -----------------------------------------------===//
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/fsqrt.h"
12+
13+
LIST_NARROWING_SQRT_TESTS(float, double, LIBC_NAMESPACE::fsqrt)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//===-- Unittests for fsqrtf128 -------------------------------------------===//
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/fsqrtf128.h"
12+
13+
LIST_NARROWING_SQRT_TESTS(float, float128, LIBC_NAMESPACE::fsqrtf128)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//===-- Unittests for fsqrtl ----------------------------------------------===//
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/fsqrtl.h"
12+
13+
LIST_NARROWING_SQRT_TESTS(float, long double, LIBC_NAMESPACE::fsqrtl)

libc/utils/MPFRWrapper/MPFRUtils.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,13 @@ template void explain_unary_operation_single_output_error(Operation op,
887887
long double,
888888
long double, double,
889889
RoundingMode);
890+
template void explain_unary_operation_single_output_error(Operation op, double,
891+
float, double,
892+
RoundingMode);
893+
template void explain_unary_operation_single_output_error(Operation op,
894+
long double, float,
895+
double, RoundingMode);
896+
890897
#ifdef LIBC_TYPES_HAS_FLOAT16
891898
template void explain_unary_operation_single_output_error(Operation op, float16,
892899
float16, double,
@@ -1106,6 +1113,11 @@ template bool compare_unary_operation_single_output(Operation, double, double,
11061113
template bool compare_unary_operation_single_output(Operation, long double,
11071114
long double, double,
11081115
RoundingMode);
1116+
template bool compare_unary_operation_single_output(Operation, double, float,
1117+
double, RoundingMode);
1118+
template bool compare_unary_operation_single_output(Operation, long double,
1119+
float, double,
1120+
RoundingMode);
11091121
#ifdef LIBC_TYPES_HAS_FLOAT16
11101122
template bool compare_unary_operation_single_output(Operation, float16, float16,
11111123
double, RoundingMode);

0 commit comments

Comments
 (0)