- fix computation of absolute value (clearing the sign bit does not since integers are encoded in 2's complement) - test sign of integer in a more conventional way (binary and with the high bit does not work for long long due to a bug in gtst) - spacing in include
Unified · Split
| @@ -1,4 +1,4 @@ | |||
| 1 | #include<limits.h> | 1 | #include <limits.h> |
| 2 | 2 | ||
| 3 | /* We rely on the little endianness and EABI calling convention for this to | 3 | /* We rely on the little endianness and EABI calling convention for this to |
| 4 | work */ | 4 | work */ |
| @@ -325,22 +325,28 @@ static inline rettype aeabi_ ## name (type num, type den) \ · 320 unmodified lines | |||
| 325 | } | 325 | } |
| 326 | 326 | ||
| 327 | #define __AEABI_XDIVMOD(name, type, uiname, rettype, urettype, typemacro) \ | 327 | #define __AEABI_XDIVMOD(name, type, uiname, rettype, urettype, typemacro) \ |
| 328 | void __aeabi_ ## name(type numerator, type denominator) \ | 328 | void __aeabi_ ## name(type numerator, type denominator) \ |
| 329 | { \ | 329 | { \ |
| 330 | unsigned type num, den; \ | 330 | unsigned type num, den; \ |
| 331 | urettype uxdiv_ret; \ | 331 | urettype uxdiv_ret; \ |
| 332 | rettype ret; \ | 332 | rettype ret; \ |
| 333 | \ | 333 | \ |
| 334 | num = numerator & typemacro ## _MAX; \ | 334 | if (numerator >= 0) \ |
| 335 | den = denominator & typemacro ## _MAX; \ | 335 | num = numerator; \ |
| 336 | else \ | ||
| 337 | num = 0 - numerator; \ | ||
| 338 | if (denominator >= 0) \ | ||
| 339 | den = denominator; \ | ||
| 340 | else \ | ||
| 341 | den = 0 - denominator; \ | ||
| 336 | uxdiv_ret = aeabi_ ## uiname(num, den); \ | 342 | uxdiv_ret = aeabi_ ## uiname(num, den); \ |
| 337 | /* signs differ */ \ | 343 | /* signs differ */ \ |
| 338 | if ((numerator & typemacro ## _MIN) != (denominator & typemacro ## _MIN)) \ | 344 | if ((numerator & typemacro ## _MIN) != (denominator & typemacro ## _MIN)) \ |
| 339 | ret.quot = uxdiv_ret.quot * -1; \ | 345 | ret.quot = 0 - uxdiv_ret.quot; \ |
| 340 | else \ | 346 | else \ |
| 341 | ret.quot = uxdiv_ret.quot; \ | 347 | ret.quot = uxdiv_ret.quot; \ |
| 342 | if (numerator & typemacro ## _MIN) \ | 348 | if (numerator < 0) \ |
| 343 | ret.rem = uxdiv_ret.rem * -1; \ | 349 | ret.rem = 0 - uxdiv_ret.rem; \ |
| 344 | else \ | 350 | else \ |
| 345 | ret.rem = uxdiv_ret.rem; \ | 351 | ret.rem = uxdiv_ret.rem; \ |
| 346 | \ | 352 | \ |
| @@ -420,8 +426,14 @@ int __aeabi_idiv(int numerator, int denominator) · 73 unmodified lines | |||
| 420 | unsigned num, den; | 426 | unsigned num, den; |
| 421 | uidiv_t ret; | 427 | uidiv_t ret; |
| 422 | 428 | ||
| 423 | num = numerator & INT_MAX; | 429 | if (numerator >= 0) |
| 424 | den = denominator & INT_MAX; | 430 | num = numerator; |
| 431 | else | ||
| 432 | num = 0 - numerator; | ||
| 433 | if (denominator >= 0) | ||
| 434 | den = denominator; | ||
| 435 | else | ||
| 436 | den = 0 - denominator; | ||
| 425 | ret = aeabi_uidivmod(num, den); | 437 | ret = aeabi_uidivmod(num, den); |
| 426 | if ((numerator & INT_MIN) != (denominator & INT_MIN)) /* signs differ */ | 438 | if ((numerator & INT_MIN) != (denominator & INT_MIN)) /* signs differ */ |
| 427 | ret.quot *= -1; | 439 | ret.quot *= -1; |