@@ -63,7 +63,7 @@ struct FEnv {
6363 // __fpcr_flush_to_zero bit in the FPCR register. This control bit is
6464 // located in a different place from FE_FLUSHTOZERO status bit relative to
6565 // the other exceptions.
66- LIBC_INLINE static uint32_t exception_value_from_status (int status) {
66+ LIBC_INLINE static uint32_t exception_value_from_status (uint32_t status) {
6767 return ((status & FE_INVALID) ? EX_INVALID : 0 ) |
6868 ((status & FE_DIVBYZERO) ? EX_DIVBYZERO : 0 ) |
6969 ((status & FE_OVERFLOW) ? EX_OVERFLOW : 0 ) |
@@ -72,7 +72,7 @@ struct FEnv {
7272 ((status & FE_FLUSHTOZERO) ? EX_FLUSHTOZERO : 0 );
7373 }
7474
75- LIBC_INLINE static uint32_t exception_value_from_control (int control) {
75+ LIBC_INLINE static uint32_t exception_value_from_control (uint32_t control) {
7676 return ((control & __fpcr_trap_invalid) ? EX_INVALID : 0 ) |
7777 ((control & __fpcr_trap_divbyzero) ? EX_DIVBYZERO : 0 ) |
7878 ((control & __fpcr_trap_overflow) ? EX_OVERFLOW : 0 ) |
@@ -81,7 +81,7 @@ struct FEnv {
8181 ((control & __fpcr_flush_to_zero) ? EX_FLUSHTOZERO : 0 );
8282 }
8383
84- LIBC_INLINE static int exception_value_to_status (uint32_t excepts) {
84+ LIBC_INLINE static uint32_t exception_value_to_status (uint32_t excepts) {
8585 return ((excepts & EX_INVALID) ? FE_INVALID : 0 ) |
8686 ((excepts & EX_DIVBYZERO) ? FE_DIVBYZERO : 0 ) |
8787 ((excepts & EX_OVERFLOW) ? FE_OVERFLOW : 0 ) |
@@ -90,7 +90,7 @@ struct FEnv {
9090 ((excepts & EX_FLUSHTOZERO) ? FE_FLUSHTOZERO : 0 );
9191 }
9292
93- LIBC_INLINE static int exception_value_to_control (uint32_t excepts) {
93+ LIBC_INLINE static uint32_t exception_value_to_control (uint32_t excepts) {
9494 return ((excepts & EX_INVALID) ? __fpcr_trap_invalid : 0 ) |
9595 ((excepts & EX_DIVBYZERO) ? __fpcr_trap_divbyzero : 0 ) |
9696 ((excepts & EX_OVERFLOW) ? __fpcr_trap_overflow : 0 ) |
@@ -113,48 +113,54 @@ struct FEnv {
113113};
114114
115115LIBC_INLINE int enable_except (int excepts) {
116- uint32_t new_excepts = FEnv::exception_value_from_status (excepts);
116+ uint32_t new_excepts =
117+ 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
126127LIBC_INLINE int disable_except (int excepts) {
127- uint32_t disabled_excepts = FEnv::exception_value_from_status (excepts);
128+ uint32_t disabled_excepts =
129+ FEnv::exception_value_from_status (static_cast <uint32_t >(excepts));
128130 uint32_t control_word = FEnv::get_control_word ();
129131 uint32_t old_excepts = FEnv::exception_value_from_control (control_word);
130132 control_word &= ~FEnv::exception_value_to_control (disabled_excepts);
131133 FEnv::set_control_word (control_word);
132- return FEnv::exception_value_to_status (old_excepts);
134+ return static_cast < int >( FEnv::exception_value_to_status (old_excepts) );
133135}
134136
135137LIBC_INLINE int get_except () {
136138 uint32_t control_word = FEnv::get_control_word ();
137139 uint32_t enabled_excepts = FEnv::exception_value_from_control (control_word);
138- return FEnv::exception_value_to_status (enabled_excepts);
140+ return static_cast < int >( FEnv::exception_value_to_status (enabled_excepts) );
139141}
140142
141143LIBC_INLINE int clear_except (int excepts) {
142144 uint32_t status_word = FEnv::get_status_word ();
143- uint32_t except_value = FEnv::exception_value_from_status (excepts);
145+ uint32_t except_value =
146+ FEnv::exception_value_from_status (static_cast <uint32_t >(excepts));
144147 status_word &= ~FEnv::exception_value_to_status (except_value);
145148 FEnv::set_status_word (status_word);
146149 return 0 ;
147150}
148151
149152LIBC_INLINE int test_except (int excepts) {
150153 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);
154+ uint32_t ex_value =
155+ FEnv::exception_value_from_status (static_cast <uint32_t >(excepts));
156+ return static_cast <int >(statusWord &
157+ FEnv::exception_value_to_status (ex_value));
153158}
154159
155160LIBC_INLINE int set_except (int excepts) {
156161 uint32_t status_word = FEnv::get_status_word ();
157- uint32_t new_exceptions = FEnv::exception_value_from_status (excepts);
162+ uint32_t new_exceptions =
163+ FEnv::exception_value_from_status (static_cast <uint32_t >(excepts));
158164 status_word |= FEnv::exception_value_to_status (new_exceptions);
159165 FEnv::set_status_word (status_word);
160166 return 0 ;
@@ -174,7 +180,8 @@ LIBC_INLINE int raise_except(int excepts) {
174180 : " s0" , " s1" /* s0 and s1 are clobbered */ );
175181 };
176182
177- uint32_t to_raise = FEnv::exception_value_from_status (excepts);
183+ uint32_t to_raise =
184+ FEnv::exception_value_from_status (static_cast <uint32_t >(excepts));
178185 int result = 0 ;
179186
180187 if (to_raise & FEnv::EX_INVALID) {
@@ -237,7 +244,7 @@ LIBC_INLINE int get_round() {
237244}
238245
239246LIBC_INLINE int set_round (int mode) {
240- uint16_t bit_value;
247+ uint32_t bit_value;
241248 switch (mode) {
242249 case FE_TONEAREST:
243250 bit_value = FEnv::TONEAREST;
@@ -256,7 +263,7 @@ LIBC_INLINE int set_round(int mode) {
256263 }
257264
258265 uint32_t control_word = FEnv::get_control_word ();
259- control_word &= ~(0x3 << FEnv::ROUNDING_CONTROL_BIT_POSITION);
266+ control_word &= ~(0x3u << FEnv::ROUNDING_CONTROL_BIT_POSITION);
260267 control_word |= (bit_value << FEnv::ROUNDING_CONTROL_BIT_POSITION);
261268 FEnv::set_control_word (control_word);
262269
0 commit comments