An Introduction to GCC Compiler Intrinsics in Vector Processing

Sep 21, 2012 By George Koharchik and Kathy Jones  inHOW-TOsMath

Speed is essential in multimedia, graphics and signalprocessing. Sometimes programmers resort to assembly language to getevery last bit of speed out of their machines. GCC offers an intermediatebetween assembly and standard C that can get you more speed and processorfeatures without having to go all the way to assembly language: compilerintrinsics. This article discusses GCC's compiler intrinsics, emphasizingvector processing on three platforms: X86 (using MMX, SSE and SSE2);Motorola, now Freescale (using Altivec); and ARM Cortex-A (using Neon).We conclude with some debugging tips and references.

Download the sample code for this articlehere: http://www.linuxjournal.com/files/linuxjournal.com/code/11108.tar

So, What Are Compiler Intrinsics?

Compiler intrinsics (sometimes called "builtins") are like thelibrary functions you're used to, except they're built in to thecompiler. They may be faster than regular library functions (thecompiler knows more about them so it can optimize better) or handlea smaller input range than the library functions. Intrinsics alsoexpose processor-specific functionality so you can use them as anintermediate between standard C and assembly language. This gives youthe ability to get to assembly-like functionality, but still let thecompiler handle details like type checking, register allocation,instruction scheduling and call stack maintenance. Some builtins areportable, others are not--they are processor-specific. You can findthe lists of the portable and target specific intrinsics in the GCCinfo pages and the include files (more about that below). Thisarticle focuses on the intrinsics useful for vector processing.

Vectors and Scalars

In this article, a vector is an ordered collection of numbers, likean array. If all the elements of a vector are measures of the samething, it's said to be a uniform vector. Non-uniform vectors haveelements that represent different things, and their elements have to beprocessed differently. In software, vectors have their own types andoperations. A scalar is a single value, a vector of size one. Codethat uses vector types and operations is said to be vector code. Codethat uses only scalar types and operations is said to be scalar code.

Vector Processing Concepts

Vector processing is in the category of Single Instruction, MultipleData (SIMD). In SIMD, the same operation happens to all the data (thevalues in the vector) at the same time. Each value in the vector iscomputed independently. Vector operations include logic and math. Mathwithin a single vector is called horizontal math. Mathbetween two vectors is called vertical math.

Instead of writing: 10 x 2

View the Original article

No comments:

Post a Comment

Thank You , For Immediate Assistance Plz Put Email Copy to Deviceporting@gmail.com