Re: GCC Vector Extensions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux