-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
[libc][c23][fenv] implement fesetexcept #87603
Conversation
@llvm/pr-subscribers-libc Author: aniplcc (aniplcc) ChangesCloses #87564 Full diff: https://github.com/llvm/llvm-project/pull/87603.diff 15 Files Affected:
diff --git a/libc/config/baremetal/arm/entrypoints.txt b/libc/config/baremetal/arm/entrypoints.txt
index 9e21f5c20d9207..f33f9430c79205 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -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
diff --git a/libc/config/baremetal/riscv/entrypoints.txt b/libc/config/baremetal/riscv/entrypoints.txt
index 7664937da0f6e0..dad187fa0496d3 100644
--- a/libc/config/baremetal/riscv/entrypoints.txt
+++ b/libc/config/baremetal/riscv/entrypoints.txt
@@ -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
diff --git a/libc/config/darwin/arm/entrypoints.txt b/libc/config/darwin/arm/entrypoints.txt
index 6b89ce55d72b65..aea2f6d5771e87 100644
--- a/libc/config/darwin/arm/entrypoints.txt
+++ b/libc/config/darwin/arm/entrypoints.txt
@@ -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
diff --git a/libc/config/darwin/x86_64/entrypoints.txt b/libc/config/darwin/x86_64/entrypoints.txt
index 5a1a6a15ef30c0..09fe3d7b476870 100644
--- a/libc/config/darwin/x86_64/entrypoints.txt
+++ b/libc/config/darwin/x86_64/entrypoints.txt
@@ -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
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 8bf99459f7898d..f5f5c437685a21 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -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
diff --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt
index 04baa4c1cf93ab..fca50735d320ba 100644
--- a/libc/config/linux/arm/entrypoints.txt
+++ b/libc/config/linux/arm/entrypoints.txt
@@ -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
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 4dc5e9d33f0f84..71289789158f4b 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -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
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index cc7671cab08184..a2bc74cc27cdea 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -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
diff --git a/libc/config/windows/entrypoints.txt b/libc/config/windows/entrypoints.txt
index c38125a6462272..c46c947bf31354 100644
--- a/libc/config/windows/entrypoints.txt
+++ b/libc/config/windows/entrypoints.txt
@@ -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
diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td
index 719bb9aa18cb0a..59801259620dcf 100644
--- a/libc/spec/stdc.td
+++ b/libc/spec/stdc.td
@@ -179,6 +179,11 @@ def StdC : StandardSpec<"stdc"> {
RetValSpec<IntType>,
[ArgSpec<FExceptTPtr>, ArgSpec<IntType>]
>,
+ FunctionSpec<
+ "fesetexcept",
+ RetValSpec<IntType>,
+ [ArgSpec<IntType>]
+ >,
FunctionSpec<
"fesetexceptflag",
RetValSpec<IntType>,
diff --git a/libc/src/fenv/CMakeLists.txt b/libc/src/fenv/CMakeLists.txt
index 0da539d187bfa1..d2f90d3d007a1b 100644
--- a/libc/src/fenv/CMakeLists.txt
+++ b/libc/src/fenv/CMakeLists.txt
@@ -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
diff --git a/libc/src/fenv/fesetexcept.cpp b/libc/src/fenv/fesetexcept.cpp
new file mode 100644
index 00000000000000..9afa7b73b4fb5d
--- /dev/null
+++ b/libc/src/fenv/fesetexcept.cpp
@@ -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
diff --git a/libc/src/fenv/fesetexcept.h b/libc/src/fenv/fesetexcept.h
new file mode 100644
index 00000000000000..40a7303efcb0aa
--- /dev/null
+++ b/libc/src/fenv/fesetexcept.h
@@ -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
diff --git a/libc/test/src/fenv/CMakeLists.txt b/libc/test/src/fenv/CMakeLists.txt
index ba338bb6c73189..7e456b9a922fb9 100644
--- a/libc/test/src/fenv/CMakeLists.txt
+++ b/libc/test/src/fenv/CMakeLists.txt
@@ -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
)
diff --git a/libc/test/src/fenv/exception_status_test.cpp b/libc/test/src/fenv/exception_status_test.cpp
index e4e2240fc374c8..c98d2c8257c60e 100644
--- a/libc/test/src/fenv/exception_status_test.cpp
+++ b/libc/test/src/fenv/exception_status_test.cpp
@@ -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.
@@ -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"
@@ -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) {
@@ -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);
}
}
@@ -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);
}
}
}
@@ -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);
}
}
}
@@ -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);
}
}
}
@@ -116,4 +143,9 @@ TEST(LlvmLibcExceptionStatusTest, RaiseAndTest) {
ASSERT_EQ(r, 0);
int s = LIBC_NAMESPACE::fetestexcept(ALL_EXCEPTS);
ASSERT_EQ(s, ALL_EXCEPTS);
+
+ int r1 = LIBC_NAMESPACE::fesetexcept(ALL_EXCEPTS);
+ ASSERT_EQ(r, 0);
+ int s1 = LIBC_NAMESPACE::fetestexcept(ALL_EXCEPTS);
+ ASSERT_EQ(s, ALL_EXCEPTS);
}
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the patch! Mind adding a |check|
in libc/docs/c23.rst? We're about to refactor our docs anyways.
@aniplcc do you need us to merge this for you? |
Yes I do, thanks! |
Closes #87564