Skip to content

[libc][c23][fenv] implement fesetexcept #87603

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
Apr 5, 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
1 change: 1 addition & 0 deletions libc/config/baremetal/arm/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.fenv.fegetround
libc.src.fenv.feholdexcept
libc.src.fenv.fesetenv
libc.src.fenv.fesetexcept
libc.src.fenv.fesetexceptflag
libc.src.fenv.fesetround
libc.src.fenv.feraiseexcept
Expand Down
1 change: 1 addition & 0 deletions libc/config/baremetal/riscv/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.fenv.fegetround
libc.src.fenv.feholdexcept
libc.src.fenv.fesetenv
libc.src.fenv.fesetexcept
libc.src.fenv.fesetexceptflag
libc.src.fenv.fesetround
libc.src.fenv.feraiseexcept
Expand Down
1 change: 1 addition & 0 deletions libc/config/darwin/arm/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.fenv.fegetround
libc.src.fenv.feholdexcept
libc.src.fenv.fesetenv
libc.src.fenv.fesetexcept
libc.src.fenv.fesetexceptflag
libc.src.fenv.fesetround
libc.src.fenv.feraiseexcept
Expand Down
1 change: 1 addition & 0 deletions libc/config/darwin/x86_64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ set(TARGET_LIBM_ENTRYPOINTS
# libc.src.fenv.fegetround
# libc.src.fenv.feholdexcept
# libc.src.fenv.fesetenv
# libc.src.fenv.fesetexcept
# libc.src.fenv.fesetexceptflag
# libc.src.fenv.fesetround
# libc.src.fenv.feraiseexcept
Expand Down
1 change: 1 addition & 0 deletions libc/config/linux/aarch64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.fenv.fegetround
libc.src.fenv.feholdexcept
libc.src.fenv.fesetenv
libc.src.fenv.fesetexcept
libc.src.fenv.fesetexceptflag
libc.src.fenv.fesetround
libc.src.fenv.feraiseexcept
Expand Down
1 change: 1 addition & 0 deletions libc/config/linux/arm/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.fenv.fegetround
libc.src.fenv.feholdexcept
libc.src.fenv.fesetenv
libc.src.fenv.fesetexcept
libc.src.fenv.fesetexceptflag
libc.src.fenv.fesetround
libc.src.fenv.feraiseexcept
Expand Down
1 change: 1 addition & 0 deletions libc/config/linux/riscv/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.fenv.fegetround
libc.src.fenv.feholdexcept
libc.src.fenv.fesetenv
libc.src.fenv.fesetexcept
libc.src.fenv.fesetexceptflag
libc.src.fenv.fesetround
libc.src.fenv.feraiseexcept
Expand Down
1 change: 1 addition & 0 deletions libc/config/linux/x86_64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.fenv.fegetround
libc.src.fenv.feholdexcept
libc.src.fenv.fesetenv
libc.src.fenv.fesetexcept
libc.src.fenv.fesetexceptflag
libc.src.fenv.fesetround
libc.src.fenv.feraiseexcept
Expand Down
1 change: 1 addition & 0 deletions libc/config/windows/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.fenv.fegetround
libc.src.fenv.feholdexcept
libc.src.fenv.fesetenv
libc.src.fenv.fesetexcept
libc.src.fenv.fesetexceptflag
libc.src.fenv.fesetround
libc.src.fenv.feraiseexcept
Expand Down
2 changes: 1 addition & 1 deletion libc/docs/c23.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Additions:

* fenv.h

* fesetexcept
* fesetexcept |check|
* fetestexceptflag
* fegetmode
* fesetmode
Expand Down
5 changes: 5 additions & 0 deletions libc/spec/stdc.td
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ def StdC : StandardSpec<"stdc"> {
RetValSpec<IntType>,
[ArgSpec<FExceptTPtr>, ArgSpec<IntType>]
>,
FunctionSpec<
"fesetexcept",
RetValSpec<IntType>,
[ArgSpec<IntType>]
>,
FunctionSpec<
"fesetexceptflag",
RetValSpec<IntType>,
Expand Down
13 changes: 13 additions & 0 deletions libc/src/fenv/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,19 @@ add_entrypoint_object(
-O2
)

add_entrypoint_object(
fesetexcept
SRCS
fesetexcept.cpp
HDRS
fesetexcept.h
DEPENDS
libc.include.fenv
libc.src.__support.FPUtil.fenv_impl
COMPILE_OPTIONS
-O2
)

add_entrypoint_object(
fesetexceptflag
SRCS
Expand Down
19 changes: 19 additions & 0 deletions libc/src/fenv/fesetexcept.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//===-- Implementation of fesetexcept 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/fenv/fesetexcept.h"
#include "src/__support/FPUtil/FEnvImpl.h"
#include "src/__support/common.h"

namespace LIBC_NAMESPACE {

LLVM_LIBC_FUNCTION(int, fesetexcept, (int excepts)) {
return fputil::set_except(excepts);
}

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

namespace LIBC_NAMESPACE {

int fesetexcept(int excepts);

} // namespace LIBC_NAMESPACE

#endif // LLVM_LIBC_SRC_FENV_FESETEXCEPT_H
1 change: 1 addition & 0 deletions libc/test/src/fenv/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ add_libc_unittest(
DEPENDS
libc.src.fenv.feclearexcept
libc.src.fenv.feraiseexcept
libc.src.fenv.fesetexcept
libc.src.fenv.fetestexcept
libc.src.__support.FPUtil.fenv_impl
)
Expand Down
34 changes: 33 additions & 1 deletion libc/test/src/fenv/exception_status_test.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//===-- Unittests for feclearexcept, feraiseexcept and fetestexpect -------===//
//===-- Unittests for feclearexcept, feraiseexcept, fetestexpect ----------===//
//===-- and fesetexcept ---------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand All @@ -8,6 +9,7 @@

#include "src/fenv/feclearexcept.h"
#include "src/fenv/feraiseexcept.h"
#include "src/fenv/fesetexcept.h"
#include "src/fenv/fetestexcept.h"

#include "src/__support/FPUtil/FEnvImpl.h"
Expand Down Expand Up @@ -38,6 +40,11 @@ TEST(LlvmLibcExceptionStatusTest, RaiseAndTest) {
ASSERT_EQ(r, 0);
s = LIBC_NAMESPACE::fetestexcept(e);
ASSERT_EQ(s, 0);

r = LIBC_NAMESPACE::fesetexcept(e);
ASSERT_EQ(r, 0);
s = LIBC_NAMESPACE::fetestexcept(e);
ASSERT_EQ(s, e);
}

for (int e1 : excepts) {
Expand All @@ -52,6 +59,11 @@ TEST(LlvmLibcExceptionStatusTest, RaiseAndTest) {
ASSERT_EQ(r, 0);
s = LIBC_NAMESPACE::fetestexcept(e);
ASSERT_EQ(s, 0);

r = LIBC_NAMESPACE::fesetexcept(e);
ASSERT_EQ(r, 0);
s = LIBC_NAMESPACE::fetestexcept(e);
ASSERT_EQ(s, e);
}
}

Expand All @@ -68,6 +80,11 @@ TEST(LlvmLibcExceptionStatusTest, RaiseAndTest) {
ASSERT_EQ(r, 0);
s = LIBC_NAMESPACE::fetestexcept(e);
ASSERT_EQ(s, 0);

r = LIBC_NAMESPACE::fesetexcept(e);
ASSERT_EQ(r, 0);
s = LIBC_NAMESPACE::fetestexcept(e);
ASSERT_EQ(s, e);
}
}
}
Expand All @@ -86,6 +103,11 @@ TEST(LlvmLibcExceptionStatusTest, RaiseAndTest) {
ASSERT_EQ(r, 0);
s = LIBC_NAMESPACE::fetestexcept(e);
ASSERT_EQ(s, 0);

r = LIBC_NAMESPACE::fesetexcept(e);
ASSERT_EQ(r, 0);
s = LIBC_NAMESPACE::fetestexcept(e);
ASSERT_EQ(s, e);
}
}
}
Expand All @@ -106,6 +128,11 @@ TEST(LlvmLibcExceptionStatusTest, RaiseAndTest) {
ASSERT_EQ(r, 0);
s = LIBC_NAMESPACE::fetestexcept(e);
ASSERT_EQ(s, 0);

r = LIBC_NAMESPACE::fesetexcept(e);
ASSERT_EQ(r, 0);
s = LIBC_NAMESPACE::fetestexcept(e);
ASSERT_EQ(s, e);
}
}
}
Expand All @@ -116,4 +143,9 @@ TEST(LlvmLibcExceptionStatusTest, RaiseAndTest) {
ASSERT_EQ(r, 0);
int s = LIBC_NAMESPACE::fetestexcept(ALL_EXCEPTS);
ASSERT_EQ(s, ALL_EXCEPTS);

r = LIBC_NAMESPACE::fesetexcept(ALL_EXCEPTS);
ASSERT_EQ(r, 0);
s = LIBC_NAMESPACE::fetestexcept(ALL_EXCEPTS);
ASSERT_EQ(s, ALL_EXCEPTS);
}
10 changes: 10 additions & 0 deletions utils/bazel/llvm-project-overlay/libc/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -1172,6 +1172,16 @@ libc_function(
],
)

libc_function(
name = "fesetexcept",
srcs = ["src/fenv/fesetexcept.cpp"],
hdrs = ["src/fenv/fesetexcept.h"],
deps = [
":__support_common",
":__support_fputil_fenv_impl",
],
)

libc_function(
name = "fegetexceptflag",
srcs = ["src/fenv/fegetexceptflag.cpp"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ libc_test(
libc_function_deps = [
"//libc:feclearexcept",
"//libc:feraiseexcept",
"//libc:fesetexcept",
"//libc:fetestexcept",
],
deps = [
Expand Down