Skip to content

Commit e519ae9

Browse files
committed
Fix get_except and include FE_DENORM in FE_ALL_EXCEPT.
1 parent d8dfeae commit e519ae9

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

libc/include/llvm-libc-macros/fenv-macros.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
#define FE_INVALID 0x4
1515
#define FE_OVERFLOW 0x8
1616
#define FE_UNDERFLOW 0x10
17-
#define __FE_DENORM 0x20
17+
#define FE_DENORM 0x20
1818
#define FE_ALL_EXCEPT \
19-
(FE_DIVBYZERO | FE_INEXACT | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW)
19+
(FE_DIVBYZERO | FE_INEXACT | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW | \
20+
FE_DENORM)
2021

2122
#define FE_DOWNWARD 0x400
2223
#define FE_TONEAREST 0

libc/src/__support/FPUtil/x86_64/fenv_mxcsr_utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ LIBC_INLINE static uint16_t test_except(uint16_t excepts) {
7171
}
7272

7373
LIBC_INLINE static uint16_t get_except() {
74-
uint32_t mxcsr = get_mxcsr();
74+
uint32_t mxcsr = ~get_mxcsr();
7575
return static_cast<uint16_t>((mxcsr >> ExceptionFlags::MXCSR_EXCEPTION_MASK_BIT_POSITION) & ExceptionFlags::ALL_F);
7676
}
7777

libc/src/__support/FPUtil/x86_64/fenv_x86_common.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ LIBC_INLINE static constexpr bool fenv_exceptions_match_x86() {
4949
return (FE_INVALID == ExceptionFlags::INVALID_F) &&
5050
#ifdef __FE_DENORM
5151
(__FE_DENORM == ExceptionFlags::DENORMAL_F) &&
52+
#elif defined(FE_DENORM)
53+
(FE_DENORM == ExceptionFlags::DENORMAL_F) &&
5254
#endif // __FE_DENORM
5355
(FE_DIVBYZERO == ExceptionFlags::DIV_BY_ZERO_F) &&
5456
(FE_OVERFLOW == ExceptionFlags::OVERFLOW_F) &&
@@ -87,6 +89,8 @@ LIBC_INLINE static uint16_t get_status_value_from_except(int excepts) {
8789
return ((excepts & FE_INVALID) ? ExceptionFlags::INVALID_F : 0) |
8890
#ifdef __FE_DENORM
8991
((excepts & __FE_DENORM) ? ExceptionFlags::DENORMAL_F : 0) |
92+
#elif defined(FE_DENORM)
93+
((excepts & FE_DENORM) ? ExceptionFlags::DENORMAL_F : 0) |
9094
#endif // __FE_DENORM
9195
((excepts & FE_DIVBYZERO) ? ExceptionFlags::DIV_BY_ZERO_F : 0) |
9296
((excepts & FE_OVERFLOW) ? ExceptionFlags::OVERFLOW_F : 0) |
@@ -102,6 +106,8 @@ LIBC_INLINE static int get_macro_from_exception_status(uint16_t status) {
102106
return ((status & ExceptionFlags::INVALID_F) ? FE_INVALID : 0) |
103107
#ifdef __FE_DENORM
104108
((status & ExceptionFlags::DENORMAL_F) ? __FE_DENORM : 0) |
109+
#elif defined(FE_DENORM)
110+
((status & ExceptionFlags::DENORMAL_F) ? FE_DENORM : 0) |
105111
#endif // __FE_DENORM
106112
((status & ExceptionFlags::DIV_BY_ZERO_F) ? FE_DIVBYZERO : 0) |
107113
((status & ExceptionFlags::OVERFLOW_F) ? FE_OVERFLOW : 0) |

libc/src/__support/FPUtil/x86_64/fenv_x87_utils.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ LIBC_INLINE static uint16_t test_except(uint16_t excepts) {
113113
}
114114

115115
LIBC_INLINE static uint16_t get_except() {
116-
uint16_t x87_status = get_x87_control_word();
117-
return static_cast<uint16_t>(x87_status & ExceptionFlags::ALL_F);
116+
uint16_t x87_control = get_x87_control_word();
117+
return static_cast<uint16_t>((~x87_control) & ExceptionFlags::ALL_F);
118118
}
119119

120120
LIBC_INLINE static void set_except(uint16_t excepts) {

0 commit comments

Comments
 (0)