Can operations be auto-vectorized on struct's field referenced by pointer?
This is my code.
struct Vector
{
float x, y, z, w;
};
typedef struct Vector Vector;
inline void inv(Vector* target)
{
(*target).x = -(*target).x;
(*target).y = -(*target).y;
(*target).z = -(*target).z开发者_高级运维;
(*target).w = -(*target).w;
}
I'm using GCC for ARM (iPhone). Can this be vectorized?
PS: I'm trying some kind of optimization. Any recommendations are welcome.
Likely not, however you can try using a restrict pointer which will reduce aliasing concerns in the compiler and potentially produce better code.
It depends on how Vector is defined, but it may be possible. If you're looking for auto-vectorization then try Intel's ICC (assuming we're talking about x86 here ?), which does a pretty good job in certain cases (much better than gcc), although it can always be improved upon by explicit vectorization by hand of course, since the programmer knows more about the program than the compiler can every imply from the source code alone.
精彩评论