Skip to content

Commit d9f362f

Browse files
committed
[libc][c23][fenv] Implement fetestexceptflag
1 parent 0a39f1a commit d9f362f

File tree

18 files changed

+87
-2
lines changed

18 files changed

+87
-2
lines changed

libc/config/baremetal/arm/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ set(TARGET_LIBM_ENTRYPOINTS
201201
libc.src.fenv.fesetround
202202
libc.src.fenv.feraiseexcept
203203
libc.src.fenv.fetestexcept
204+
libc.src.fenv.fetestexceptflag
204205
libc.src.fenv.feupdateenv
205206

206207
# math.h entrypoints

libc/config/baremetal/riscv/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ set(TARGET_LIBM_ENTRYPOINTS
201201
libc.src.fenv.fesetround
202202
libc.src.fenv.feraiseexcept
203203
libc.src.fenv.fetestexcept
204+
libc.src.fenv.fetestexceptflag
204205
libc.src.fenv.feupdateenv
205206

206207
# math.h entrypoints

libc/config/darwin/arm/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ set(TARGET_LIBM_ENTRYPOINTS
112112
libc.src.fenv.fesetround
113113
libc.src.fenv.feraiseexcept
114114
libc.src.fenv.fetestexcept
115+
libc.src.fenv.fetestexceptflag
115116
libc.src.fenv.feupdateenv
116117

117118
# math.h entrypoints

libc/config/darwin/x86_64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ set(TARGET_LIBM_ENTRYPOINTS
106106
# libc.src.fenv.fesetround
107107
# libc.src.fenv.feraiseexcept
108108
# libc.src.fenv.fetestexcept
109+
# libc.src.fenv.fetestexceptflag
109110
# libc.src.fenv.feupdateenv
110111

111112
## Currently disabled for failing tests.

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ set(TARGET_LIBM_ENTRYPOINTS
324324
libc.src.fenv.fesetround
325325
libc.src.fenv.feraiseexcept
326326
libc.src.fenv.fetestexcept
327+
libc.src.fenv.fetestexceptflag
327328
libc.src.fenv.feupdateenv
328329

329330
# math.h entrypoints

libc/config/linux/arm/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ set(TARGET_LIBM_ENTRYPOINTS
192192
libc.src.fenv.fesetround
193193
libc.src.fenv.feraiseexcept
194194
libc.src.fenv.fetestexcept
195+
libc.src.fenv.fetestexceptflag
195196
libc.src.fenv.feupdateenv
196197

197198
# math.h entrypoints

libc/config/linux/riscv/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ set(TARGET_LIBM_ENTRYPOINTS
332332
libc.src.fenv.fesetround
333333
libc.src.fenv.feraiseexcept
334334
libc.src.fenv.fetestexcept
335+
libc.src.fenv.fetestexceptflag
335336
libc.src.fenv.feupdateenv
336337

337338
# math.h entrypoints

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ set(TARGET_LIBM_ENTRYPOINTS
342342
libc.src.fenv.fesetround
343343
libc.src.fenv.feraiseexcept
344344
libc.src.fenv.fetestexcept
345+
libc.src.fenv.fetestexceptflag
345346
libc.src.fenv.feupdateenv
346347

347348
# math.h entrypoints

libc/config/windows/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ set(TARGET_LIBM_ENTRYPOINTS
110110
libc.src.fenv.fesetround
111111
libc.src.fenv.feraiseexcept
112112
libc.src.fenv.fetestexcept
113+
libc.src.fenv.fetestexceptflag
113114
libc.src.fenv.feupdateenv
114115

115116
# math.h entrypoints

libc/docs/c23.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Additions:
2121
* fenv.h
2222

2323
* fesetexcept |check|
24-
* fetestexceptflag
24+
* fetestexceptflag |check|
2525
* fegetmode
2626
* fesetmode
2727
* math.h

libc/spec/stdc.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ def StdC : StandardSpec<"stdc"> {
149149
RetValSpec<IntType>,
150150
[ArgSpec<IntType>]
151151
>,
152+
FunctionSpec<
153+
"fetestexceptflag",
154+
RetValSpec<IntType>,
155+
[ArgSpec<ConstFExceptTPtr>, ArgSpec<IntType>]
156+
>,
152157
FunctionSpec<
153158
"feraiseexcept",
154159
RetValSpec<IntType>,

libc/src/fenv/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,19 @@ add_entrypoint_object(
6363
-O2
6464
)
6565

66+
add_entrypoint_object(
67+
fetestexceptflag
68+
SRCS
69+
fetestexceptflag.cpp
70+
HDRS
71+
fetestexceptflag.h
72+
DEPENDS
73+
libc.include.fenv
74+
libc.src.__support.FPUtil.fenv_impl
75+
COMPILE_OPTIONS
76+
-O2
77+
)
78+
6679
add_entrypoint_object(
6780
fegetenv
6881
SRCS

libc/src/fenv/fetestexceptflag.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//===-- Implementation of fesetexceptflag function ------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "src/fenv/fesetexceptflag.h"
10+
#include "src/__support/FPUtil/FEnvImpl.h"
11+
#include "src/__support/common.h"
12+
13+
#include <fenv.h>
14+
15+
namespace LIBC_NAMESPACE {
16+
17+
LLVM_LIBC_FUNCTION(int, fetestexceptflag,
18+
(const fexcept_t *flagp, int excepts)) {
19+
static_assert(sizeof(int) >= sizeof(fexcept_t),
20+
"fexcept_t value cannot fit in an int value.");
21+
return static_cast<int>(*flagp) & excepts;
22+
}
23+
24+
} // namespace LIBC_NAMESPACE

libc/src/fenv/fetestexceptflag.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===-- Implementation header for fesetexceptflag ---------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_SRC_FENV_FESETEXCEPTFLAG_H
10+
#define LLVM_LIBC_SRC_FENV_FESETEXCEPTFLAG_H
11+
12+
#include <fenv.h>
13+
14+
namespace LIBC_NAMESPACE {
15+
16+
int fetestexceptflag(const fexcept_t *, int excepts);
17+
18+
} // namespace LIBC_NAMESPACE
19+
20+
#endif // LLVM_LIBC_SRC_FENV_FESETEXCEPTFLAG_H

libc/test/src/fenv/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ add_libc_unittest(
4848
DEPENDS
4949
libc.src.fenv.fegetexceptflag
5050
libc.src.fenv.fesetexceptflag
51+
libc.src.fenv.fetestexceptflag
5152
libc.src.__support.FPUtil.fenv_impl
5253
)
5354

libc/test/src/fenv/exception_flags_test.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
//===-- Unittests for fegetexceptflag and fesetexceptflag -----------------===//
1+
//===-- Unittests for fegetexceptflag, fesetexceptflag and ----------------===//
2+
//===-- fetestexceptflag --------------------------------------------------===//
23
//
34
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
45
// See https://llvm.org/LICENSE.txt for license information.
@@ -8,6 +9,7 @@
89

910
#include "src/fenv/fegetexceptflag.h"
1011
#include "src/fenv/fesetexceptflag.h"
12+
#include "src/fenv/fetestexceptflag.h"
1113

1214
#include "src/__support/FPUtil/FEnvImpl.h"
1315
#include "test/UnitTest/Test.h"

utils/bazel/llvm-project-overlay/libc/BUILD.bazel

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,6 +1094,16 @@ libc_function(
10941094
],
10951095
)
10961096

1097+
libc_function(
1098+
name = "fetestexceptflag",
1099+
srcs = ["src/fenv/fetestexceptflag.cpp"],
1100+
hdrs = ["src/fenv/fetestexceptflag.h"],
1101+
deps = [
1102+
":__support_common",
1103+
":__support_fputil_fenv_impl",
1104+
],
1105+
)
1106+
10971107
libc_function(
10981108
name = "feclearexcept",
10991109
srcs = ["src/fenv/feclearexcept.cpp"],

utils/bazel/llvm-project-overlay/libc/test/src/fenv/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ libc_test(
7171
libc_function_deps = [
7272
"//libc:fegetexceptflag",
7373
"//libc:fesetexceptflag",
74+
"//libc:fetestexceptflag",
7475
],
7576
deps = [
7677
"//libc:__support_fputil_fenv_impl",

0 commit comments

Comments
 (0)