Skip to content

Commit 7e263a6

Browse files
fenv_darwin_impl.h
1 parent 3568e2a commit 7e263a6

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

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

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "src/__support/macros/attributes.h" // LIBC_INLINE
1313
#include "src/__support/macros/config.h"
1414
#include "src/__support/macros/properties/architectures.h"
15+
#include <_types/_uint32_t.h>
1516

1617
#if !defined(LIBC_TARGET_ARCH_IS_AARCH64) || !defined(__APPLE__)
1718
#error "Invalid include"
@@ -63,7 +64,7 @@ struct FEnv {
6364
// __fpcr_flush_to_zero bit in the FPCR register. This control bit is
6465
// located in a different place from FE_FLUSHTOZERO status bit relative to
6566
// the other exceptions.
66-
LIBC_INLINE static uint32_t exception_value_from_status(int status) {
67+
LIBC_INLINE static uint32_t exception_value_from_status(uint32_t status) {
6768
return ((status & FE_INVALID) ? EX_INVALID : 0) |
6869
((status & FE_DIVBYZERO) ? EX_DIVBYZERO : 0) |
6970
((status & FE_OVERFLOW) ? EX_OVERFLOW : 0) |
@@ -72,7 +73,7 @@ struct FEnv {
7273
((status & FE_FLUSHTOZERO) ? EX_FLUSHTOZERO : 0);
7374
}
7475

75-
LIBC_INLINE static uint32_t exception_value_from_control(int control) {
76+
LIBC_INLINE static uint32_t exception_value_from_control(uint32_t control) {
7677
return ((control & __fpcr_trap_invalid) ? EX_INVALID : 0) |
7778
((control & __fpcr_trap_divbyzero) ? EX_DIVBYZERO : 0) |
7879
((control & __fpcr_trap_overflow) ? EX_OVERFLOW : 0) |
@@ -81,7 +82,7 @@ struct FEnv {
8182
((control & __fpcr_flush_to_zero) ? EX_FLUSHTOZERO : 0);
8283
}
8384

84-
LIBC_INLINE static int exception_value_to_status(uint32_t excepts) {
85+
LIBC_INLINE static uint32_t exception_value_to_status(uint32_t excepts) {
8586
return ((excepts & EX_INVALID) ? FE_INVALID : 0) |
8687
((excepts & EX_DIVBYZERO) ? FE_DIVBYZERO : 0) |
8788
((excepts & EX_OVERFLOW) ? FE_OVERFLOW : 0) |
@@ -90,7 +91,7 @@ struct FEnv {
9091
((excepts & EX_FLUSHTOZERO) ? FE_FLUSHTOZERO : 0);
9192
}
9293

93-
LIBC_INLINE static int exception_value_to_control(uint32_t excepts) {
94+
LIBC_INLINE static uint32_t exception_value_to_control(uint32_t excepts) {
9495
return ((excepts & EX_INVALID) ? __fpcr_trap_invalid : 0) |
9596
((excepts & EX_DIVBYZERO) ? __fpcr_trap_divbyzero : 0) |
9697
((excepts & EX_OVERFLOW) ? __fpcr_trap_overflow : 0) |
@@ -113,48 +114,48 @@ struct FEnv {
113114
};
114115

115116
LIBC_INLINE int enable_except(int excepts) {
116-
uint32_t new_excepts = FEnv::exception_value_from_status(excepts);
117+
uint32_t new_excepts = FEnv::exception_value_from_status(static_cast<uint32_t>(excepts));
117118
uint32_t control_word = FEnv::get_control_word();
118119
uint32_t old_excepts = FEnv::exception_value_from_control(control_word);
119120
if (new_excepts != old_excepts) {
120121
control_word |= FEnv::exception_value_to_control(new_excepts);
121122
FEnv::set_control_word(control_word);
122123
}
123-
return FEnv::exception_value_to_status(old_excepts);
124+
return static_cast<int>(FEnv::exception_value_to_status(old_excepts));
124125
}
125126

126127
LIBC_INLINE int disable_except(int excepts) {
127-
uint32_t disabled_excepts = FEnv::exception_value_from_status(excepts);
128+
uint32_t disabled_excepts = FEnv::exception_value_from_status(static_cast<uint32_t>(excepts));
128129
uint32_t control_word = FEnv::get_control_word();
129130
uint32_t old_excepts = FEnv::exception_value_from_control(control_word);
130131
control_word &= ~FEnv::exception_value_to_control(disabled_excepts);
131132
FEnv::set_control_word(control_word);
132-
return FEnv::exception_value_to_status(old_excepts);
133+
return static_cast<int>(FEnv::exception_value_to_status(old_excepts));
133134
}
134135

135136
LIBC_INLINE int get_except() {
136137
uint32_t control_word = FEnv::get_control_word();
137138
uint32_t enabled_excepts = FEnv::exception_value_from_control(control_word);
138-
return FEnv::exception_value_to_status(enabled_excepts);
139+
return static_cast<int>(FEnv::exception_value_to_status(enabled_excepts));
139140
}
140141

141142
LIBC_INLINE int clear_except(int excepts) {
142143
uint32_t status_word = FEnv::get_status_word();
143-
uint32_t except_value = FEnv::exception_value_from_status(excepts);
144+
uint32_t except_value = FEnv::exception_value_from_status(static_cast<uint32_t>(excepts));
144145
status_word &= ~FEnv::exception_value_to_status(except_value);
145146
FEnv::set_status_word(status_word);
146147
return 0;
147148
}
148149

149150
LIBC_INLINE int test_except(int excepts) {
150151
uint32_t statusWord = FEnv::get_status_word();
151-
uint32_t ex_value = FEnv::exception_value_from_status(excepts);
152-
return statusWord & FEnv::exception_value_to_status(ex_value);
152+
uint32_t ex_value = FEnv::exception_value_from_status(static_cast<uint32_t>(excepts));
153+
return static_cast<int>(statusWord & FEnv::exception_value_to_status(ex_value));
153154
}
154155

155156
LIBC_INLINE int set_except(int excepts) {
156157
uint32_t status_word = FEnv::get_status_word();
157-
uint32_t new_exceptions = FEnv::exception_value_from_status(excepts);
158+
uint32_t new_exceptions = FEnv::exception_value_from_status(static_cast<uint32_t>(excepts));
158159
status_word |= FEnv::exception_value_to_status(new_exceptions);
159160
FEnv::set_status_word(status_word);
160161
return 0;
@@ -174,7 +175,7 @@ LIBC_INLINE int raise_except(int excepts) {
174175
: "s0", "s1" /* s0 and s1 are clobbered */);
175176
};
176177

177-
uint32_t to_raise = FEnv::exception_value_from_status(excepts);
178+
uint32_t to_raise = FEnv::exception_value_from_status(static_cast<uint32_t>(excepts));
178179
int result = 0;
179180

180181
if (to_raise & FEnv::EX_INVALID) {
@@ -237,7 +238,7 @@ LIBC_INLINE int get_round() {
237238
}
238239

239240
LIBC_INLINE int set_round(int mode) {
240-
uint16_t bit_value;
241+
uint32_t bit_value;
241242
switch (mode) {
242243
case FE_TONEAREST:
243244
bit_value = FEnv::TONEAREST;
@@ -256,7 +257,7 @@ LIBC_INLINE int set_round(int mode) {
256257
}
257258

258259
uint32_t control_word = FEnv::get_control_word();
259-
control_word &= ~(0x3 << FEnv::ROUNDING_CONTROL_BIT_POSITION);
260+
control_word &= ~(0x3u << FEnv::ROUNDING_CONTROL_BIT_POSITION);
260261
control_word |= (bit_value << FEnv::ROUNDING_CONTROL_BIT_POSITION);
261262
FEnv::set_control_word(control_word);
262263

0 commit comments

Comments
 (0)