Skip to content

Commit 4ee8e6a

Browse files
committed
Resolve llvm#106
1 parent 94d7a64 commit 4ee8e6a

File tree

6 files changed

+23
-26
lines changed

6 files changed

+23
-26
lines changed

filc/include/pizlonated_math.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ long double zmath_log1pl(long double value);
6363
long double zmath_nearbyintl(long double value);
6464
unsigned zmath_getcw(void);
6565
void zmath_setcw(unsigned cw);
66+
void zmath_feclearexcept(int excepts);
6667

6768
#ifdef __cplusplus
6869
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include <fenv.h>
2+
3+
int main()
4+
{
5+
feclearexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW);
6+
return 0;
7+
}
8+

filc/tests/feclearexcept/manifest

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
return:
2+
success
3+
extraLinkerArgs:
4+
"-lm"

libpas/src/libpas/filc_runtime.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
#include <sys/statvfs.h>
104104
#include <sys/reboot.h>
105105
#include <linux/keyctl.h>
106+
#include <fenv.h>
106107

107108
#if PAS_GLIBC
108109
#include <sys/pidfd.h>
@@ -13166,6 +13167,12 @@ void filc_native_zmath_setcw(filc_thread* my_thread, unsigned cw)
1316613167
asm volatile ("fldcw %0" : : "m"(cw));
1316713168
}
1316813169

13170+
void filc_native_zmath_feclearexcept(filc_thread* my_thread, int excepts)
13171+
{
13172+
PAS_UNUSED_PARAM(my_thread);
13173+
PAS_ASSERT(!feclearexcept(excepts));
13174+
}
13175+
1316913176
#endif /* PAS_ENABLE_FILC */
1317013177

1317113178
#endif /* LIBPAS_ENABLED */

libpas/src/libpas/generate_pizlonated_forwarders.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,7 @@ def addOutSig(name, rets, *args)
557557
addSig "long double", "zmath_nearbyintl", "long double"
558558
addSig "unsigned", "zmath_getcw"
559559
addSig "void", "zmath_setcw", "unsigned"
560+
addSig "void", "zmath_feclearexcept", "int"
560561

561562
addOutSig "void_ptr_ptr", "void", "filc_ptr", "filc_ptr"
562563
addOutSig "main", "exception/int", "int", "filc_ptr", "filc_ptr"

projects/user-glibc-2.40/sysdeps/x86_64/fpu/fclrexcpt.c

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,36 +17,12 @@
1717
<https://www.gnu.org/licenses/>. */
1818

1919
#include <fenv.h>
20+
#include <pizlonated_math.h>
2021

2122
int
2223
feclearexcept (int excepts)
2324
{
24-
fenv_t temp;
25-
unsigned int mxcsr;
26-
27-
/* Mask out unsupported bits/exceptions. */
28-
excepts &= FE_ALL_EXCEPT;
29-
30-
/* Bah, we have to clear selected exceptions. Since there is no
31-
`fldsw' instruction we have to do it the hard way. */
32-
__asm__ ("fnstenv %0" : "=m" (*&temp));
33-
34-
/* Clear the relevant bits. */
35-
temp.__status_word &= excepts ^ FE_ALL_EXCEPT;
36-
37-
/* Put the new data in effect. */
38-
__asm__ ("fldenv %0" : : "m" (*&temp));
39-
40-
/* And the same procedure for SSE. */
41-
__asm__ ("stmxcsr %0" : "=m" (*&mxcsr));
42-
43-
/* Clear the relevant bits. */
44-
mxcsr &= ~excepts;
45-
46-
/* And put them into effect. */
47-
__asm__ ("ldmxcsr %0" : : "m" (*&mxcsr));
48-
49-
/* Success. */
25+
zmath_feclearexcept(excepts);
5026
return 0;
5127
}
5228
libm_hidden_def (feclearexcept)

0 commit comments

Comments
 (0)