GCC optimisation: use of ARM conditional instructions?

Seeing some actual assembly would make things clear, but I suspect that the default settings for iOS compilation prefer generation of Thumb code instead of ARM for better code density. While there are pseudo-conditional instructions in Thumb32 aka Thumb-2 (supported in ARMv7 architecture via the IT instruction), the original Thumb16 only has conditional branches. Also, even in ARM mode there are some instructions that cannot be conditional (e.g. Many NEON instructions use the extended opcode space with condition field set to NV).

Up vote 3 down vote favorite 1 share g+ share fb share tw.

I'm looking at some code compiled for iOS in XCode (so compiled for ARM with gcc) and as far as I can see, the compiler has never used ARM's feature of allowing arbitrary instructions to have a condition attached to them, but instead always branches on a condition as would be the case on Intel and other architectures. Is this simply a restriction of GCC (I can understand that it might be: that "condition = branch" is embedded at a too high a level in the compiler architecture to allow otherwise), or is there a particular optimisation flag that needs to be turned on to allow compilation of conditional instructions? (Obviously I appreciate I'm making big assumptions about where use of conditional instructions "ought" to be used and would actually be an optimisation, but I have experience of programming earlier ARM chips and using and analysing the output of Acorn's original ARM C compiler, so I have a rough idea.

) Update: Having investigated this more thanks to the information below, it turns out that: XCode compiles in Thumb-2 mode, in which conditional execution of arbitrary instructions is not available; Under some circumstances, it does however use the ITE (if-then-else) instruction to effectively produce instructions with conditional execution. Ios gcc arm link|improve this question edited Apr 20 '11 at 23:02 asked Apr 19 '11 at 19:38Neil Coffey7,7431331 67% accept rate.

I don't think what you are seeing is true (see for ex this email thread about the subject - ok it's about bugs in it, but still). Are you setting the right optimization and target cpu types? – Mat Apr 19 '11 at 20:01 Well, in a sense that's what I'm trying to find out: what is the "right optimization"...! Thanks for the link-- I'll see if that specific example gets compiled with conditional execution.

– Neil Coffey Apr 19 '11 at 20:11 they're documented: gcc.gnu.org/onlinedocs/gcc/ARM-Options.html – Mat Apr 19 '11 at 20:12 Conditional execution of ARM instructions is not always faster, although it may be smaller. In LLVM, the decision is made in llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/… in either of the ARMBaseInstrInfo::isProfitableToIfCvt() overloads. – ohmantics Apr 20 '11 at 11:13 Have updated question: turns out that XCode compiles in Thumb mode.

However, I've tried the code mentioned in the e-mail indicated by Mat, and XCode compiles to a sequence of ITE/MOVEQ/MOVNE which is available in Thumb mode. So conditional execution is apparently being used under some circumstances and it isn't to do with optimisation options per se. – Neil Coffey Apr 20 '11 at 23:05.

Thumb-2 is indeed the default for Xcode projects. – ohmantics Apr 20 '11 at 11:07 Aah thank you that would explain it I think! – Neil Coffey Apr 20 '11 at 16:01.

Yes, gcc does not really produce the most optimal code WRT conditional instructions. It works well in the most simple cases, but real code suffers from some pointless slowdowns that can be avoided in hand coded arm ASM. Just to give you a rough idea, I was able to get a 2x speedup for a very low level graphics blit method by doing the read/write and copy logic in ARM asm instead of the C code emitted by gcc.

But, keep in mind that this optimization is only worth it for the most heavily used parts of your code. It takes a lot of work to write well optimized ARM asm, so don't even attempt it unless there is a real benefit in the optimization. The first thing to keep in mind is that xcode uses Thumb mode by default, so in order to generate ARM asm you will need to add the -mno-thumb option to the module specific options for the specific .

C file that will contain the ARM asm. Once the ARM asm is getting emitted, you will want to conditionally compile asm statements as indicated in the answer to the following question: ARM asm conditional compilation question.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions