Fix signed division to use __aeabi_idiv.
Extend the testmod test to test division as well as modulus.
The sort test now passes.
diff --git a/src/arm.md b/src/arm.md
index 2b20ec3..aed3789 100644
--- a/src/arm.md
+++ b/src/arm.md
@@ -322,7 +322,7 @@
reg: MULF4(reg,reg) "\tfmls\t%c, %0, %1\n" 1
reg: MULF8(reg,reg) "\tmufd\t%c, %0, %1\n" 1
-reg: DIVI4(reg,reg) "\tbl\t__divsi3\n" 2
+reg: DIVI4(reg,reg) "\tbl\t__aeabi_idiv\n" 2
reg: DIVU4(reg,reg) "\tbl\t|x$udivide|\n" 2
reg: DIVF4(reg,reg) "\tfdvs\t%c, %0, %1\n" 1
reg: DIVF8(reg,reg) "\tdvfd\t%c, %0, %1\n" 1
@@ -471,8 +471,8 @@
break;
case DIV+I: case DIV+U:
setreg(p, ireg[0]);
- rtarget(p, 1, ireg[0]);
- rtarget(p, 0, ireg[1]);
+ rtarget(p, 0, ireg[0]);
+ rtarget(p, 1, ireg[1]);
break;
case MOD+I: case MOD+U:
setreg(p, ireg[1]);
@@ -487,10 +487,13 @@
assert(p);
switch (specific(p->op)) {
case CALL+F: case CALL+I: case CALL+U: case CALL+P: case CALL+V:
- spill(0xf, FREG, p);
+ spill(0xf, IREG, p);
+ break;
+ case DIV+I: case DIV+U:
+ spill(0xc, IREG, p);
break;
case MOD+I: case MOD+U:
- /* spill(1, IREG, p); */
+ spill(0xd, IREG, p);
break;
}
}
diff --git a/tst/test-android.py b/tst/test-android.py
index 7e63e89..5444951 100755
--- a/tst/test-android.py
+++ b/tst/test-android.py
@@ -14,7 +14,7 @@
"incr",
"init",
"limits",
- "sort", # bad output, bus error.
+ "sort",
"struct",
"switch",
"testmod"
diff --git a/tst/testmod.c b/tst/testmod.c
index 23881db..63480ed 100644
--- a/tst/testmod.c
+++ b/tst/testmod.c
@@ -2,7 +2,7 @@
void main(int argc, char** argv) {
int i;
- for (i = 1; i < 12; i++) {
- printf("%d %% %d = %d\n", i, 3, i % 3);
+ for (i = 0; i < 12; i++) {
+ printf("%d / %d = %d, %d %% %d = %d\n", i, 3, i / 3, i, 3, i % 3);
}
}
diff --git a/tst/testmod.expected b/tst/testmod.expected
index 875d12b..c56a30f 100644
--- a/tst/testmod.expected
+++ b/tst/testmod.expected
@@ -1,11 +1,12 @@
-1 % 3 = 1
-2 % 3 = 2
-3 % 3 = 0
-4 % 3 = 1
-5 % 3 = 2
-6 % 3 = 0
-7 % 3 = 1
-8 % 3 = 2
-9 % 3 = 0
-10 % 3 = 1
-11 % 3 = 2
+0 / 3 = 0, 0 % 3 = 0
+1 / 3 = 0, 1 % 3 = 1
+2 / 3 = 0, 2 % 3 = 2
+3 / 3 = 1, 3 % 3 = 0
+4 / 3 = 1, 4 % 3 = 1
+5 / 3 = 1, 5 % 3 = 2
+6 / 3 = 2, 6 % 3 = 0
+7 / 3 = 2, 7 % 3 = 1
+8 / 3 = 2, 8 % 3 = 2
+9 / 3 = 3, 9 % 3 = 0
+10 / 3 = 3, 10 % 3 = 1
+11 / 3 = 3, 11 % 3 = 2