[compiler-rt] r288960 - [builtin] Add Thumb1 implementation for idivsi3 and aeabi_idivmod
Weiming Zhao via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 7 11:14:29 PST 2016
Author: weimingz
Date: Wed Dec 7 13:14:29 2016
New Revision: 288960
URL: http://llvm.org/viewvc/llvm-project?rev=288960&view=rev
Log:
[builtin] Add Thumb1 implementation for idivsi3 and aeabi_idivmod
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
Modified:
compiler-rt/trunk/lib/builtins/arm/aeabi_idivmod.S
compiler-rt/trunk/lib/builtins/arm/divsi3.S
Modified: compiler-rt/trunk/lib/builtins/arm/aeabi_idivmod.S
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/builtins/arm/aeabi_idivmod.S?rev=288960&r1=288959&r2=288960&view=diff
==============================================================================
--- compiler-rt/trunk/lib/builtins/arm/aeabi_idivmod.S (original)
+++ compiler-rt/trunk/lib/builtins/arm/aeabi_idivmod.S Wed Dec 7 13:14:29 2016
@@ -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
@@ -34,6 +42,7 @@ DEFINE_COMPILERRT_FUNCTION(__aeabi_idivm
ldr r1, [sp]
add sp, sp, #4
pop { pc }
+#endif // __ARM_ARCH_ISA_THUMB == 1
END_COMPILERRT_FUNCTION(__aeabi_idivmod)
NO_EXEC_STACK_DIRECTIVE
Modified: compiler-rt/trunk/lib/builtins/arm/divsi3.S
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/builtins/arm/divsi3.S?rev=288960&r1=288959&r2=288960&view=diff
==============================================================================
--- compiler-rt/trunk/lib/builtins/arm/divsi3.S (original)
+++ compiler-rt/trunk/lib/builtins/arm/divsi3.S Wed Dec 7 13:14:29 2016
@@ -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)
More information about the llvm-commits
mailing list