summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorNick Kledzik <kledzik@apple.com>2011-03-17 00:09:13 +0000
committerNick Kledzik <kledzik@apple.com>2011-03-17 00:09:13 +0000
commit5c0809916b70dbb754cf0c999e2923909e5603c6 (patch)
tree875c98489b0419eb321390a6093da33c5116f79a /test
parent1ea7a40c373d811250eb59259140453461e50c30 (diff)
downloadcompiler-rt-5c0809916b70dbb754cf0c999e2923909e5603c6.tar.gz
compiler-rt-5c0809916b70dbb754cf0c999e2923909e5603c6.tar.bz2
compiler-rt-5c0809916b70dbb754cf0c999e2923909e5603c6.tar.xz
<rdar://problem/8914924> implement udivmodsi4 and divmodsi4 for ARM
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@127778 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r--test/Unit/divmodsi4_test.c73
-rw-r--r--test/Unit/udivmodsi4_test.c59
2 files changed, 132 insertions, 0 deletions
diff --git a/test/Unit/divmodsi4_test.c b/test/Unit/divmodsi4_test.c
new file mode 100644
index 00000000..bea31ea9
--- /dev/null
+++ b/test/Unit/divmodsi4_test.c
@@ -0,0 +1,73 @@
+//===-- divmodsi4_test.c - Test __divmodsi4 -------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file tests __divmodsi4 for the compiler_rt library.
+//
+//===----------------------------------------------------------------------===//
+
+#include "int_lib.h"
+#include <stdio.h>
+
+// Returns: a / b
+
+extern si_int __divmodsi4(si_int a, si_int b, si_int* rem);
+
+
+int test__divmodsi4(si_int a, si_int b,
+ si_int expected_result, si_int expected_rem)
+{
+ si_int rem;
+ si_int result = __divmodsi4(a, b, &rem);
+ if (result != expected_result) {
+ printf("error in __divmodsi4: %d / %d = %d, expected %d\n",
+ a, b, result, expected_result);
+ return 1;
+ }
+ if (rem != expected_rem) {
+ printf("error in __divmodsi4: %d mod %d = %d, expected %d\n",
+ a, b, rem, expected_rem);
+ return 1;
+ }
+
+ return 0;
+}
+
+
+int main()
+{
+ if (test__divmodsi4(0, 1, 0, 0))
+ return 1;
+ if (test__divmodsi4(0, -1, 0, 0))
+ return 1;
+
+ if (test__divmodsi4(2, 1, 2, 0))
+ return 1;
+ if (test__divmodsi4(2, -1, -2, 0))
+ return 1;
+ if (test__divmodsi4(-2, 1, -2, 0))
+ return 1;
+ if (test__divmodsi4(-2, -1, 2, 0))
+ return 1;
+
+ if (test__divmodsi4(7, 5, 1, 2))
+ return 1;
+ if (test__divmodsi4(-7, 5, -1, -2))
+ return 1;
+ if (test__divmodsi4(19, 5, 3, 4))
+ return 1;
+ if (test__divmodsi4(19, -5, -3, 4))
+ return 1;
+
+ if (test__divmodsi4(0x80000000, 8, 0xf0000000, 0))
+ return 1;
+ if (test__divmodsi4(0x80000007, 8, 0xf0000001, -1))
+ return 1;
+
+ return 0;
+}
diff --git a/test/Unit/udivmodsi4_test.c b/test/Unit/udivmodsi4_test.c
new file mode 100644
index 00000000..d734cd1f
--- /dev/null
+++ b/test/Unit/udivmodsi4_test.c
@@ -0,0 +1,59 @@
+//===-- udivmodsi4_test.c - Test __udivmodsi4 -----------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file tests __udivmodsi4 for the compiler_rt library.
+//
+//===----------------------------------------------------------------------===//
+
+#include "int_lib.h"
+#include <stdio.h>
+
+// Returns: a / b
+
+extern su_int __udivmodsi4(su_int a, su_int b, su_int* rem);
+
+int test__udivmodsi4(su_int a, su_int b,
+ su_int expected_result, su_int expected_rem)
+{
+ su_int rem;
+ su_int result = __udivmodsi4(a, b, &rem);
+ if (result != expected_result) {
+ printf("error in __udivmodsi4: %u / %u = %u, expected %u\n",
+ a, b, result, expected_result);
+ return 1;
+ }
+ if (rem != expected_rem) {
+ printf("error in __udivmodsi4: %u mod %u = %u, expected %u\n",
+ a, b, rem, expected_rem);
+ return 1;
+ }
+
+ return 0;
+}
+
+
+int main()
+{
+ if (test__udivmodsi4(0, 1, 0, 0))
+ return 1;
+
+ if (test__udivmodsi4(2, 1, 2, 0))
+ return 1;
+
+ if (test__udivmodsi4(19, 5, 3, 4))
+ return 1;
+
+ if (test__udivmodsi4(0x80000000, 8, 0x10000000, 0))
+ return 1;
+
+ if (test__udivmodsi4(0x80000003, 8, 0x10000000, 3))
+ return 1;
+
+ return 0;
+}