samturner
samturner

Reputation: 2223

Dynamically allocate SIMD Vector as array of doubles

I'm new to vectors and I've been having a read of the gcc documentation trying to get my head around it.

Is it possible to dynamically allocate the size of a vector at run time? It appears as though you have to do this in the typedef like:

typedef double v4sf __attribute__((vector_size (16)));

I want to set the values of the vector to an array of doubles. I've tried like so:

v4sf curr_vect = double_array;

Where double_array is obviously an array of doubles. But this fails to compile. Is it possible to do either of these things?

Upvotes: 2

Views: 273

Answers (1)

user529758
user529758

Reputation:

If your platform is POSIX-compliant, you can achieve aligned dynamic memory allocation using the posix_memalign() function:

double *p;
if (posix_memalign((void **)&p, 16, sizeof(*p) * 16) != 0) {
    perror("posix_memalign");
    abort();
}

p[0] = 3.1415927;
// ...

free(p);

Upvotes: 2

Related Questions