Skip to content

[libc] Provide isnan, isnanf and isnanl functions #96008

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 5 commits into from
Jul 10, 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/baremetal/arm/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,9 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.ilogb
libc.src.math.ilogbf
libc.src.math.ilogbl
libc.src.math.isnan
libc.src.math.isnanf
libc.src.math.isnanl
libc.src.math.ldexp
libc.src.math.ldexpf
libc.src.math.ldexpl
Expand Down
3 changes: 3 additions & 0 deletions libc/config/baremetal/riscv/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,9 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.ilogb
libc.src.math.ilogbf
libc.src.math.ilogbl
libc.src.math.isnan
libc.src.math.isnanf
libc.src.math.isnanl
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't test baremetal continuously; please add these entrypoints to at least libc/config/linux/x86_64/entrypoints.txt, if not the rest of the linux targets.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

libc.src.math.ldexp
libc.src.math.ldexpf
libc.src.math.ldexpl
Expand Down
3 changes: 3 additions & 0 deletions libc/config/linux/aarch64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,9 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.ilogb
libc.src.math.ilogbf
libc.src.math.ilogbl
libc.src.math.isnan
libc.src.math.isnanf
libc.src.math.isnanl
libc.src.math.ldexp
libc.src.math.ldexpf
libc.src.math.ldexpl
Expand Down
3 changes: 3 additions & 0 deletions libc/config/linux/riscv/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,9 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.ilogb
libc.src.math.ilogbf
libc.src.math.ilogbl
libc.src.math.isnan
libc.src.math.isnanf
libc.src.math.isnanl
libc.src.math.ldexp
libc.src.math.ldexpf
libc.src.math.ldexpl
Expand Down
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 @@ -440,6 +440,9 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.ilogb
libc.src.math.ilogbf
libc.src.math.ilogbl
libc.src.math.isnan
libc.src.math.isnanf
libc.src.math.isnanl
libc.src.math.ldexp
libc.src.math.ldexpf
libc.src.math.ldexpl
Expand Down
1 change: 1 addition & 0 deletions libc/include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ add_gen_header(
.llvm_libc_common_h
.llvm-libc-macros.float16_macros
.llvm-libc-macros.math_macros
.llvm-libc-macros.math_function_macros
.llvm-libc-types.double_t
.llvm-libc-types.float_t
.llvm-libc-types.float128
Expand Down
6 changes: 6 additions & 0 deletions libc/include/llvm-libc-macros/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ add_macro_header(
.limits_macros
)

add_macro_header(
math_function_macros
HDR
math-function-macros.h
)

add_macro_header(
offsetof_macro
HDR
Expand Down
16 changes: 16 additions & 0 deletions libc/include/llvm-libc-macros/math-function-macros.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//===-- Definition of function macros from math.h -------------------------===//
//
// 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_MACROS_MATH_FUNCTION_MACROS_H
#define LLVM_LIBC_MACROS_MATH_FUNCTION_MACROS_H

#define isfinite(x) __builtin_isfinite(x)
#define isinf(x) __builtin_isinf(x)
#define isnan(x) __builtin_isnan(x)

#endif // LLVM_LIBC_MACROS_MATH_FUNCTION_MACROS_H
5 changes: 0 additions & 5 deletions libc/include/llvm-libc-macros/math-macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,4 @@
#define math_errhandling (MATH_ERRNO | MATH_ERREXCEPT)
#endif

// TODO: Move generic functional math macros to a separate header file.
#define isfinite(x) __builtin_isfinite(x)
#define isinf(x) __builtin_isinf(x)
#define isnan(x) __builtin_isnan(x)

#endif // LLVM_LIBC_MACROS_MATH_MACROS_H
3 changes: 3 additions & 0 deletions libc/include/math.h.def
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@

%%public_api()


#include "llvm-libc-macros/math-function-macros.h"

#endif // LLVM_LIBC_MATH_H
13 changes: 13 additions & 0 deletions libc/spec/bsd_ext.td
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
def BsdExtensions : StandardSpec<"BSDExtensions"> {
HeaderSpec Math = HeaderSpec<
"math.h",
[], // Macros
[], // Types
[], // Enumerations
[
FunctionSpec<"isnan", RetValSpec<IntType>, [ArgSpec<DoubleType>]>,
FunctionSpec<"isnanf", RetValSpec<IntType>, [ArgSpec<FloatType>]>,
FunctionSpec<"isnanl", RetValSpec<IntType>, [ArgSpec<LongDoubleType>]>,
]
>;

HeaderSpec String = HeaderSpec<
"string.h",
[], // Macros
Expand Down Expand Up @@ -67,6 +79,7 @@ def BsdExtensions : StandardSpec<"BSDExtensions"> {
>;

let Headers = [
Math,
String,
Strings,
SysWait,
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 @@ -242,6 +242,10 @@ add_math_entrypoint_object(ilogbl)
add_math_entrypoint_object(ilogbf16)
add_math_entrypoint_object(ilogbf128)

add_math_entrypoint_object(isnan)
add_math_entrypoint_object(isnanf)
add_math_entrypoint_object(isnanl)

add_math_entrypoint_object(llogb)
add_math_entrypoint_object(llogbf)
add_math_entrypoint_object(llogbl)
Expand Down
30 changes: 30 additions & 0 deletions libc/src/math/generic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2810,6 +2810,36 @@ add_entrypoint_object(
-O3
)

add_entrypoint_object(
isnan
SRCS
isnan.cpp
HDRS
../isnan.h
COMPILE_OPTIONS
-O3
)

add_entrypoint_object(
isnanf
SRCS
isnanf.cpp
HDRS
../isnanf.h
COMPILE_OPTIONS
-O3
)

add_entrypoint_object(
isnanl
SRCS
isnanl.cpp
HDRS
../isnanl.h
COMPILE_OPTIONS
-O3
)

add_entrypoint_object(
nan
SRCS
Expand Down
16 changes: 16 additions & 0 deletions libc/src/math/generic/isnan.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//===-- Implementation of isnan 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/isnan.h"
#include "src/__support/common.h"

namespace LIBC_NAMESPACE {

LLVM_LIBC_FUNCTION(int, isnan, (double x)) { return __builtin_isnan(x); }

} // namespace LIBC_NAMESPACE
16 changes: 16 additions & 0 deletions libc/src/math/generic/isnanf.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//===-- Implementation of isnanf 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/isnanf.h"
#include "src/__support/common.h"

namespace LIBC_NAMESPACE {

LLVM_LIBC_FUNCTION(int, isnanf, (float x)) { return __builtin_isnan(x); }

} // namespace LIBC_NAMESPACE
16 changes: 16 additions & 0 deletions libc/src/math/generic/isnanl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//===-- Implementation of isnanl 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/isnanl.h"
#include "src/__support/common.h"

namespace LIBC_NAMESPACE {

LLVM_LIBC_FUNCTION(int, isnanl, (long double x)) { return __builtin_isnan(x); }

} // namespace LIBC_NAMESPACE
18 changes: 18 additions & 0 deletions libc/src/math/isnan.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//===-- Implementation header for isnan -------------------------*- 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_ISNAN_H
#define LLVM_LIBC_SRC_MATH_ISNAN_H

namespace LIBC_NAMESPACE {

int isnan(double x);

} // namespace LIBC_NAMESPACE

#endif // LLVM_LIBC_SRC_MATH_ISNAN_H
18 changes: 18 additions & 0 deletions libc/src/math/isnanf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//===-- Implementation header for isnanf ------------------------*- 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_ISNANF_H
#define LLVM_LIBC_SRC_MATH_ISNANF_H

namespace LIBC_NAMESPACE {

int isnanf(float x);

} // namespace LIBC_NAMESPACE

#endif // LLVM_LIBC_SRC_MATH_ISNANF_H
18 changes: 18 additions & 0 deletions libc/src/math/isnanl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//===-- Implementation header for isnanl ------------------------*- 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_ISNANL_H
#define LLVM_LIBC_SRC_MATH_ISNANL_H

namespace LIBC_NAMESPACE {

int isnanl(long double x);

} // namespace LIBC_NAMESPACE

#endif // LLVM_LIBC_SRC_MATH_ISNANL_H
Loading