2626
2727namespace LIBC_NAMESPACE_DECL {
2828namespace fputil {
29- #pragma push_macro("OVERFLOW")
30- #undef OVERFLOW
31- #pragma push_macro("UNDERFLOW")
32- #undef UNDERFLOW
3329struct FEnv {
3430 struct FPState {
3531 uint32_t ControlWord;
@@ -45,31 +41,31 @@ struct FEnv {
4541 static constexpr uint32_t DOWNWARD = 0x2 ;
4642 static constexpr uint32_t TOWARDZERO = 0x3 ;
4743
48- static constexpr uint32_t INVALID = 0x1 ;
49- static constexpr uint32_t DIVBYZERO = 0x2 ;
50- static constexpr uint32_t OVERFLOW = 0x4 ;
51- static constexpr uint32_t UNDERFLOW = 0x8 ;
52- static constexpr uint32_t INEXACT = 0x10 ;
44+ static constexpr uint32_t INVALID_F = 0x1 ;
45+ static constexpr uint32_t DIVBYZERO_F = 0x2 ;
46+ static constexpr uint32_t OVERFLOW_F = 0x4 ;
47+ static constexpr uint32_t UNDERFLOW_F = 0x8 ;
48+ static constexpr uint32_t INEXACT_F = 0x10 ;
5349
5450 // Zero-th bit is the first bit.
5551 static constexpr uint32_t RoundingControlBitPosition = 22 ;
5652 static constexpr uint32_t ExceptionStatusFlagsBitPosition = 0 ;
5753 static constexpr uint32_t ExceptionControlFlagsBitPosition = 8 ;
5854
5955 LIBC_INLINE static uint32_t getStatusValueForExcept (int excepts) {
60- return ((excepts & FE_INVALID) ? INVALID : 0 ) |
61- ((excepts & FE_DIVBYZERO) ? DIVBYZERO : 0 ) |
62- ((excepts & FE_OVERFLOW) ? OVERFLOW : 0 ) |
63- ((excepts & FE_UNDERFLOW) ? UNDERFLOW : 0 ) |
64- ((excepts & FE_INEXACT) ? INEXACT : 0 );
56+ return ((excepts & FE_INVALID) ? INVALID_F : 0 ) |
57+ ((excepts & FE_DIVBYZERO) ? DIVBYZERO_F : 0 ) |
58+ ((excepts & FE_OVERFLOW) ? OVERFLOW_F : 0 ) |
59+ ((excepts & FE_UNDERFLOW) ? UNDERFLOW_F : 0 ) |
60+ ((excepts & FE_INEXACT) ? INEXACT_F : 0 );
6561 }
6662
6763 LIBC_INLINE static int exceptionStatusToMacro (uint32_t status) {
68- return ((status & INVALID ) ? FE_INVALID : 0 ) |
69- ((status & DIVBYZERO ) ? FE_DIVBYZERO : 0 ) |
70- ((status & OVERFLOW ) ? FE_OVERFLOW : 0 ) |
71- ((status & UNDERFLOW ) ? FE_UNDERFLOW : 0 ) |
72- ((status & INEXACT ) ? FE_INEXACT : 0 );
64+ return ((status & INVALID_F ) ? FE_INVALID : 0 ) |
65+ ((status & DIVBYZERO_F ) ? FE_DIVBYZERO : 0 ) |
66+ ((status & OVERFLOW_F ) ? FE_OVERFLOW : 0 ) |
67+ ((status & UNDERFLOW_F ) ? FE_UNDERFLOW : 0 ) |
68+ ((status & INEXACT_F ) ? FE_INEXACT : 0 );
7369 }
7470
7571 static uint32_t getControlWord () {
@@ -174,44 +170,44 @@ LIBC_INLINE int raise_except(int excepts) {
174170 uint32_t toRaise = FEnv::getStatusValueForExcept (excepts);
175171 int result = 0 ;
176172
177- if (toRaise & FEnv::INVALID ) {
173+ if (toRaise & FEnv::INVALID_F ) {
178174 divfunc (zero, zero);
179175 uint32_t statusWord = FEnv::getStatusWord ();
180176 if (!((statusWord >> FEnv::ExceptionStatusFlagsBitPosition) &
181- FEnv::INVALID ))
177+ FEnv::INVALID_F ))
182178 result = -1 ;
183179 }
184180
185- if (toRaise & FEnv::DIVBYZERO ) {
181+ if (toRaise & FEnv::DIVBYZERO_F ) {
186182 divfunc (one, zero);
187183 uint32_t statusWord = FEnv::getStatusWord ();
188184 if (!((statusWord >> FEnv::ExceptionStatusFlagsBitPosition) &
189- FEnv::DIVBYZERO ))
185+ FEnv::DIVBYZERO_F ))
190186 result = -1 ;
191187 }
192- if (toRaise & FEnv::OVERFLOW ) {
188+ if (toRaise & FEnv::OVERFLOW_F ) {
193189 divfunc (largeValue, smallValue);
194190 uint32_t statusWord = FEnv::getStatusWord ();
195191 if (!((statusWord >> FEnv::ExceptionStatusFlagsBitPosition) &
196- FEnv::OVERFLOW ))
192+ FEnv::OVERFLOW_F ))
197193 result = -1 ;
198194 }
199- if (toRaise & FEnv::UNDERFLOW ) {
195+ if (toRaise & FEnv::UNDERFLOW_F ) {
200196 divfunc (smallValue, largeValue);
201197 uint32_t statusWord = FEnv::getStatusWord ();
202198 if (!((statusWord >> FEnv::ExceptionStatusFlagsBitPosition) &
203- FEnv::UNDERFLOW ))
199+ FEnv::UNDERFLOW_F ))
204200 result = -1 ;
205201 }
206- if (toRaise & FEnv::INEXACT ) {
202+ if (toRaise & FEnv::INEXACT_F ) {
207203 float two = 2 .0f ;
208204 float three = 3 .0f ;
209205 // 2.0 / 3.0 cannot be represented exactly in any radix 2 floating point
210206 // format.
211207 divfunc (two, three);
212208 uint32_t statusWord = FEnv::getStatusWord ();
213209 if (!((statusWord >> FEnv::ExceptionStatusFlagsBitPosition) &
214- FEnv::INEXACT ))
210+ FEnv::INEXACT_F ))
215211 result = -1 ;
216212 }
217213 return result;
@@ -281,9 +277,6 @@ LIBC_INLINE int set_env(const fenv_t *envp) {
281277 FEnv::writeStatusWord (state->StatusWord );
282278 return 0 ;
283279}
284-
285- #pragma pop_macro("UNDERFLOW")
286- #pragma pop_macro("OVERFLOW")
287280} // namespace fputil
288281} // namespace LIBC_NAMESPACE_DECL
289282
0 commit comments