Skip to content

[libc][math][c23] Add entrypoints and tests for fsqrt{,l,f128} #99669

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from Jul 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions libc/config/linux/x86_64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,8 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.fromfpx
libc.src.math.fromfpxf
libc.src.math.fromfpxl
libc.src.math.fsqrt
libc.src.math.fsqrtl
libc.src.math.hypot
libc.src.math.hypotf
libc.src.math.ilogb
Expand Down Expand Up @@ -661,6 +663,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
libc.src.math.frexpf128
libc.src.math.fromfpf128
libc.src.math.fromfpxf128
libc.src.math.fsqrtf128
libc.src.math.ilogbf128
libc.src.math.ldexpf128
libc.src.math.llogbf128
Expand Down
2 changes: 1 addition & 1 deletion libc/docs/math/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ Higher Math Functions
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| f16sqrt | |check|\* | |check|\* | |check|\* | N/A | |check| | 7.12.14.6 | F.10.11 |
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| fsqrt | N/A | | | N/A | | 7.12.14.6 | F.10.11 |
| fsqrt | N/A | |check| | |check| | N/A | |check|\* | 7.12.14.6 | F.10.11 |
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| hypot | |check| | |check| | | | | 7.12.7.4 | F.10.4.4 |
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
Expand Down
2 changes: 2 additions & 0 deletions libc/spec/llvm_libc_ext.td
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ def LLVMLibcExt : StandardSpec<"llvm_libc_ext"> {
GuardedFunctionSpec<"f16sqrtf", RetValSpec<Float16Type>, [ArgSpec<FloatType>], "LIBC_TYPES_HAS_FLOAT16">,
GuardedFunctionSpec<"f16sqrtl", RetValSpec<Float16Type>, [ArgSpec<LongDoubleType>], "LIBC_TYPES_HAS_FLOAT16">,

GuardedFunctionSpec<"fsqrtf128", RetValSpec<FloatType>, [ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,

FunctionSpec<"powi", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<IntType>]>,
FunctionSpec<"powif", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<IntType>]>,
]
Expand Down
3 changes: 3 additions & 0 deletions libc/spec/stdc.td
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,9 @@ def StdC : StandardSpec<"stdc"> {

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

FunctionSpec<"fsqrt", RetValSpec<FloatType>, [ArgSpec<DoubleType>]>,
FunctionSpec<"fsqrtl", RetValSpec<FloatType>, [ArgSpec<LongDoubleType>]>,

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

GuardedFunctionSpec<"f16sqrtf128", RetValSpec<Float16Type>, [ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT16_AND_FLOAT128">,
Expand Down
4 changes: 4 additions & 0 deletions libc/src/math/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ add_math_entrypoint_object(f16sqrtf)
add_math_entrypoint_object(f16sqrtl)
add_math_entrypoint_object(f16sqrtf128)

add_math_entrypoint_object(fsqrt)
add_math_entrypoint_object(fsqrtl)
add_math_entrypoint_object(fsqrtf128)

add_math_entrypoint_object(f16sub)
add_math_entrypoint_object(f16subf)
add_math_entrypoint_object(f16subl)
Expand Down
20 changes: 20 additions & 0 deletions libc/src/math/fsqrt.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- Implementation header for fsqrt -------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_SRC_MATH_FSQRT_H
#define LLVM_LIBC_SRC_MATH_FSQRT_H

#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

float fsqrt(double x);

} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC_MATH_FSQRT_H
21 changes: 21 additions & 0 deletions libc/src/math/fsqrtf128.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//===-- Implementation header for fsqrtf128 ---------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_SRC_MATH_FSQRTF128_H
#define LLVM_LIBC_SRC_MATH_FSQRTF128_H

#include "src/__support/macros/config.h"
#include "src/__support/macros/properties/types.h"

namespace LIBC_NAMESPACE_DECL {

float fsqrtf128(float128 x);

} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC_MATH_FSQRTF128_H
20 changes: 20 additions & 0 deletions libc/src/math/fsqrtl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- Implementation header for fsqrtl ------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_SRC_MATH_FSQRTL_H
#define LLVM_LIBC_SRC_MATH_FSQRTL_H

#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

float fsqrtl(long double x);

} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC_MATH_FSQRTL_H
37 changes: 37 additions & 0 deletions libc/src/math/generic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4201,6 +4201,43 @@ add_entrypoint_object(
-O3
)

add_entrypoint_object(
fsqrt
SRCS
fsqrt.cpp
HDRS
../fsqrt.h
DEPENDS
libc.src.__support.FPUtil.generic.sqrt
COMPILE_OPTIONS
-O3
)

add_entrypoint_object(
fsqrtl
SRCS
fsqrtl.cpp
HDRS
../fsqrtl.h
DEPENDS
libc.src.__support.FPUtil.generic.sqrt
COMPILE_OPTIONS
-O3
)

add_entrypoint_object(
fsqrtf128
SRCS
fsqrtf128.cpp
HDRS
../fsqrtf128.h
DEPENDS
libc.src.__support.macros.properties.types
libc.src.__support.FPUtil.generic.sqrt
COMPILE_OPTIONS
-O3
)

