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

0 commit comments

Comments
 (0)