summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJack Palevich <jackpal@google.com>2009-05-06 10:08:37 -0700
committerJack Palevich <jackpal@google.com>2009-05-06 10:08:37 -0700
commit4b11de2675aca2eebb5f18b513690fcc7c711d39 (patch)
tree0659a57f33434cbea88d7aebc2b9b8b49fd5a6b0
parente138ab357c91cb3ca55bd38b782c19b30e2d54c8 (diff)
downloadlcc-4b11de2675aca2eebb5f18b513690fcc7c711d39.tar.gz
Implement unsigned integer division and modulus.
Works just like signed integer division and modulus, except we call unsigned versions of the runtime functions. Extended the testmod test to test both signed and unsigned division and modulus. Extended the test framework to report the number of tests that failed and the total number of tests. This should make it easier to notice when tests fail.
-rw-r--r--src/arm.md6
-rwxr-xr-xtst/test-android.py8
-rw-r--r--tst/testmod.c28
-rw-r--r--tst/testmod.expected33
4 files changed, 54 insertions, 21 deletions
diff --git a/src/arm.md b/src/arm.md
index aed3789..16be69b 100644
--- a/src/arm.md
+++ b/src/arm.md
@@ -323,12 +323,12 @@ 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__aeabi_idiv\n" 2
-reg: DIVU4(reg,reg) "\tbl\t|x$udivide|\n" 2
+reg: DIVU4(reg,reg) "\tbl\t__aeabi_uidiv\n" 2
reg: DIVF4(reg,reg) "\tfdvs\t%c, %0, %1\n" 1
reg: DIVF8(reg,reg) "\tdvfd\t%c, %0, %1\n" 1
-reg: MODI4(reg,reg) "\tbl \t__aeabi_idivmod\n" 1
-reg: MODU4(reg,reg) "\tbl\t|x$uremainder|\n" 1
+reg: MODI4(reg,reg) "\tbl \t__aeabi_idivmod\n" 1
+reg: MODU4(reg,reg) "\tbl\t__aeabi_uidivmod\n" 1
stmt: LABELV "%a:\n"
diff --git a/tst/test-android.py b/tst/test-android.py
index 5444951..86ccc9b 100755
--- a/tst/test-android.py
+++ b/tst/test-android.py
@@ -90,11 +90,15 @@ def test(testFile):
transferToAndroid(testFile)
os.remove(testFile)
output = run(testFile)
- compareResult(testFile, output)
+ return compareResult(testFile, output)
def doTests():
+ failCount = 0
for testFile in testFiles:
- test(testFile)
+ if not test(testFile):
+ failCount += 1
+ print "Total tests: ", len(testFiles)
+ print "Total failures: ", failCount
def checkForDevice():
if adbGetState() != "device":
diff --git a/tst/testmod.c b/tst/testmod.c
index 63480ed..865f25c 100644
--- a/tst/testmod.c
+++ b/tst/testmod.c
@@ -1,8 +1,28 @@
extern void printf(const char* s,...);
+void testUnsigned(unsigned int a, unsigned int b) {
+ printf("%u / %% %u = %u, %u\n", a, b, a / b, a % b);
+}
+
+void testSigned(int a, int b) {
+ printf("%d / %% %d = %d, %d\n", a, b, a / b, a % b);
+}
+
void main(int argc, char** argv) {
- int i;
- for (i = 0; i < 12; i++) {
- printf("%d / %d = %d, %d %% %d = %d\n", i, 3, i / 3, i, 3, i % 3);
- }
+ {
+ int i;
+ printf("signed:\n");
+ for (i = -6; i < 6; i++) {
+ testSigned(i, 3);
+ }
+ }
+ {
+ unsigned int u;
+ unsigned int big = ((unsigned int) 1) << ((unsigned int) 31);
+ printf("unsigned:\n");
+ for (u = 0; u < 6; u++) {
+ testUnsigned(u, 3);
+ }
+ testUnsigned(big, 2);
+ }
}
diff --git a/tst/testmod.expected b/tst/testmod.expected
index c56a30f..d77bccf 100644
--- a/tst/testmod.expected
+++ b/tst/testmod.expected
@@ -1,12 +1,21 @@
-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
+signed:
+-6 / % 3 = -2, 0
+-5 / % 3 = -1, -2
+-4 / % 3 = -1, -1
+-3 / % 3 = -1, 0
+-2 / % 3 = 0, -2
+-1 / % 3 = 0, -1
+0 / % 3 = 0, 0
+1 / % 3 = 0, 1
+2 / % 3 = 0, 2
+3 / % 3 = 1, 0
+4 / % 3 = 1, 1
+5 / % 3 = 1, 2
+unsigned:
+0 / % 3 = 0, 0
+1 / % 3 = 0, 1
+2 / % 3 = 0, 2
+3 / % 3 = 1, 0
+4 / % 3 = 1, 1
+5 / % 3 = 1, 2
+2147483648 / % 2 = 1073741824, 0