History

Fix signed integer division in ARM runtime ABI

- 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

Thomas Preud'homme committed 12 years ago

Commit a24e31e1 parent f2dbcf71 file · +21 −9Browse files

Unified · Split

lib/armeabi.c+21−9
@@ -1,4 +1,4 @@
1−#include<limits.h>
1+#include <limits.h>
22
33 /* We rely on the little endianness and EABI calling convention for this to
44 work */
@@ -325,22 +325,28 @@ static inline rettype aeabi_ ## name (type num, type den) \ · 320 unmodified lines
325325 }
326326
327327 #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) \
329329 { \
330330 unsigned type num, den; \
331331 urettype uxdiv_ret; \
332332 rettype ret; \
333333 \
334− num = numerator & typemacro ## _MAX; \
335− den = denominator & typemacro ## _MAX; \
334+ if (numerator >= 0) \
335+ num = numerator; \
336+ else \
337+ num = 0 - numerator; \
338+ if (denominator >= 0) \
339+ den = denominator; \
340+ else \
341+ den = 0 - denominator; \
336342 uxdiv_ret = aeabi_ ## uiname(num, den); \
337343 /* signs differ */ \
338344 if ((numerator & typemacro ## _MIN) != (denominator & typemacro ## _MIN)) \
339− ret.quot = uxdiv_ret.quot * -1; \
345+ ret.quot = 0 - uxdiv_ret.quot; \
340346 else \
341347 ret.quot = uxdiv_ret.quot; \
342− if (numerator & typemacro ## _MIN) \
343− ret.rem = uxdiv_ret.rem * -1; \
348+ if (numerator < 0) \
349+ ret.rem = 0 - uxdiv_ret.rem; \
344350 else \
345351 ret.rem = uxdiv_ret.rem; \
346352 \
@@ -420,8 +426,14 @@ int __aeabi_idiv(int numerator, int denominator) · 73 unmodified lines
420426 unsigned num, den;
421427 uidiv_t ret;
422428
423− num = numerator & INT_MAX;
424− den = denominator & INT_MAX;
429+ if (numerator >= 0)
430+ num = numerator;
431+ else
432+ num = 0 - numerator;
433+ if (denominator >= 0)
434+ den = denominator;
435+ else
436+ den = 0 - denominator;
425437 ret = aeabi_uidivmod(num, den);
426438 if ((numerator & INT_MIN) != (denominator & INT_MIN)) /* signs differ */
427439 ret.quot *= -1;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t