@@ -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 (uint32_t status) {
66+ LIBC_INLINE static uint32_t exception_value_from_status (int 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 (uint32_t control) {
75+ LIBC_INLINE static uint32_t exception_value_from_control (int 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 uint32_t exception_value_to_status (uint32_t excepts) {
84+ LIBC_INLINE static int 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 uint32_t exception_value_to_control (uint32_t excepts) {
93+ LIBC_INLINE static int 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,54 +113,48 @@ struct FEnv {
113113};
114114
115115LIBC_INLINE int enable_except (int excepts) {
116- uint32_t new_excepts =
117- FEnv::exception_value_from_status (static_cast <uint32_t >(excepts));
116+ uint32_t new_excepts = FEnv::exception_value_from_status (excepts);
118117 uint32_t control_word = FEnv::get_control_word ();
119118 uint32_t old_excepts = FEnv::exception_value_from_control (control_word);
120119 if (new_excepts != old_excepts) {
121120 control_word |= FEnv::exception_value_to_control (new_excepts);
122121 FEnv::set_control_word (control_word);
123122 }
124- return static_cast < int >( FEnv::exception_value_to_status (old_excepts) );
123+ return FEnv::exception_value_to_status (old_excepts);
125124}
126125
127126LIBC_INLINE int disable_except (int excepts) {
128- uint32_t disabled_excepts =
129- FEnv::exception_value_from_status (static_cast <uint32_t >(excepts));
127+ uint32_t disabled_excepts = FEnv::exception_value_from_status (excepts);
130128 uint32_t control_word = FEnv::get_control_word ();
131129 uint32_t old_excepts = FEnv::exception_value_from_control (control_word);
132130 control_word &= ~FEnv::exception_value_to_control (disabled_excepts);
133131 FEnv::set_control_word (control_word);
134- return static_cast < int >( FEnv::exception_value_to_status (old_excepts) );
132+ return FEnv::exception_value_to_status (old_excepts);
135133}
136134
137135LIBC_INLINE int get_except () {
138136 uint32_t control_word = FEnv::get_control_word ();
139137 uint32_t enabled_excepts = FEnv::exception_value_from_control (control_word);
140- return static_cast < int >( FEnv::exception_value_to_status (enabled_excepts) );
138+ return FEnv::exception_value_to_status (enabled_excepts);
141139}
142140
143141LIBC_INLINE int clear_except (int excepts) {
144142 uint32_t status_word = FEnv::get_status_word ();
145- uint32_t except_value =
146- FEnv::exception_value_from_status (static_cast <uint32_t >(excepts));
143+ uint32_t except_value = FEnv::exception_value_from_status (excepts);
147144 status_word &= ~FEnv::exception_value_to_status (except_value);
148145 FEnv::set_status_word (status_word);
149146 return 0 ;
150147}
151148
152149LIBC_INLINE int test_except (int excepts) {
153150 uint32_t statusWord = FEnv::get_status_word ();
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));
151+ uint32_t ex_value = FEnv::exception_value_from_status (excepts);
152+ return statusWord & FEnv::exception_value_to_status (ex_value);
158153}
159154
160155LIBC_INLINE int set_except (int excepts) {
161156 uint32_t status_word = FEnv::get_status_word ();
162- uint32_t new_exceptions =
163- FEnv::exception_value_from_status (static_cast <uint32_t >(excepts));
157+ uint32_t new_exceptions = FEnv::exception_value_from_status (excepts);
164158 status_word |= FEnv::exception_value_to_status (new_exceptions);
165159 FEnv::set_status_word (status_word);
166160 return 0 ;
@@ -180,8 +174,7 @@ LIBC_INLINE int raise_except(int excepts) {
180174 : " s0" , " s1" /* s0 and s1 are clobbered */ );
181175 };
182176
183- uint32_t to_raise =
184- FEnv::exception_value_from_status (static_cast <uint32_t >(excepts));
177+ uint32_t to_raise = FEnv::exception_value_from_status (excepts);
185178 int result = 0 ;
186179
187180 if (to_raise & FEnv::EX_INVALID) {
@@ -244,7 +237,7 @@ LIBC_INLINE int get_round() {
244237}
245238
246239LIBC_INLINE int set_round (int mode) {
247- uint32_t bit_value;
240+ uint16_t bit_value;
248241 switch (mode) {
249242 case FE_TONEAREST:
250243 bit_value = FEnv::TONEAREST;
@@ -263,7 +256,7 @@ LIBC_INLINE int set_round(int mode) {
263256 }
264257
265258 uint32_t control_word = FEnv::get_control_word ();
266- control_word &= ~(0x3u << FEnv::ROUNDING_CONTROL_BIT_POSITION);
259+ control_word &= ~(0x3 << FEnv::ROUNDING_CONTROL_BIT_POSITION);
267260 control_word |= (bit_value << FEnv::ROUNDING_CONTROL_BIT_POSITION);
268261 FEnv::set_control_word (control_word);
269262
0 commit comments