[llvm-commits] [compiler-rt] r127778 - in /compiler-rt/trunk: README.txt lib/divmodsi4.c lib/udivmodsi4.c make/platform/darwin_bni.mk test/Unit/divmodsi4_test.c test/Unit/udivmodsi4_test.c

Nick Kledzik kledzik at apple.com
Wed Mar 16 17:09:13 PDT 2011


Author: kledzik
Date: Wed Mar 16 19:09:13 2011
New Revision: 127778

URL: http://llvm.org/viewvc/llvm-project?rev=127778&view=rev
Log:
<rdar://problem/8914924> implement udivmodsi4 and divmodsi4 for ARM

Added:
    compiler-rt/trunk/lib/divmodsi4.c
    compiler-rt/trunk/lib/udivmodsi4.c
    compiler-rt/trunk/test/Unit/divmodsi4_test.c
    compiler-rt/trunk/test/Unit/udivmodsi4_test.c
Modified:
    compiler-rt/trunk/README.txt
    compiler-rt/trunk/make/platform/darwin_bni.mk

Modified: compiler-rt/trunk/README.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/README.txt?rev=127778&r1=127777&r2=127778&view=diff
==============================================================================
--- compiler-rt/trunk/README.txt (original)
+++ compiler-rt/trunk/README.txt Wed Mar 16 19:09:13 2011
@@ -77,8 +77,12 @@
 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
 

Added: compiler-rt/trunk/lib/divmodsi4.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/divmodsi4.c?rev=127778&view=auto
==============================================================================
--- compiler-rt/trunk/lib/divmodsi4.c (added)
+++ compiler-rt/trunk/lib/divmodsi4.c Wed Mar 16 19:09:13 2011
@@ -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; 
+}
+
+

Added: compiler-rt/trunk/lib/udivmodsi4.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/udivmodsi4.c?rev=127778&view=auto
==============================================================================
--- compiler-rt/trunk/lib/udivmodsi4.c (added)
+++ compiler-rt/trunk/lib/udivmodsi4.c Wed Mar 16 19:09:13 2011
@@ -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; 
+}
+
+

Modified: compiler-rt/trunk/make/platform/darwin_bni.mk
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/make/platform/darwin_bni.mk?rev=127778&r1=127777&r2=127778&view=diff
==============================================================================
--- compiler-rt/trunk/make/platform/darwin_bni.mk (original)
+++ compiler-rt/trunk/make/platform/darwin_bni.mk Wed Mar 16 19:09:13 2011
@@ -61,10 +61,10 @@
                 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 @@
                 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 @@
                 muldf3vfp mulsf3vfp \
                 nedf2vfp nesf2vfp \
                 subdf3vfp subsf3vfp truncdfsf2vfp unorddf2vfp unordsf2vfp \
-                modsi3 umodsi3 udivsi3 divsi3 
+                modsi3 umodsi3 udivsi3 divsi3 udivmodsi4 divmodsi4
 

Added: compiler-rt/trunk/test/Unit/divmodsi4_test.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/Unit/divmodsi4_test.c?rev=127778&view=auto
==============================================================================
--- compiler-rt/trunk/test/Unit/divmodsi4_test.c (added)
+++ compiler-rt/trunk/test/Unit/divmodsi4_test.c Wed Mar 16 19:09:13 2011
@@ -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;
+}

Added: compiler-rt/trunk/test/Unit/udivmodsi4_test.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/Unit/udivmodsi4_test.c?rev=127778&view=auto
==============================================================================
--- compiler-rt/trunk/test/Unit/udivmodsi4_test.c (added)
+++ compiler-rt/trunk/test/Unit/udivmodsi4_test.c Wed Mar 16 19:09:13 2011
@@ -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;
+}





More information about the llvm-commits mailing list