views:

73

answers:

3
A: 

A life lesson about coding till 3am in the morning.....

I never tried just using the unary minus on my packed vector. That actually compiles and has the exact same performance as the non-SIMD approach.

nsanders
Beware though - using gcc-specific extensions like this this makes your code non-portable.
Paul R
+1  A: 

Just to complete your own answer by the gcc documentation about these builtin vectors:

The types defined in this manner can be used with a subset of normal C
operations.  Currently, GCC will allow using the following operators on
these types: `+, -, *, /, unary minus, ^, |, &, ~'.

It is probably a good idea to always stick to these when possible. With very high chances gcc will always provide the most efficient code for this SSE stuff.

For your compiler options, add something more specific to your architecture, something like -march=native will do in most cases.

Jens Gustedt
+1  A: 

That union is not really needed, best of all worlds (readability, speed and portability):

_mm_xor_ps(vec, _mm_set1_ps(-0.f))
LiraNuna