[libc-commits] [libc] [llvm] [libc][c23][fenv] Implement fetestexceptflag (PR #87828)
Robin Caloudis via libc-commits
libc-commits at lists.llvm.org
Fri Apr 5 14:10:00 PDT 2024
https://github.com/robincaloudis created https://github.com/llvm/llvm-project/pull/87828
Closes https://github.com/llvm/llvm-project/issues/87565.
>From 11a45e392c13e3c1f86e28129282d8c409355d14 Mon Sep 17 00:00:00 2001
From: Robin Caloudis <robin.caloudis at gmx.de>
Date: Fri, 5 Apr 2024 23:07:50 +0200
Subject: [PATCH] [libc][c23][fenv] Implement fetestexceptflag
---
libc/config/baremetal/arm/entrypoints.txt | 1 +
libc/config/baremetal/riscv/entrypoints.txt | 1 +
libc/config/darwin/arm/entrypoints.txt | 1 +
libc/config/darwin/x86_64/entrypoints.txt | 1 +
libc/config/linux/aarch64/entrypoints.txt | 1 +
libc/config/linux/arm/entrypoints.txt | 1 +
libc/config/linux/riscv/entrypoints.txt | 1 +
libc/config/linux/x86_64/entrypoints.txt | 1 +
libc/config/windows/entrypoints.txt | 1 +
libc/docs/c23.rst | 2 +-
libc/spec/stdc.td | 5 ++++
libc/src/fenv/CMakeLists.txt | 13 ++++++++++
libc/src/fenv/fetestexceptflag.cpp | 24 +++++++++++++++++++
libc/src/fenv/fetestexceptflag.h | 20 ++++++++++++++++
libc/test/src/fenv/CMakeLists.txt | 1 +
libc/test/src/fenv/exception_flags_test.cpp | 4 +++-
.../llvm-project-overlay/libc/BUILD.bazel | 10 ++++++++
.../libc/test/src/fenv/BUILD.bazel | 1 +
18 files changed, 87 insertions(+), 2 deletions(-)
create mode 100644 libc/src/fenv/fetestexceptflag.cpp
create mode 100644 libc/src/fenv/fetestexceptflag.h
diff --git a/libc/config/baremetal/arm/entrypoints.txt b/libc/config/baremetal/arm/entrypoints.txt
index 9e21f5c20d9207..c4681857083a90 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -200,6 +200,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.fenv.fesetround
libc.src.fenv.feraiseexcept
libc.src.fenv.fetestexcept
+ libc.src.fenv.fetestexceptflag
libc.src.fenv.feupdateenv
# math.h entrypoints
diff --git a/libc/config/baremetal/riscv/entrypoints.txt b/libc/config/baremetal/riscv/entrypoints.txt
index 7664937da0f6e0..1efc2301814bf5 100644
--- a/libc/config/baremetal/riscv/entrypoints.txt
+++ b/libc/config/baremetal/riscv/entrypoints.txt
@@ -200,6 +200,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.fenv.fesetround
libc.src.fenv.feraiseexcept
libc.src.fenv.fetestexcept
+ libc.src.fenv.fetestexceptflag
libc.src.fenv.feupdateenv
# math.h entrypoints
diff --git a/libc/config/darwin/arm/entrypoints.txt b/libc/config/darwin/arm/entrypoints.txt
index 6b89ce55d72b65..598139feaa8fee 100644
--- a/libc/config/darwin/arm/entrypoints.txt
+++ b/libc/config/darwin/arm/entrypoints.txt
@@ -111,6 +111,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.fenv.fesetround
libc.src.fenv.feraiseexcept
libc.src.fenv.fetestexcept
+ libc.src.fenv.fetestexceptflag
libc.src.fenv.feupdateenv
# math.h entrypoints
diff --git a/libc/config/darwin/x86_64/entrypoints.txt b/libc/config/darwin/x86_64/entrypoints.txt
index 5a1a6a15ef30c0..84e3a877859194 100644
--- a/libc/config/darwin/x86_64/entrypoints.txt
+++ b/libc/config/darwin/x86_64/entrypoints.txt
@@ -105,6 +105,7 @@ set(TARGET_LIBM_ENTRYPOINTS
# libc.src.fenv.fesetround
# libc.src.fenv.feraiseexcept
# libc.src.fenv.fetestexcept
+ # libc.src.fenv.fetestexceptflag
# libc.src.fenv.feupdateenv
## Currently disabled for failing tests.
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 8bf99459f7898d..607e6cb1e1a4af 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -323,6 +323,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.fenv.fesetround
libc.src.fenv.feraiseexcept
libc.src.fenv.fetestexcept
+ libc.src.fenv.fetestexceptflag
libc.src.fenv.feupdateenv
# math.h entrypoints
diff --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt
index 04baa4c1cf93ab..927b629c7a284a 100644
--- a/libc/config/linux/arm/entrypoints.txt
+++ b/libc/config/linux/arm/entrypoints.txt
@@ -191,6 +191,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.fenv.fesetround
libc.src.fenv.feraiseexcept
libc.src.fenv.fetestexcept
+ libc.src.fenv.fetestexceptflag
libc.src.fenv.feupdateenv
# math.h entrypoints
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 4dc5e9d33f0f84..9db724f485175e 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -331,6 +331,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.fenv.fesetround
libc.src.fenv.feraiseexcept
libc.src.fenv.fetestexcept
+ libc.src.fenv.fetestexceptflag
libc.src.fenv.feupdateenv
# math.h entrypoints
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index b522e7f0301544..f82d653db64301 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -341,6 +341,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.fenv.fesetround
libc.src.fenv.feraiseexcept
libc.src.fenv.fetestexcept
+ libc.src.fenv.fetestexceptflag
libc.src.fenv.feupdateenv
# math.h entrypoints
diff --git a/libc/config/windows/entrypoints.txt b/libc/config/windows/entrypoints.txt
index c38125a6462272..72934421e9e5c9 100644
--- a/libc/config/windows/entrypoints.txt
+++ b/libc/config/windows/entrypoints.txt
@@ -109,6 +109,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.fenv.fesetround
libc.src.fenv.feraiseexcept
libc.src.fenv.fetestexcept
+ libc.src.fenv.fetestexceptflag
libc.src.fenv.feupdateenv
# math.h entrypoints
diff --git a/libc/docs/c23.rst b/libc/docs/c23.rst
index 152178eaf751e2..fd515653096c45 100644
--- a/libc/docs/c23.rst
+++ b/libc/docs/c23.rst
@@ -21,7 +21,7 @@ Additions:
* fenv.h
* fesetexcept
- * fetestexceptflag
+ * fetestexceptflag |check|
* fegetmode
* fesetmode
* math.h
diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td
index bd62870b07c89c..a17f5081224362 100644
--- a/libc/spec/stdc.td
+++ b/libc/spec/stdc.td
@@ -149,6 +149,11 @@ def StdC : StandardSpec<"stdc"> {
RetValSpec<IntType>,
[ArgSpec<IntType>]
>,
+ FunctionSpec<
+ "fetestexceptflag",
+ RetValSpec<IntType>,
+ [ArgSpec<ConstFExceptTPtr>, ArgSpec<IntType>]
+ >,
FunctionSpec<
"feraiseexcept",
RetValSpec<IntType>,
diff --git a/libc/src/fenv/CMakeLists.txt b/libc/src/fenv/CMakeLists.txt
index 0da539d187bfa1..24520ec349feca 100644
--- a/libc/src/fenv/CMakeLists.txt
+++ b/libc/src/fenv/CMakeLists.txt
@@ -63,6 +63,19 @@ add_entrypoint_object(
-O2
)
+add_entrypoint_object(
+ fetestexceptflag
+ SRCS
+ fetestexceptflag.cpp
+ HDRS
+ fetestexceptflag.h
+ DEPENDS
+ libc.include.fenv
+ libc.src.__support.FPUtil.fenv_impl
+ COMPILE_OPTIONS
+ -O2
+)
+
add_entrypoint_object(
fegetenv
SRCS
diff --git a/libc/src/fenv/fetestexceptflag.cpp b/libc/src/fenv/fetestexceptflag.cpp
new file mode 100644
index 00000000000000..35760caa158e28
--- /dev/null
+++ b/libc/src/fenv/fetestexceptflag.cpp
@@ -0,0 +1,24 @@
+//===-- Implementation of fesetexceptflag 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/fesetexceptflag.h"
+#include "src/__support/FPUtil/FEnvImpl.h"
+#include "src/__support/common.h"
+
+#include <fenv.h>
+
+namespace LIBC_NAMESPACE {
+
+LLVM_LIBC_FUNCTION(int, fetestexceptflag,
+ (const fexcept_t *flagp, int excepts)) {
+ static_assert(sizeof(int) >= sizeof(fexcept_t),
+ "fexcept_t value cannot fit in an int value.");
+ return static_cast<int>(*flagp) | excepts;
+}
+
+} // namespace LIBC_NAMESPACE
diff --git a/libc/src/fenv/fetestexceptflag.h b/libc/src/fenv/fetestexceptflag.h
new file mode 100644
index 00000000000000..a11d904ac7865c
--- /dev/null
+++ b/libc/src/fenv/fetestexceptflag.h
@@ -0,0 +1,20 @@
+//===-- Implementation header for fesetexceptflag ---------------*- 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_FESETEXCEPTFLAG_H
+#define LLVM_LIBC_SRC_FENV_FESETEXCEPTFLAG_H
+
+#include <fenv.h>
+
+namespace LIBC_NAMESPACE {
+
+int fetestexceptflag(const fexcept_t *, int excepts);
+
+} // namespace LIBC_NAMESPACE
+
+#endif // LLVM_LIBC_SRC_FENV_FESETEXCEPTFLAG_H
diff --git a/libc/test/src/fenv/CMakeLists.txt b/libc/test/src/fenv/CMakeLists.txt
index ba338bb6c73189..7f213dabec06f4 100644
--- a/libc/test/src/fenv/CMakeLists.txt
+++ b/libc/test/src/fenv/CMakeLists.txt
@@ -47,6 +47,7 @@ add_libc_unittest(
DEPENDS
libc.src.fenv.fegetexceptflag
libc.src.fenv.fesetexceptflag
+ libc.src.fenv.fetestexceptflag
libc.src.__support.FPUtil.fenv_impl
)
diff --git a/libc/test/src/fenv/exception_flags_test.cpp b/libc/test/src/fenv/exception_flags_test.cpp
index 434adc06b1a36a..c1a24bc7700e3d 100644
--- a/libc/test/src/fenv/exception_flags_test.cpp
+++ b/libc/test/src/fenv/exception_flags_test.cpp
@@ -1,4 +1,5 @@
-//===-- Unittests for fegetexceptflag and fesetexceptflag -----------------===//
+//===-- Unittests for fegetexceptflag, fesetexceptflag and ----------------===//
+//===-- fetestexceptflag --------------------------------------------------===//
//
// 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/fegetexceptflag.h"
#include "src/fenv/fesetexceptflag.h"
+#include "src/fenv/fetestexceptflag.h"
#include "src/__support/FPUtil/FEnvImpl.h"
#include "test/UnitTest/Test.h"
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 42af5cbe8f35f4..59ea1774badb0d 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -1094,6 +1094,16 @@ libc_function(
],
)
+libc_function(
+ name = "fetestexceptflag",
+ srcs = ["src/fenv/fetestexceptflag.cpp"],
+ hdrs = ["src/fenv/fetestexceptflag.h"],
+ deps = [
+ ":__support_common",
+ ":__support_fputil_fenv_impl",
+ ],
+)
+
libc_function(
name = "feclearexcept",
srcs = ["src/fenv/feclearexcept.cpp"],
diff --git a/utils/bazel/llvm-project-overlay/libc/test/src/fenv/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/test/src/fenv/BUILD.bazel
index f64f78c113c01e..f1aa5961e63be1 100644
--- a/utils/bazel/llvm-project-overlay/libc/test/src/fenv/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/test/src/fenv/BUILD.bazel
@@ -70,6 +70,7 @@ libc_test(
libc_function_deps = [
"//libc:fegetexceptflag",
"//libc:fesetexceptflag",
+ "//libc:fetestexceptflag",
],
deps = [
"//libc:__support_fputil_fenv_impl",
More information about the libc-commits
mailing list