@@ -48,15 +48,15 @@ static constexpr uint16_t MXCSR_ROUNDING_CONTROL_BIT_POSITION = 13;
48
48
// The exception flags in the x87 status register and the MXCSR have the same
49
49
// encoding as well as the same bit positions.
50
50
struct ExceptionFlags {
51
- static constexpr uint16_t INVALID = 0x1 ;
51
+ static constexpr uint16_t INVALID_F = 0x1 ;
52
52
// Some libcs define __FE_DENORM corresponding to the denormal input
53
53
// exception and include it in FE_ALL_EXCEPTS. We define and use it to
54
54
// support compiling against headers provided by such libcs.
55
- static constexpr uint16_t DENORMAL = 0x2 ;
56
- static constexpr uint16_t DIV_BY_ZERO = 0x4 ;
57
- static constexpr uint16_t OVERFLOW = 0x8 ;
58
- static constexpr uint16_t UNDERFLOW = 0x10 ;
59
- static constexpr uint16_t INEXACT = 0x20 ;
55
+ static constexpr uint16_t DENORMAL_F = 0x2 ;
56
+ static constexpr uint16_t DIV_BY_ZERO_F = 0x4 ;
57
+ static constexpr uint16_t OVERFLOW_F = 0x8 ;
58
+ static constexpr uint16_t UNDERFLOW_F = 0x10 ;
59
+ static constexpr uint16_t INEXACT_F = 0x20 ;
60
60
};
61
61
62
62
// The exception control bits occupy six bits, one bit for each exception.
@@ -71,25 +71,25 @@ static constexpr uint16_t MXCSR_EXCEPTION_CONTOL_BIT_POISTION = 7;
71
71
static inline uint16_t get_status_value_for_except (int excepts) {
72
72
// We will make use of the fact that exception control bits are single
73
73
// bit flags in the control registers.
74
- return (excepts & FE_INVALID ? ExceptionFlags::INVALID : 0 ) |
74
+ return (excepts & FE_INVALID ? ExceptionFlags::INVALID_F : 0 ) |
75
75
#ifdef __FE_DENORM
76
- (excepts & __FE_DENORM ? ExceptionFlags::DENORMAL : 0 ) |
76
+ (excepts & __FE_DENORM ? ExceptionFlags::DENORMAL_F : 0 ) |
77
77
#endif // __FE_DENORM
78
- (excepts & FE_DIVBYZERO ? ExceptionFlags::DIV_BY_ZERO : 0 ) |
79
- (excepts & FE_OVERFLOW ? ExceptionFlags::OVERFLOW : 0 ) |
80
- (excepts & FE_UNDERFLOW ? ExceptionFlags::UNDERFLOW : 0 ) |
81
- (excepts & FE_INEXACT ? ExceptionFlags::INEXACT : 0 );
78
+ (excepts & FE_DIVBYZERO ? ExceptionFlags::DIV_BY_ZERO_F : 0 ) |
79
+ (excepts & FE_OVERFLOW ? ExceptionFlags::OVERFLOW_F : 0 ) |
80
+ (excepts & FE_UNDERFLOW ? ExceptionFlags::UNDERFLOW_F : 0 ) |
81
+ (excepts & FE_INEXACT ? ExceptionFlags::INEXACT_F : 0 );
82
82
}
83
83
84
84
static inline int exception_status_to_macro (uint16_t status) {
85
- return (status & ExceptionFlags::INVALID ? FE_INVALID : 0 ) |
85
+ return (status & ExceptionFlags::INVALID_F ? FE_INVALID : 0 ) |
86
86
#ifdef __FE_DENORM
87
- (status & ExceptionFlags::DENORMAL ? __FE_DENORM : 0 ) |
87
+ (status & ExceptionFlags::DENORMAL_F ? __FE_DENORM : 0 ) |
88
88
#endif // __FE_DENORM
89
- (status & ExceptionFlags::DIV_BY_ZERO ? FE_DIVBYZERO : 0 ) |
90
- (status & ExceptionFlags::OVERFLOW ? FE_OVERFLOW : 0 ) |
91
- (status & ExceptionFlags::UNDERFLOW ? FE_UNDERFLOW : 0 ) |
92
- (status & ExceptionFlags::INEXACT ? FE_INEXACT : 0 );
89
+ (status & ExceptionFlags::DIV_BY_ZERO_F ? FE_DIVBYZERO : 0 ) |
90
+ (status & ExceptionFlags::OVERFLOW_F ? FE_OVERFLOW : 0 ) |
91
+ (status & ExceptionFlags::UNDERFLOW_F ? FE_UNDERFLOW : 0 ) |
92
+ (status & ExceptionFlags::INEXACT_F ? FE_INEXACT : 0 );
93
93
}
94
94
95
95
struct X87StateDescriptor {
@@ -263,19 +263,19 @@ static inline int raise_except(int excepts) {
263
263
internal::fwait ();
264
264
};
265
265
266
- if (status_value & internal::ExceptionFlags::INVALID )
267
- raise_helper (internal::ExceptionFlags::INVALID );
268
- if (status_value & internal::ExceptionFlags::DIV_BY_ZERO )
269
- raise_helper (internal::ExceptionFlags::DIV_BY_ZERO );
270
- if (status_value & internal::ExceptionFlags::OVERFLOW )
271
- raise_helper (internal::ExceptionFlags::OVERFLOW );
272
- if (status_value & internal::ExceptionFlags::UNDERFLOW )
273
- raise_helper (internal::ExceptionFlags::UNDERFLOW );
274
- if (status_value & internal::ExceptionFlags::INEXACT )
275
- raise_helper (internal::ExceptionFlags::INEXACT );
266
+ if (status_value & internal::ExceptionFlags::INVALID_F )
267
+ raise_helper (internal::ExceptionFlags::INVALID_F );
268
+ if (status_value & internal::ExceptionFlags::DIV_BY_ZERO_F )
269
+ raise_helper (internal::ExceptionFlags::DIV_BY_ZERO_F );
270
+ if (status_value & internal::ExceptionFlags::OVERFLOW_F )
271
+ raise_helper (internal::ExceptionFlags::OVERFLOW_F );
272
+ if (status_value & internal::ExceptionFlags::UNDERFLOW_F )
273
+ raise_helper (internal::ExceptionFlags::UNDERFLOW_F );
274
+ if (status_value & internal::ExceptionFlags::INEXACT_F )
275
+ raise_helper (internal::ExceptionFlags::INEXACT_F );
276
276
#ifdef __FE_DENORM
277
- if (status_value & internal::ExceptionFlags::DENORMAL ) {
278
- raise_helper (internal::ExceptionFlags::DENORMAL );
277
+ if (status_value & internal::ExceptionFlags::DENORMAL_F ) {
278
+ raise_helper (internal::ExceptionFlags::DENORMAL_F );
279
279
}
280
280
#endif // __FE_DENORM
281
281
@@ -371,24 +371,24 @@ static_assert(
371
371
// The exception flags in the Windows FEnv struct and the MXCSR have almost
372
372
// reversed bit positions.
373
373
struct WinExceptionFlags {
374
- static constexpr uint32_t INEXACT = 0x01 ;
375
- static constexpr uint32_t UNDERFLOW = 0x02 ;
376
- static constexpr uint32_t OVERFLOW = 0x04 ;
377
- static constexpr uint32_t DIV_BY_ZERO = 0x08 ;
378
- static constexpr uint32_t INVALID = 0x10 ;
379
- static constexpr uint32_t DENORMAL = 0x20 ;
374
+ static constexpr uint32_t INEXACT_WIN = 0x01 ;
375
+ static constexpr uint32_t UNDERFLOW_WIN = 0x02 ;
376
+ static constexpr uint32_t OVERFLOW_WIN = 0x04 ;
377
+ static constexpr uint32_t DIV_BY_ZERO_WIN = 0x08 ;
378
+ static constexpr uint32_t INVALID_WIN = 0x10 ;
379
+ static constexpr uint32_t DENORMAL_WIN = 0x20 ;
380
380
381
381
// The Windows FEnv struct has a second copy of all of these bits in the high
382
382
// byte of the 32 bit control word. These are used as the source of truth when
383
383
// calling fesetenv.
384
384
static constexpr uint32_t HIGH_OFFSET = 24 ;
385
385
386
- static constexpr uint32_t HIGH_INEXACT = INEXACT << HIGH_OFFSET;
387
- static constexpr uint32_t HIGH_UNDERFLOW = UNDERFLOW << HIGH_OFFSET;
388
- static constexpr uint32_t HIGH_OVERFLOW = OVERFLOW << HIGH_OFFSET;
389
- static constexpr uint32_t HIGH_DIV_BY_ZERO = DIV_BY_ZERO << HIGH_OFFSET;
390
- static constexpr uint32_t HIGH_INVALID = INVALID << HIGH_OFFSET;
391
- static constexpr uint32_t HIGH_DENORMAL = DENORMAL << HIGH_OFFSET;
386
+ static constexpr uint32_t HIGH_INEXACT = INEXACT_WIN << HIGH_OFFSET;
387
+ static constexpr uint32_t HIGH_UNDERFLOW = UNDERFLOW_WIN << HIGH_OFFSET;
388
+ static constexpr uint32_t HIGH_OVERFLOW = OVERFLOW_WIN << HIGH_OFFSET;
389
+ static constexpr uint32_t HIGH_DIV_BY_ZERO = DIV_BY_ZERO_WIN << HIGH_OFFSET;
390
+ static constexpr uint32_t HIGH_INVALID = INVALID_WIN << HIGH_OFFSET;
391
+ static constexpr uint32_t HIGH_DENORMAL = DENORMAL_WIN << HIGH_OFFSET;
392
392
};
393
393
394
394
/*
@@ -470,25 +470,24 @@ static inline int get_env(fenv_t *envp) {
470
470
uint32_t mxcsr = internal::get_mxcsr ();
471
471
472
472
// Set exception flags in the status word
473
- status_word |= (mxcsr & (internal::ExceptionFlags::INVALID |
474
- internal::ExceptionFlags::DENORMAL ))
473
+ status_word |= (mxcsr & (internal::ExceptionFlags::INVALID_F |
474
+ internal::ExceptionFlags::DENORMAL_F ))
475
475
<< 4 ;
476
- status_word |= (mxcsr & internal::ExceptionFlags::DIV_BY_ZERO ) << 1 ;
477
- status_word |= (mxcsr & internal::ExceptionFlags::OVERFLOW ) >> 1 ;
478
- status_word |= (mxcsr & internal::ExceptionFlags::UNDERFLOW ) >> 3 ;
479
- status_word |= (mxcsr & internal::ExceptionFlags::INEXACT ) >> 5 ;
476
+ status_word |= (mxcsr & internal::ExceptionFlags::DIV_BY_ZERO_F ) << 1 ;
477
+ status_word |= (mxcsr & internal::ExceptionFlags::OVERFLOW_F ) >> 1 ;
478
+ status_word |= (mxcsr & internal::ExceptionFlags::UNDERFLOW_F ) >> 3 ;
479
+ status_word |= (mxcsr & internal::ExceptionFlags::INEXACT_F ) >> 5 ;
480
480
status_word |= status_word << WinExceptionFlags::HIGH_OFFSET;
481
481
482
482
// Set exception masks in bits 0-5 and 24-29
483
- control_word |=
484
- (mxcsr &
485
- ((internal::ExceptionFlags::INVALID | internal::ExceptionFlags::DENORMAL)
486
- << 7 )) >>
487
- 3 ;
488
- control_word |= (mxcsr & (internal::ExceptionFlags::DIV_BY_ZERO << 7 )) >> 6 ;
489
- control_word |= (mxcsr & (internal::ExceptionFlags::OVERFLOW << 7 )) >> 8 ;
490
- control_word |= (mxcsr & (internal::ExceptionFlags::UNDERFLOW << 7 )) >> 10 ;
491
- control_word |= (mxcsr & (internal::ExceptionFlags::INEXACT << 7 )) >> 12 ;
483
+ control_word |= (mxcsr & ((internal::ExceptionFlags::INVALID_F |
484
+ internal::ExceptionFlags::DENORMAL_F)
485
+ << 7 )) >>
486
+ 3 ;
487
+ control_word |= (mxcsr & (internal::ExceptionFlags::DIV_BY_ZERO_F << 7 )) >> 6 ;
488
+ control_word |= (mxcsr & (internal::ExceptionFlags::OVERFLOW_F << 7 )) >> 8 ;
489
+ control_word |= (mxcsr & (internal::ExceptionFlags::UNDERFLOW_F << 7 )) >> 10 ;
490
+ control_word |= (mxcsr & (internal::ExceptionFlags::INEXACT_F << 7 )) >> 12 ;
492
491
control_word |= control_word << WinExceptionFlags::HIGH_OFFSET;
493
492
494
493
// Set rounding in bits 8-9 and 30-31
0 commit comments