<div dir="ltr">With this CL, we can no longer build compiler-rt with clang from XCode 7.0:<div><a href="https://build.chromium.org/p/chromium.fyi/builders/ClangToTMac%20%28dbg%29/builds/7185/steps/gclient%20runhooks/logs/stdio">https://build.chromium.org/p/chromium.fyi/builders/ClangToTMac%20%28dbg%29/builds/7185/steps/gclient%20runhooks/logs/stdio</a><br></div><div><div><br></div><div>FAILED: lib/builtins/CMakeFiles/clang_rt.hard_pic_armv7em_macho_embedded.dir/arm/clzdi2.S.o </div><div>/Applications/Xcode7.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc ...</div><div>/b/c/b/ClangToTMac__dbg_/src/third_party/llvm/compiler-rt/lib/builtins/arm/clzdi2.S:58:2: error: predicated instructions must be in IT block</div><div> movne r0, r1</div><div> ^</div><div>/b/c/b/ClangToTMac__dbg_/src/third_party/llvm/compiler-rt/lib/builtins/arm/clzdi2.S:60:2: error: predicated instructions must be in IT block</div><div> movne r1, 1</div><div> ^</div></div><div>...</div><div><br></div><div>With the changed __ARM_FEATURE_CLZ ifdef, now something goes wrong.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Dec 5, 2016 at 11:13 PM, Weiming Zhao via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: weimingz<br>
Date: Tue Dec 6 01:13:15 2016<br>
New Revision: 288777<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=288777&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=288777&view=rev</a><br>
Log:<br>
builtins: Add ARM Thumb1 implementation for uidiv and uidivmod<br>
<br>
This is a resubmit of r288710 due to breakage of Darwin armv7em.<br>
<br>
Modified:<br>
compiler-rt/trunk/lib/<wbr>builtins/arm/aeabi_uidivmod.S<br>
compiler-rt/trunk/lib/<wbr>builtins/arm/udivsi3.S<br>
compiler-rt/trunk/lib/<wbr>builtins/assembly.h<br>
<br>
Modified: compiler-rt/trunk/lib/<wbr>builtins/arm/aeabi_uidivmod.S<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/builtins/arm/aeabi_uidivmod.S?rev=288777&r1=288776&r2=288777&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/compiler-rt/trunk/lib/<wbr>builtins/arm/aeabi_uidivmod.S?<wbr>rev=288777&r1=288776&r2=<wbr>288777&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- compiler-rt/trunk/lib/<wbr>builtins/arm/aeabi_uidivmod.S (original)<br>
+++ compiler-rt/trunk/lib/<wbr>builtins/arm/aeabi_uidivmod.S Tue Dec 6 01:13:15 2016<br>
@@ -23,6 +23,20 @@<br>
.syntax unified<br>
.p2align 2<br>
DEFINE_COMPILERRT_FUNCTION(__<wbr>aeabi_uidivmod)<br>
+#if __ARM_ARCH_ISA_THUMB == 1<br>
+ cmp r0, r1<br>
+ bcc LOCAL_LABEL(case_denom_larger)<br>
+ push {r0, r1, lr}<br>
+ bl SYMBOL_NAME(__aeabi_uidiv)<br>
+ pop {r1, r2, r3}<br>
+ muls r2, r2, r0 // r2 = quot * denom<br>
+ subs r1, r1, r2<br>
+ JMP (r3)<br>
+LOCAL_LABEL(case_denom_<wbr>larger):<br>
+ movs r1, r0<br>
+ movs r0, #0<br>
+ JMP (lr)<br>
+#else<br>
push { lr }<br>
sub sp, sp, #4<br>
mov r2, sp<br>
@@ -35,6 +49,7 @@ DEFINE_COMPILERRT_FUNCTION(__<wbr>aeabi_uidiv<br>
ldr r1, [sp]<br>
add sp, sp, #4<br>
pop { pc }<br>
+#endif<br>
END_COMPILERRT_FUNCTION(__<wbr>aeabi_uidivmod)<br>
<br>
NO_EXEC_STACK_DIRECTIVE<br>
<br>
Modified: compiler-rt/trunk/lib/<wbr>builtins/arm/udivsi3.S<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/builtins/arm/udivsi3.S?rev=288777&r1=288776&r2=288777&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/compiler-rt/trunk/lib/<wbr>builtins/arm/udivsi3.S?rev=<wbr>288777&r1=288776&r2=288777&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- compiler-rt/trunk/lib/<wbr>builtins/arm/udivsi3.S (original)<br>
+++ compiler-rt/trunk/lib/<wbr>builtins/arm/udivsi3.S Tue Dec 6 01:13:15 2016<br>
@@ -40,12 +40,26 @@ DEFINE_COMPILERRT_FUNCTION(__<wbr>udivsi3)<br>
#else<br>
cmp r1, #1<br>
bcc LOCAL_LABEL(divby0)<br>
+#if __ARM_ARCH_ISA_THUMB == 1<br>
+ bne LOCAL_LABEL(num_neq_denom)<br>
+ JMP(lr)<br>
+LOCAL_LABEL(num_neq_denom):<br>
+#else<br>
IT(eq)<br>
JMPc(lr, eq)<br>
+#endif<br>
cmp r0, r1<br>
+#if __ARM_ARCH_ISA_THUMB == 1<br>
+ bhs LOCAL_LABEL(num_ge_denom)<br>
+ movs r0, #0<br>
+ JMP(lr)<br>
+LOCAL_LABEL(num_ge_denom):<br>
+#else<br>
ITT(cc)<br>
movcc r0, #0<br>
JMPc(lr, cc)<br>
+#endif<br>
+<br>
/*<br>
* Implement division using binary long division algorithm.<br>
*<br>
@@ -62,7 +76,7 @@ DEFINE_COMPILERRT_FUNCTION(__<wbr>udivsi3)<br>
* that (r0 << shift) < 2 * r1. The quotient is stored in r3.<br>
*/<br>
<br>
-# ifdef __ARM_FEATURE_CLZ<br>
+# if defined(__ARM_FEATURE_CLZ)<br>
clz ip, r0<br>
clz r3, r1<br>
/* r0 >= r1 implies clz(r0) <= clz(r1), so ip <= r3. */<br>
@@ -77,49 +91,128 @@ DEFINE_COMPILERRT_FUNCTION(__<wbr>udivsi3)<br>
sub ip, ip, r3, lsl #3<br>
mov r3, #0<br>
bx ip<br>
-# else<br>
+# else /* No CLZ Feature */<br>
# if __ARM_ARCH_ISA_THUMB == 2<br>
# error THUMB mode requires CLZ or UDIV<br>
# endif<br>
+# if __ARM_ARCH_ISA_THUMB == 1<br>
+# define BLOCK_SIZE 10<br>
+# else<br>
+# define BLOCK_SIZE 12<br>
+# endif<br>
+<br>
mov r2, r0<br>
+# if __ARM_ARCH_ISA_THUMB == 1<br>
+ mov ip, r0<br>
+ adr r0, LOCAL_LABEL(div0block)<br>
+ adds r0, #1<br>
+# else<br>
adr ip, LOCAL_LABEL(div0block)<br>
-<br>
- lsr r3, r2, #16<br>
+# endif<br>
+ lsrs r3, r2, #16<br>
cmp r3, r1<br>
+# if __ARM_ARCH_ISA_THUMB == 1<br>
+ blo LOCAL_LABEL(skip_16)<br>
+ movs r2, r3<br>
+ subs r0, r0, #(16 * BLOCK_SIZE)<br>
+LOCAL_LABEL(skip_16):<br>
+# else<br>
movhs r2, r3<br>
- subhs ip, ip, #(16 * 12)<br>
+ subhs ip, ip, #(16 * BLOCK_SIZE)<br>
+# endif<br>
<br>
- lsr r3, r2, #8<br>
+ lsrs r3, r2, #8<br>
cmp r3, r1<br>
+# if __ARM_ARCH_ISA_THUMB == 1<br>
+ blo LOCAL_LABEL(skip_8)<br>
+ movs r2, r3<br>
+ subs r0, r0, #(8 * BLOCK_SIZE)<br>
+LOCAL_LABEL(skip_8):<br>
+# else<br>
movhs r2, r3<br>
- subhs ip, ip, #(8 * 12)<br>
+ subhs ip, ip, #(8 * BLOCK_SIZE)<br>
+# endif<br>
<br>
- lsr r3, r2, #4<br>
+ lsrs r3, r2, #4<br>
cmp r3, r1<br>
+# if __ARM_ARCH_ISA_THUMB == 1<br>
+ blo LOCAL_LABEL(skip_4)<br>
+ movs r2, r3<br>
+ subs r0, r0, #(4 * BLOCK_SIZE)<br>
+LOCAL_LABEL(skip_4):<br>
+# else<br>
movhs r2, r3<br>
- subhs ip, #(4 * 12)<br>
+ subhs ip, #(4 * BLOCK_SIZE)<br>
+# endif<br>
<br>
- lsr r3, r2, #2<br>
+ lsrs r3, r2, #2<br>
cmp r3, r1<br>
+# if __ARM_ARCH_ISA_THUMB == 1<br>
+ blo LOCAL_LABEL(skip_2)<br>
+ movs r2, r3<br>
+ subs r0, r0, #(2 * BLOCK_SIZE)<br>
+LOCAL_LABEL(skip_2):<br>
+# else<br>
movhs r2, r3<br>
- subhs ip, ip, #(2 * 12)<br>
+ subhs ip, ip, #(2 * BLOCK_SIZE)<br>
+# endif<br>
<br>
/* Last block, no need to update r2 or r3. */<br>
+# if __ARM_ARCH_ISA_THUMB == 1<br>
+ lsrs r3, r2, #1<br>
+ cmp r3, r1<br>
+ blo LOCAL_LABEL(skip_1)<br>
+ subs r0, r0, #(1 * BLOCK_SIZE)<br>
+LOCAL_LABEL(skip_1):<br>
+ movs r2, r0<br>
+ mov r0, ip<br>
+ movs r3, #0<br>
+ JMP (r2)<br>
+<br>
+# else<br>
cmp r1, r2, lsr #1<br>
- subls ip, ip, #(1 * 12)<br>
+ subls ip, ip, #(1 * BLOCK_SIZE)<br>
<br>
- mov r3, #0<br>
+ movs r3, #0<br>
<br>
JMP(ip)<br>
-# endif<br>
+# endif<br>
+# endif /* __ARM_FEATURE_CLZ */<br>
+<br>
<br>
#define IMM #<br>
+ /* due to the range limit of branch in Thumb1, we have to place the<br>
+ block closer */<br>
+LOCAL_LABEL(divby0):<br>
+ movs r0, #0<br>
+# if defined(__ARM_EABI__)<br>
+ bl __aeabi_idiv0 // due to relocation limit, can't use b.<br>
+# endif<br>
+ JMP(lr)<br>
<br>
+<br>
+#if __ARM_ARCH_ISA_THUMB == 1<br>
+#define block(shift) \<br>
+ lsls r2, r1, IMM shift; \<br>
+ cmp r0, r2; \<br>
+ blo LOCAL_LABEL(block_skip_##<wbr>shift); \<br>
+ subs r0, r0, r2; \<br>
+ LOCAL_LABEL(block_skip_##<wbr>shift) :; \<br>
+ adcs r3, r3 /* same as ((r3 << 1) | Carry). Carry is set if r0 >= r2. */<br>
+<br>
+ /* TODO: if current location counter is not not word aligned, we don't<br>
+ need the .p2align and nop */<br>
+ /* Label div0block must be word-aligned. First align block 31 */<br>
+ .p2align 2<br>
+ nop /* Padding to align div0block as 31 blocks = 310 bytes */<br>
+<br>
+#else<br>
#define block(shift) \<br>
cmp r0, r1, lsl IMM shift; \<br>
ITT(hs); \<br>
WIDE(addhs) r3, r3, IMM (1 << shift); \<br>
WIDE(subhs) r0, r0, r1, lsl IMM shift<br>
+#endif<br>
<br>
block(31)<br>
block(30)<br>
@@ -159,12 +252,14 @@ LOCAL_LABEL(div0block):<br>
JMP(lr)<br>
#endif /* __ARM_ARCH_EXT_IDIV__ */<br>
<br>
+#if __ARM_ARCH_EXT_IDIV__<br>
LOCAL_LABEL(divby0):<br>
- mov r0, #0<br>
-#ifdef __ARM_EABI__<br>
- b __aeabi_idiv0<br>
-#else<br>
- JMP(lr)<br>
+ mov r0, #0<br>
+# ifdef __ARM_EABI__<br>
+ b __aeabi_idiv0<br>
+# else<br>
+ JMP(lr)<br>
+# endif<br>
#endif<br>
<br>
END_COMPILERRT_FUNCTION(__<wbr>udivsi3)<br>
<br>
Modified: compiler-rt/trunk/lib/<wbr>builtins/assembly.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/builtins/assembly.h?rev=288777&r1=288776&r2=288777&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/compiler-rt/trunk/lib/<wbr>builtins/assembly.h?rev=<wbr>288777&r1=288776&r2=288777&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- compiler-rt/trunk/lib/<wbr>builtins/assembly.h (original)<br>
+++ compiler-rt/trunk/lib/<wbr>builtins/assembly.h Tue Dec 6 01:13:15 2016<br>
@@ -71,7 +71,8 @@<br>
#define ARM_HAS_BX<br>
#endif<br>
#if !defined(__ARM_FEATURE_CLZ) && \<br>
- (__ARM_ARCH >= 6 || (__ARM_ARCH == 5 && !defined(__ARM_ARCH_5__)))<br>
+ ((__ARM_ARCH >= 6 && __ARM_ARCH_PROFILE != 'M') || \<br>
+ (__ARM_ARCH == 5 && !defined(__ARM_ARCH_5__)))<br>
#define __ARM_FEATURE_CLZ<br>
#endif<br>
<br>
<br>
<br>
______________________________<wbr>_________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>