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> Features<br />

4.1 <strong>Compiler</strong> intrinsics<br />

The C and C++ languages are suited to a wide variety of tasks but <strong>the</strong>y do not provide inbuilt<br />

support <strong>for</strong> specific areas of application, <strong>for</strong> example, Digital Signal Processing (DSP).<br />

Within a given application domain, <strong>the</strong>re is usually a range of domain-specific operations that<br />

have to be per<strong>for</strong>med frequently. However, often <strong>the</strong>se operations cannot be efficiently<br />

implemented in C or C++. A typical example is <strong>the</strong> saturated add of two 32-bit signed two’s<br />

complement integers, commonly used in DSP programming. Example 4-1 shows its<br />

implementation in C.<br />

Example 4-1 C implementation of saturated add operation<br />

#include <br />

int L_add(const int a, const int b)<br />

{<br />

int c;<br />

c = a + b;<br />

if (((a ^ b) & INT_MIN) == 0)<br />

{<br />

if ((c ^ a) & INT_MIN)<br />

{<br />

c = (a < 0) ? INT_MIN : INT_MAX;<br />

}<br />

}<br />

return c;<br />

}<br />

<strong>Compiler</strong> intrinsics are functions provided by <strong>the</strong> compiler. They enable you to easily<br />

incorporate domain-specific operations in C and C++ source code without resorting to complex<br />

implementations in assembly language. <strong>Using</strong> compiler intrinsics, you can achieve more<br />

complete coverage of target architecture instructions than you would from <strong>the</strong> instruction<br />

selection of <strong>the</strong> compiler.<br />

An intrinsic function has <strong>the</strong> appearance of a function call in C or C++, but is replaced during<br />

compilation by a specific sequence of low-level instructions. When implemented using an<br />

intrinsic, <strong>for</strong> example, <strong>the</strong> saturated add function of Example 4-1 has <strong>the</strong> <strong>for</strong>m:<br />

#include /* Include ETSI intrinsics */<br />

...<br />

int a, b, result;<br />

...<br />

result = L_add(a, b); /* Saturated add of a and b */<br />

4.1.1 See also<br />

Concepts<br />

• Per<strong>for</strong>mance benefits of compiler intrinsics on page 4-5<br />

• <strong>ARM</strong> assembler instruction intrinsics supported by <strong>the</strong> compiler on page 4-6<br />

• European Telecommunications Standards Institute (ETSI) basic operations on page 4-12<br />

• Texas Instruments (TI) C55x intrinsics <strong>for</strong> optimizing C code on page 4-15.<br />

Reference<br />

<strong>Compiler</strong> Reference:<br />

• Instruction intrinsics on page 5-61<br />

• ETSI basic operations on page 5-89<br />

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

ID061811<br />

Non-Confidential

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

Saved successfully!

Ooh no, something went wrong!