Allow divsi3 to take advantage of a hardware unsigned divide when it is available, by replacing an explicit call to udivsi3 with the divide operator. Patch by Sébastien Bourdeauducq.
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@158996 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/divsi3.c b/lib/divsi3.c
index 0d81cb8..44573db 100644
--- a/lib/divsi3.c
+++ b/lib/divsi3.c
@@ -29,5 +29,11 @@
a = (a ^ s_a) - s_a; /* negate if s_a == -1 */
b = (b ^ s_b) - s_b; /* negate if s_b == -1 */
s_a ^= s_b; /* sign of quotient */
- return (__udivsi3(a, b) ^ s_a) - s_a; /* negate if s_a == -1 */
+ /*
+ * On CPUs without unsigned hardware division support,
+ * this calls __udivsi3 (notice the cast to su_int).
+ * On CPUs with unsigned hardware division support,
+ * this uses the unsigned division instruction.
+ */
+ return ((su_int)a/(su_int)b ^ s_a) - s_a; /* negate if s_a == -1 */
}