[LLVMdev] Vector code

Duncan Sands baldrick at free.fr
Thu May 8 12:29:50 PDT 2008


> I assume that's the same as the online demo's "Show LLVM C++ API code"
> option (http://llvm.org/demo/)? I've tried that with a structure containing
> four floating-point components but it also appears to add them individually
> using extract/insert. Maybe I have to try an array of floats...

You need to use gcc's vector extensions.

Ciao,

Duncan.

>From the gcc docs:

5.43 Using vector instructions through built-in functions
=========================================================

On some targets, the instruction set contains SIMD vector instructions
that operate on multiple values contained in one large register at the
same time.  For example, on the i386 the MMX, 3Dnow! and SSE extensions
can be used this way.

 The first step in using these extensions is to provide the necessary
data types.  This should be done using an appropriate `typedef':

     typedef int v4si __attribute__ ((vector_size (16)));

 The `int' type specifies the base type, while the attribute specifies
the vector size for the variable, measured in bytes.  For example, the
declaration above causes the compiler to set the mode for the `v4si'
type to be 16 bytes wide and divided into `int' sized units.  For a
32-bit `int' this means a vector of 4 units of 4 bytes, and the
corresponding mode of `foo' will be V4SI.

 The `vector_size' attribute is only applicable to integral and float
scalars, although arrays, pointers, and function return values are
allowed in conjunction with this construct.

 All the basic integer types can be used as base types, both as signed
and as unsigned: `char', `short', `int', `long', `long long'.  In
addition, `float' and `double' can be used to build floating-point
vector types.




More information about the llvm-dev mailing list