Skip to content

Commit c3b8111

Browse files
committed
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.
llvm-svn: 158996
1 parent 2f42bb0 commit c3b8111

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

compiler-rt/lib/divsi3.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,11 @@ __divsi3(si_int a, si_int b)
2929
a = (a ^ s_a) - s_a; /* negate if s_a == -1 */
3030
b = (b ^ s_b) - s_b; /* negate if s_b == -1 */
3131
s_a ^= s_b; /* sign of quotient */
32-
return (__udivsi3(a, b) ^ s_a) - s_a; /* negate if s_a == -1 */
32+
/*
33+
* On CPUs without unsigned hardware division support,
34+
* this calls __udivsi3 (notice the cast to su_int).
35+
* On CPUs with unsigned hardware division support,
36+
* this uses the unsigned division instruction.
37+
*/
38+
return ((su_int)a/(su_int)b ^ s_a) - s_a; /* negate if s_a == -1 */
3339
}

compiler-rt/lib/udivsi3.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
ARM_EABI_FNALIAS(uidiv, udivsi3);
2222

23+
/* This function should not call __divsi3! */
2324
COMPILER_RT_ABI su_int
2425
__udivsi3(su_int n, su_int d)
2526
{

0 commit comments

Comments
 (0)