diff options
-rw-r--r-- | README.txt | 8 | ||||
-rw-r--r-- | lib/divmodsi4.c | 30 | ||||
-rw-r--r-- | lib/udivmodsi4.c | 30 | ||||
-rw-r--r-- | make/platform/darwin_bni.mk | 9 | ||||
-rw-r--r-- | test/Unit/divmodsi4_test.c | 73 | ||||
-rw-r--r-- | test/Unit/udivmodsi4_test.c | 59 |
6 files changed, 203 insertions, 6 deletions
diff --git a/README.txt b/README.txt index ab389d212..cbeb10cf9 100644 --- a/README.txt +++ b/README.txt @@ -77,8 +77,12 @@ ti_int __modti3 (ti_int a, ti_int b); // a % b signed su_int __umodsi3 (su_int a, su_int b); // a % b unsigned du_int __umoddi3 (du_int a, du_int b); // a % b unsigned tu_int __umodti3 (tu_int a, tu_int b); // a % b unsigned -du_int __udivmoddi4(du_int a, du_int b, du_int* rem); // a / b, *rem = a % b -tu_int __udivmodti4(tu_int a, tu_int b, tu_int* rem); // a / b, *rem = a % b +du_int __udivmoddi4(du_int a, du_int b, du_int* rem); // a / b, *rem = a % b unsigned +tu_int __udivmodti4(tu_int a, tu_int b, tu_int* rem); // a / b, *rem = a % b unsigned +su_int __udivmodsi4(su_int a, su_int b, su_int* rem); // a / b, *rem = a % b unsigned +si_int __divmodsi4(si_int a, si_int b, si_int* rem); // a / b, *rem = a % b signed + + // Integral arithmetic with trapping overflow diff --git a/lib/divmodsi4.c b/lib/divmodsi4.c new file mode 100644 index 000000000..2ec3dd4a7 --- /dev/null +++ b/lib/divmodsi4.c @@ -0,0 +1,30 @@ +/*===-- divmodsi4.c - Implement __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 implements __divmodsi4 for the compiler_rt library. + * + * ===----------------------------------------------------------------------=== + */ + +#include "int_lib.h" + +extern si_int __divsi3(si_int a, si_int b); + + +/* Returns: a / b, *rem = a % b */ + +si_int +__divmodsi4(si_int a, si_int b, si_int* rem) +{ + si_int d = __divsi3(a,b); + *rem = a - (d*b); + return d; +} + + diff --git a/lib/udivmodsi4.c b/lib/udivmodsi4.c new file mode 100644 index 000000000..38b5bd43d --- /dev/null +++ b/lib/udivmodsi4.c @@ -0,0 +1,30 @@ +/*===-- udivmodsi4.c - Implement __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 implements __udivmodsi4 for the compiler_rt library. + * + * ===----------------------------------------------------------------------=== + */ + +#include "int_lib.h" + +extern su_int __udivsi3(su_int n, su_int d); + + +/* Returns: a / b, *rem = a % b */ + +su_int +__udivmodsi4(su_int a, su_int b, su_int* rem) +{ + si_int d = __udivsi3(a,b); + *rem = a - (d*b); + return d; +} + + diff --git a/make/platform/darwin_bni.mk b/make/platform/darwin_bni.mk index ec859f3b5..f15334f31 100644 --- a/make/platform/darwin_bni.mk +++ b/make/platform/darwin_bni.mk @@ -61,10 +61,10 @@ FUNCTIONS.armv5 := $(FUNCTIONS) \ muldf3 mulsf3 \ negdf2 negsf2 \ truncdfsf2 \ - modsi3 umodsi3 udivsi3 divsi3 \ + modsi3 umodsi3 udivsi3 divsi3 udivmodsi4 divmodsi4 \ switch8 switchu8 switch16 switch32 \ sync_synchronize - + FUNCTIONS.armv6 := $(FUNCTIONS) \ comparedf2 comparesf2 \ adddf3vfp addsf3vfp bswapdi2 bswapsi2 divdf3vfp \ @@ -76,10 +76,11 @@ FUNCTIONS.armv6 := $(FUNCTIONS) \ muldf3vfp mulsf3vfp \ nedf2vfp nesf2vfp \ subdf3vfp subsf3vfp truncdfsf2vfp unorddf2vfp unordsf2vfp \ - modsi3 umodsi3 udivsi3 divsi3 \ + modsi3 umodsi3 udivsi3 divsi3 udivmodsi4 divmodsi4 \ switch8 switchu8 switch16 switch32 \ restore_vfp_d8_d15_regs save_vfp_d8_d15_regs \ sync_synchronize + FUNCTIONS.armv7 := $(FUNCTIONS) \ comparedf2 comparesf2 \ adddf3vfp addsf3vfp bswapdi2 bswapsi2 divdf3vfp \ @@ -91,5 +92,5 @@ FUNCTIONS.armv7 := $(FUNCTIONS) \ muldf3vfp mulsf3vfp \ nedf2vfp nesf2vfp \ subdf3vfp subsf3vfp truncdfsf2vfp unorddf2vfp unordsf2vfp \ - modsi3 umodsi3 udivsi3 divsi3 + modsi3 umodsi3 udivsi3 divsi3 udivmodsi4 divmodsi4 diff --git a/test/Unit/divmodsi4_test.c b/test/Unit/divmodsi4_test.c new file mode 100644 index 000000000..bea31ea9a --- /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 000000000..d734cd1fd --- /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; +} |