add_entrypoint_object(
cbrtf
SRCS
Expand Down
18 changes: 18 additions & 0 deletions libc/src/math/generic/fsqrt.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//===-- Implementation of fsqrt function ----------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "src/math/fsqrt.h"
#include "src/__support/FPUtil/generic/sqrt.h"
#include "src/__support/common.h"
#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

LLVM_LIBC_FUNCTION(float, fsqrt, (double x)) { return fputil::sqrt<float>(x); }

} // namespace LIBC_NAMESPACE_DECL
20 changes: 20 additions & 0 deletions libc/src/math/generic/fsqrtf128.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- Implementation of fsqrt128 function -------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "src/math/fsqrtf128.h"
#include "src/__support/FPUtil/generic/sqrt.h"
#include "src/__support/common.h"
#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

LLVM_LIBC_FUNCTION(float, fsqrtf128, (float128 x)) {
return fputil::sqrt<float>(x);
}

} // namespace LIBC_NAMESPACE_DECL
20 changes: 20 additions & 0 deletions libc/src/math/generic/fsqrtl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- Implementation of fsqrtl function ---------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "src/math/fsqrtl.h"
#include "src/__support/FPUtil/generic/sqrt.h"
#include "src/__support/common.h"
#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

LLVM_LIBC_FUNCTION(float, fsqrtl, (long double x)) {
return fputil::sqrt<float>(x);
}

} // namespace LIBC_NAMESPACE_DECL
26 changes: 26 additions & 0 deletions libc/test/src/math/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2245,6 +2245,32 @@ add_fp_unittest(
libc.src.math.f16sqrtl
)

add_fp_unittest(
fsqrt_test
NEED_MPFR
SUITE
libc-math-unittests
SRCS
fsqrt_test.cpp
HDRS
SqrtTest.h
DEPENDS
libc.src.math.fsqrt
)

add_fp_unittest(
fsqrtl_test
NEED_MPFR
SUITE
libc-math-unittests
SRCS
fsqrtl_test.cpp
HDRS
SqrtTest.h
DEPENDS
libc.src.math.fsqrtl
)

add_fp_unittest(
cbrtf_test
NEED_MPFR
Expand Down
13 changes: 13 additions & 0 deletions libc/test/src/math/fsqrt_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//===-- Unittests for fsqrt -----------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "SqrtTest.h"

#include "src/math/fsqrt.h"

LIST_NARROWING_SQRT_TESTS(float, double, LIBC_NAMESPACE::fsqrt)
13 changes: 13 additions & 0 deletions libc/test/src/math/fsqrtl_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//===-- Unittests for fsqrtl ----------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "SqrtTest.h"

#include "src/math/fsqrtl.h"

LIST_NARROWING_SQRT_TESTS(float, long double, LIBC_NAMESPACE::fsqrtl)
37 changes: 37 additions & 0 deletions libc/test/src/math/smoke/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3959,6 +3959,43 @@ add_fp_unittest(
libc.src.math.f16sqrtf128
)

add_fp_unittest(
fsqrt_test
SUITE
libc-math-smoke-tests
SRCS
fsqrt_test.cpp
HDRS
SqrtTest.h
DEPENDS
libc.src.math.fsqrt
)


add_fp_unittest(
fsqrtl_test
SUITE
libc-math-smoke-tests
SRCS
fsqrtl_test.cpp
HDRS
SqrtTest.h
DEPENDS
libc.src.math.fsqrtl
)

add_fp_unittest(
fsqrtf128_test
SUITE
libc-math-smoke-tests
SRCS
fsqrtf128_test.cpp
HDRS
SqrtTest.h
DEPENDS
libc.src.math.fsqrtf128
)

add_fp_unittest(
sin_test
SUITE
Expand Down
13 changes: 13 additions & 0 deletions libc/test/src/math/smoke/fsqrt_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//===-- Unittests for fsqrt -----------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "SqrtTest.h"

#include "src/math/fsqrt.h"

LIST_NARROWING_SQRT_TESTS(float, double, LIBC_NAMESPACE::fsqrt)
13 changes: 13 additions & 0 deletions libc/test/src/math/smoke/fsqrtf128_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//===-- Unittests for fsqrtf128 -------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "SqrtTest.h"

#include "src/math/fsqrtf128.h"

LIST_NARROWING_SQRT_TESTS(float, float128, LIBC_NAMESPACE::fsqrtf128)
13 changes: 13 additions & 0 deletions libc/test/src/math/smoke/fsqrtl_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//===-- Unittests for fsqrtl ----------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "SqrtTest.h"

#include "src/math/fsqrtl.h"

LIST_NARROWING_SQRT_TESTS(float, long double, LIBC_NAMESPACE::fsqrtl)
12 changes: 12 additions & 0 deletions libc/utils/MPFRWrapper/MPFRUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,13 @@ template void explain_unary_operation_single_output_error(Operation op,
long double,
long double, double,
RoundingMode);
template void explain_unary_operation_single_output_error(Operation op, double,
float, double,
RoundingMode);
template void explain_unary_operation_single_output_error(Operation op,
long double, float,
double, RoundingMode);

#ifdef LIBC_TYPES_HAS_FLOAT16
template void explain_unary_operation_single_output_error(Operation op, float16,
float16, double,
Expand Down Expand Up @@ -1106,6 +1113,11 @@ template bool compare_unary_operation_single_output(Operation, double, double,
template bool compare_unary_operation_single_output(Operation, long double,
long double, double,
RoundingMode);
template bool compare_unary_operation_single_output(Operation, double, float,
double, RoundingMode);
template bool compare_unary_operation_single_output(Operation, long double,
float, double,
RoundingMode);
#ifdef LIBC_TYPES_HAS_FLOAT16
template bool compare_unary_operation_single_output(Operation, float16, float16,
double, RoundingMode);
Expand Down
Loading