Skip to content

Commit f91a5fe

Browse files
[libc] fix woa64 fenv implementation (#119155)
Changing name type to match x86-64. This resolves definition conflicts with `core_crt` headers. fix #119154
1 parent 8569b47 commit f91a5fe

File tree

1 file changed

+25
-27
lines changed

1 file changed

+25
-27
lines changed

libc/src/__support/FPUtil/aarch64/FEnvImpl.h

+25-27
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
namespace LIBC_NAMESPACE_DECL {
2828
namespace fputil {
29-
3029
struct FEnv {
3130
struct FPState {
3231
uint32_t ControlWord;
@@ -42,31 +41,31 @@ struct FEnv {
4241
static constexpr uint32_t DOWNWARD = 0x2;
4342
static constexpr uint32_t TOWARDZERO = 0x3;
4443

45-
static constexpr uint32_t INVALID = 0x1;
46-
static constexpr uint32_t DIVBYZERO = 0x2;
47-
static constexpr uint32_t OVERFLOW = 0x4;
48-
static constexpr uint32_t UNDERFLOW = 0x8;
49-
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;
5049

5150
// Zero-th bit is the first bit.
5251
static constexpr uint32_t RoundingControlBitPosition = 22;
5352
static constexpr uint32_t ExceptionStatusFlagsBitPosition = 0;
5453
static constexpr uint32_t ExceptionControlFlagsBitPosition = 8;
5554

5655
LIBC_INLINE static uint32_t getStatusValueForExcept(int excepts) {
57-
return ((excepts & FE_INVALID) ? INVALID : 0) |
58-
((excepts & FE_DIVBYZERO) ? DIVBYZERO : 0) |
59-
((excepts & FE_OVERFLOW) ? OVERFLOW : 0) |
60-
((excepts & FE_UNDERFLOW) ? UNDERFLOW : 0) |
61-
((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);
6261
}
6362

6463
LIBC_INLINE static int exceptionStatusToMacro(uint32_t status) {
65-
return ((status & INVALID) ? FE_INVALID : 0) |
66-
((status & DIVBYZERO) ? FE_DIVBYZERO : 0) |
67-
((status & OVERFLOW) ? FE_OVERFLOW : 0) |
68-
((status & UNDERFLOW) ? FE_UNDERFLOW : 0) |
69-
((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);
7069
}
7170

7271
static uint32_t getControlWord() {
@@ -171,44 +170,44 @@ LIBC_INLINE int raise_except(int excepts) {
171170
uint32_t toRaise = FEnv::getStatusValueForExcept(excepts);
172171
int result = 0;
173172

174-
if (toRaise & FEnv::INVALID) {
173+
if (toRaise & FEnv::INVALID_F) {
175174
divfunc(zero, zero);
176175
uint32_t statusWord = FEnv::getStatusWord();
177176
if (!((statusWord >> FEnv::ExceptionStatusFlagsBitPosition) &
178-
FEnv::INVALID))
177+
FEnv::INVALID_F))
179178
result = -1;
180179
}
181180

182-
if (toRaise & FEnv::DIVBYZERO) {
181+
if (toRaise & FEnv::DIVBYZERO_F) {
183182
divfunc(one, zero);
184183
uint32_t statusWord = FEnv::getStatusWord();
185184
if (!((statusWord >> FEnv::ExceptionStatusFlagsBitPosition) &
186-
FEnv::DIVBYZERO))
185+
FEnv::DIVBYZERO_F))
187186
result = -1;
188187
}
189-
if (toRaise & FEnv::OVERFLOW) {
188+
if (toRaise & FEnv::OVERFLOW_F) {
190189
divfunc(largeValue, smallValue);
191190
uint32_t statusWord = FEnv::getStatusWord();
192191
if (!((statusWord >> FEnv::ExceptionStatusFlagsBitPosition) &
193-
FEnv::OVERFLOW))
192+
FEnv::OVERFLOW_F))
194193
result = -1;
195194
}
196-
if (toRaise & FEnv::UNDERFLOW) {
195+
if (toRaise & FEnv::UNDERFLOW_F) {
197196
divfunc(smallValue, largeValue);
198197
uint32_t statusWord = FEnv::getStatusWord();
199198
if (!((statusWord >> FEnv::ExceptionStatusFlagsBitPosition) &
200-
FEnv::UNDERFLOW))
199+
FEnv::UNDERFLOW_F))
201200
result = -1;
202201
}
203-
if (toRaise & FEnv::INEXACT) {
202+
if (toRaise & FEnv::INEXACT_F) {
204203
float two = 2.0f;
205204
float three = 3.0f;
206205
// 2.0 / 3.0 cannot be represented exactly in any radix 2 floating point
207206
// format.
208207
divfunc(two, three);
209208
uint32_t statusWord = FEnv::getStatusWord();
210209
if (!((statusWord >> FEnv::ExceptionStatusFlagsBitPosition) &
211-
FEnv::INEXACT))
210+
FEnv::INEXACT_F))
212211
result = -1;
213212
}
214213
return result;
@@ -278,7 +277,6 @@ LIBC_INLINE int set_env(const fenv_t *envp) {
278277
FEnv::writeStatusWord(state->StatusWord);
279278
return 0;
280279
}
281-
282280
} // namespace fputil
283281
} // namespace LIBC_NAMESPACE_DECL
284282

0 commit comments

Comments
 (0)