Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to do optimization with C code in Xcode
    text
    copied!<p>here is a piece of code like this:</p> <pre><code>// example_3 int Add_8K_3(int* in, int* out, int b) { int i; for(i=0;i&lt;1024;i++) { int a0, a1; a0 = *in++; a1 = *in++; *out++ = a0 + b; *out++ = a1 + b; } return 0; } </code></pre> <p>I compile it by both ARMCC and Xcode (by -O3). But the performance of two results are much different. the cycle number in Xcode is about 3 times than armcc result. arm asm code</p> <pre><code> { Add_8K_3 PROC ADD r0,r0,#4 MOV r3,#0x400 PUSH {r4} ;3264 |L1.12| SUBS r3,r3,#1 LDR r4,[r0,#-4] ;3271 LDR r12,[r0],#8 ;3271 ADD r4,r4,r2 ;3271 STR r4,[r1],#8 ADD r12,r12,r2 STR r12,[r1,#-4] BNE |L1.12| POP {r4} MOV r0,#0 BX lr ENDP } </code></pre> <p>Xcode asm code</p> <pre><code> { _Add_8K_3: .cfi_startproc Lfunc_begin3: .loc 1 77 0 @ /Users/Emedia/Desktop/testperformance/testperformance/core.c:77:0 @ BB#0: .loc 1 76 19 prologue_end @ /Users/Emedia/Desktop/testperformance/testperformance/core.c:76:19 push {r7, lr} mov.w lr, #0 Ltmp15: @DEBUG_VALUE: i &lt;- 0+0 mov r7, sp @DEBUG_VALUE: Add_8K_3:in &lt;- R0+0 @DEBUG_VALUE: Add_8K_3:out &lt;- R1+0 @DEBUG_VALUE: Add_8K_3:b &lt;- R2+0 LBB3_1: @ =&gt;This Inner Loop Header: Depth=1 Ltmp16: @DEBUG_VALUE: Add_8K_3:in &lt;- R0+0 @DEBUG_VALUE: Add_8K_3:out &lt;- R1+0 @DEBUG_VALUE: Add_8K_3:b &lt;- R2+0 @DEBUG_VALUE: i &lt;- 0+0 .loc 1 82 9 @ /Users/Emedia/Desktop/testperformance/testperformance/core.c:82:9 ldr.w r12, [r0, lr, lsl #3] Ltmp17: @DEBUG_VALUE: a0 &lt;- R12+0 add.w r3, r0, lr, lsl #3 .loc 1 83 9 @ /Users/Emedia/Desktop/testperformance/testperformance/core.c:83:9 ldr.w r9, [r3, #4] Ltmp18: @DEBUG_VALUE: a1 &lt;- R9+0 .loc 1 86 9 @ /Users/Emedia/Desktop/testperformance/testperformance/core.c:86:9 add.w r3, r12, r2 str.w r3, [r1, lr, lsl #3] add.w r12, r1, lr, lsl #3 Ltmp19: .loc 1 79 20 @ /Users/Emedia/Desktop/testperformance/testperformance/core.c:79:20 add.w lr, lr, #1 Ltmp20: @DEBUG_VALUE: i &lt;- LR+0 .loc 1 87 9 @ /Users/Emedia/Desktop/testperformance/testperformance/core.c:87:9 add.w r3, r9, r2 str.w r3, [r12, #4] Ltmp21: .loc 1 79 9 @ /Users/Emedia/Desktop/testperformance/testperformance/core.c:79:9 cmp.w lr, #1024 bne LBB3_1 Ltmp22: @ BB#2: movs r0, #0 .loc 1 93 5 @ /Users/Emedia/Desktop/testperformance/testperformance/core.c:93:5 pop {r7, pc} Ltmp23: Lfunc_end3: } </code></pre> <p>The problem i could get is that Xcode can't parse the "in[X]" by suitable asm code. And my question is: (1) How can i write the C code to generate the asm code that the Xcode could parse "in[X]" to suitable asm code like arm? (2) Is there some manual to describe the compiler difference with clang and armcc, and tell me how to write C code for iOS by high performance.</p> <p>Thx.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload