views:

21

answers:

2

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.

+1  A: 

Likely not, however you can try using a restrict pointer which will reduce aliasing concerns in the compiler and potentially produce better code.

Yann Ramin
Thanks for introducing restrict keyword. I'll dig it.
Eonil
A: 

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.

Paul R
Oh I'm sorry. I added Vector's definition and target hardware.
Eonil
OK - in that case I would suggest vectorizing this by hand - it's pretty trivial - use the Neon intrinsics for gcc rather than resorting to assembler.
Paul R
Thanks for suggestion here and other question :)
Eonil