This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: GCC Vector Extensions


Christian Schoenebeck wrote:
> b) We wondered [2] what the currently best way is to access single elements of
> one vector. Currently the only solution we saw is to use a union trick

/* I don't know if this qualifies as good, but here's some things
   I've used before  */

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef float v4sf __attribute__ ((vector_size (16)));

int main()
{
    v4sf  a,b,c;
    float *z;

    ((float *)&a)[0] = 1.0;
    ((float *)&a)[1] = 2.0;
    ((float *)&a)[2] = 3.0;
    ((float *)&a)[3] = 4.0;
    
    memcpy((float *)&b,(float[]){0.5,0.6,0.7,0.8},4*sizeof(float));
    
    c = a + b;

    z = (float *)&c;
    
    printf("%f, %f, %f, %f\n", *z, *(z+1), z[2], z[3]);
  
    return 0;
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]