29.10.2014 Views

ARM Compiler toolchain v4.1 for µVision Using the Compiler

ARM Compiler toolchain v4.1 for µVision Using the Compiler

ARM Compiler toolchain v4.1 for µVision Using the Compiler

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Compiler</strong> Coding Practices<br />

5.42 Example of hardware and software support differences <strong>for</strong> floating-point<br />

arithmetic<br />

Example 5-2 shows a function implementing floating-point arithmetic in C code.<br />

Example 5-2 Floating-point arithmetic implemented in C code<br />

float foo(float num1, float num2)<br />

{<br />

float temp, temp2;<br />

temp = num1 + num2;<br />

temp2 = num2 * num2;<br />

return temp2 - temp;<br />

}<br />

When <strong>the</strong> C code of Example 5-2 is compiled with <strong>the</strong> command-line options --cpu 5TE and<br />

--fpu softvfp, <strong>the</strong> compiler produces machine code with <strong>the</strong> disassembly shown in<br />

Example 5-3. In Example 5-3, floating-point arithmetic is per<strong>for</strong>med in software through calls<br />

to library routines such as __aeabi_fmul.<br />

Example 5-3 Support <strong>for</strong> floating-point arithmetic in software<br />

||foo|| PROC<br />

PUSH<br />

MOV<br />

BL<br />

MOV<br />

MOV<br />

MOV<br />

BL<br />

MOV<br />

POP<br />

B<br />

ENDP<br />

{r4-r6, lr}<br />

r4, r1<br />

__aeabi_fadd<br />

r5, r0<br />

r1, r4<br />

r0, r4<br />

__aeabi_fmul<br />

r1, r5<br />

{r4-r6, lr}<br />

__aeabi_fsub<br />

However, when <strong>the</strong> C code of Example 5-2 is compiled with <strong>the</strong> command-line option --fpu<br />

vfp, <strong>the</strong> compiler produces machine code with <strong>the</strong> disassembly shown in Example 5-4. In<br />

Example 5-4, floating-point arithmetic is per<strong>for</strong>med in hardware through floating-point<br />

arithmetic instructions such as VMUL.F32.<br />

Example 5-4 Support <strong>for</strong> floating-point arithmetic in hardware<br />

||foo|| PROC<br />

VADD.F32 s2, s0, s1<br />

VMUL.F32 s0, s1, s1<br />

VSUB.F32 s0, s0, s2<br />

BX lr<br />

ENDP<br />

5.42.1 See also<br />

Concepts<br />

• Default selection of hardware or software floating-point support on page 5-55<br />

<strong>ARM</strong> DUI 0375C Copyright © 2007-2008, 2011 <strong>ARM</strong>. All rights reserved. 5-56<br />

ID061811<br />

Non-Confidential

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

Saved successfully!

Ooh no, something went wrong!