Re: Accessing the vector elements

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

 



Chris Lattner <clattner@xxxxxxxxx> writes:

> >     union
> >     {
> >       vectortype v;
> >       float af[4];
> >     } u;
> >     u.v = v;
> >     return u.af[0];
> >
> > Ian
> 
> Or, alternatively:
> 
> vectortype v;
> 
> elementtype e = ((elementtype*)&v)[1]

Well, I don't recommend that in general.  gcc currently has an
exception to the aliasing rules, and treats vectortype* and
elementtype* as being in the same alias set.  But at my previous
company, we got significantly better generated code in some cases by
breaking that aliasing.  In particular this aliasing forces a pointer
to a vector of char to alias char* and therefore alias everything.
But if the compiler breaks that aliasing, then your suggestion of
using a cast will fail in some cases.

Ian

[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