06.02.2013 Views

ARM Compiler toolchain Using the Linker - ARM Information Center

ARM Compiler toolchain Using the Linker - ARM Information Center

ARM Compiler toolchain Using the Linker - ARM Information Center

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

5.14 Factors that influence function inlining<br />

5.14.1 See also<br />

The following factors influence <strong>the</strong> way functions are inlined:<br />

<strong>Using</strong> linker optimizations<br />

• The linker handles only <strong>the</strong> simplest cases and does not inline any instructions that read<br />

or write to <strong>the</strong> PC because this depends on <strong>the</strong> location of <strong>the</strong> function.<br />

• If your image contains both <strong>ARM</strong> and Thumb code, functions that are called from <strong>the</strong><br />

opposite state must be built for interworking. The linker can inline functions containing<br />

up to two 16-bit Thumb instructions. However, an <strong>ARM</strong> calling function can only inline<br />

functions containing a single 16-bit Thumb instruction or 32-bit Thumb-2 instruction.<br />

• The action that <strong>the</strong> linker takes depends on <strong>the</strong> size of <strong>the</strong> function being called. The<br />

following table shows <strong>the</strong> state of both <strong>the</strong> calling function and <strong>the</strong> function being called:<br />

Calling function<br />

state<br />

Called function<br />

state<br />

The linker can inline in different states if <strong>the</strong>re is an equivalent instruction available. For<br />

example, if a Thumb instruction is adds r0, r0 <strong>the</strong>n <strong>the</strong> linker can inline <strong>the</strong> equivalent<br />

<strong>ARM</strong> instruction. It is not possible to inline from <strong>ARM</strong> to Thumb because <strong>the</strong>re is less<br />

chance of Thumb equivalent to an <strong>ARM</strong> instruction.<br />

• For a function to be inlined, <strong>the</strong> last instruction of <strong>the</strong> function must be ei<strong>the</strong>r:<br />

MOV pc, lr<br />

or<br />

BX lr<br />

A function that consists only of a return sequence can be inlined as a NOP.<br />

• A conditional <strong>ARM</strong> instruction can only be inlined if ei<strong>the</strong>r:<br />

— The condition on <strong>the</strong> BL matches <strong>the</strong> condition on <strong>the</strong> instruction being inlined. For<br />

example, BLEQ can only inline an instruction with a matching condition like ADDEQ.<br />

— The BL instruction or <strong>the</strong> instruction to be inlined is unconditional. An unconditional<br />

<strong>ARM</strong> BL can inline any conditional or unconditional instruction that satisfies all <strong>the</strong><br />

o<strong>the</strong>r criteria. An instruction that cannot be conditionally executed cannot be inlined<br />

if <strong>the</strong> BL instruction is conditional.<br />

• A BL that is <strong>the</strong> last instruction of a Thumb-2 If-Then (IT) block cannot inline a 16-bit<br />

Thumb instruction or a 32-bit MRS, MSR, or CPS instruction. This is because <strong>the</strong> IT block<br />

changes <strong>the</strong> behavior of <strong>the</strong> instructions within its scope so inlining <strong>the</strong> instruction<br />

changes <strong>the</strong> behavior of <strong>the</strong> program.<br />

Concepts<br />

• Handling branches that optimize to a NOP on page 5-21.<br />

<strong>Using</strong> <strong>the</strong> Assembler:<br />

• Conditional instructions on page 6-2.<br />

Table 5-1 Inlining small functions<br />

<strong>ARM</strong> <strong>ARM</strong> 4 to 8 bytes<br />

<strong>ARM</strong> Thumb 2 to 6 bytes<br />

Called function size<br />

Thumb Thumb 2 to 6 bytes<br />

<strong>ARM</strong> DUI 0474C Copyright © 2010-2011 <strong>ARM</strong>. All rights reserved. 5-19<br />

ID080411 Non-Confidential

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!