title: How to store the contents of a __m128d simd vector as doubles without accessing it as a union?
body: <p>The code i want to optimize is basically a simple but large arithmetic formula, it should be fairly simple to analyze the code automatically to compute the independent multiplications/additions in parallel, but i read that autovectorization only works for loops.</p>
  
  <p>I've read multiple times now that access of single elements in a vector via union or some other way should be avoided at all costs, instead should be replaced by a _mm_shuffle_pd (i'm working on doubles only)... </p>
  
  <p>I don't seem to figure out how I can store the content of a __m128d vector as doubles without accessing it as a union. Also, does an operation like this give any performance gain when compared to scalar code?</p>
  
  <pre><code>union {
    __m128d v;
    double d[2];
  } vec;
  union {
    __m128d v;
  double d[2];
  } vec2;
  
  vec.v = index1;
  vec2.v = index2;
  temp1 = _mm_mul_pd(temp1, _mm_set_pd(bvec[vec.d[1]], bvec[vec2[1]]));
  </code></pre>
  
  <p>also, the two unions look ridiculously ugly, but when using </p>
  
  <pre><code>union dvec {
    __m128d v;
    double d[2];
  } vec;
  </code></pre>
  
  <p>Trying to declare the indexX as dvec, the compiler complained dvec is undeclared.</p>