Skip to content

Commit

Permalink
[builtin] Add Thumb1 implementation for idivsi3 and aeabi_idivmod
Browse files Browse the repository at this point in the history
Summary:
For idivsi3, convert the Thumb2 only instruction to thumb1.
For aeabi_idivmod, using __divsi3.

Reviewers: rengolin, compnerd

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D27472

llvm-svn: 288960
  • Loading branch information
Weiming Zhao committed Dec 7, 2016
1 parent f3ecc9a commit 0a274c5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
9 changes: 9 additions & 0 deletions compiler-rt/lib/builtins/arm/aeabi_idivmod.S
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@
.syntax unified
.p2align 2
DEFINE_COMPILERRT_FUNCTION(__aeabi_idivmod)
#if __ARM_ARCH_ISA_THUMB == 1
push {r0, r1, lr}
bl SYMBOL_NAME(__divsi3)
pop {r1, r2, r3} // now r0 = quot, r1 = num, r2 = denom
muls r2, r2, r0 // r2 = quot * denom
subs r1, r1, r2
JMP (r3)
#else
push { lr }
sub sp, sp, #4
mov r2, sp
Expand All @@ -34,6 +42,7 @@ DEFINE_COMPILERRT_FUNCTION(__aeabi_idivmod)
ldr r1, [sp]
add sp, sp, #4
pop { pc }
#endif // __ARM_ARCH_ISA_THUMB == 1
END_COMPILERRT_FUNCTION(__aeabi_idivmod)

NO_EXEC_STACK_DIRECTIVE
Expand Down
20 changes: 20 additions & 0 deletions compiler-rt/lib/builtins/arm/divsi3.S
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,37 @@ LOCAL_LABEL(divzero):
#else
ESTABLISH_FRAME
// Set aside the sign of the quotient.
# if __ARM_ARCH_ISA_THUMB == 1
movs r4, r0
eors r4, r1
# else
eor r4, r0, r1
# endif
// Take absolute value of a and b via abs(x) = (x^(x >> 31)) - (x >> 31).
# if __ARM_ARCH_ISA_THUMB == 1
asrs r2, r0, #31
asrs r3, r1, #31
eors r0, r2
eors r1, r3
subs r0, r0, r2
subs r1, r1, r3
# else
eor r2, r0, r0, asr #31
eor r3, r1, r1, asr #31
sub r0, r2, r0, asr #31
sub r1, r3, r1, asr #31
# endif
// abs(a) / abs(b)
bl SYMBOL_NAME(__udivsi3)
// Apply sign of quotient to result and return.
# if __ARM_ARCH_ISA_THUMB == 1
asrs r4, #31
eors r0, r4
subs r0, r0, r4
# else
eor r0, r0, r4, asr #31
sub r0, r0, r4, asr #31
# endif
CLEAR_FRAME_AND_RETURN
#endif
END_COMPILERRT_FUNCTION(__divsi3)
Expand Down

0 comments on commit 0a274c5

Please sign in to comment.