SSE (SIMD extensions) support in gcc

Posted by goldenmean on Stack Overflow See other posts from Stack Overflow or by goldenmean
Published on 2011-01-04T18:14:18Z Indexed on 2011/01/04 18:53 UTC
Read the original article Hit count: 191

Filed under:
|
|

Hi,

I see a code as below:

include "stdio.h"

#define VECTOR_SIZE         4
typedef float v4sf __attribute__ ((vector_size(sizeof(float)*VECTOR_SIZE))); 
 // vector of four single floats


typedef union f4vector
{
    v4sf    v;
    float   f[VECTOR_SIZE];
} f4vector;



void print_vector (f4vector *v)
{
    printf("%f,%f,%f,%f\n", v->f[0], v->f[1], v->f[2], v->f[3]);
}

int main()
{
    union f4vector a, b, c;

    a.v = (v4sf){1.2, 2.3, 3.4, 4.5};
    b.v = (v4sf){5., 6., 7., 8.};
    c.v = a.v + b.v;

    print_vector(&a);
    print_vector(&b);
    print_vector(&c);
}

This code builds fine and works expectedly using gcc (it's inbuild SSE / MMX extensions and vector data types. this code is doing a SIMD vector addition using 4 single floats.

I want to understand in detail what does each keyword/function call on this typedef line means and does:

typedef float v4sf __attribute__ ((vector_size(sizeof(float)*VECTOR_SIZE))); 

What is the vector_size() function return;

What is the __attribute__ keyword for

Here is the float data type being type defined to vfsf type?

I understand the rest part.

thanks,

-AD

© Stack Overflow or respective owner

Related posts about gcc

Related posts about sse