title: Get an arbitrary float from a simd register at runtime?
body: <p>I want to access an arbitrary float from a simd register. I know that I can do things like:</p>
  
  
  
  <pre class="lang-c++ prettyprint-override"><code>float get(const __m128i&amp; a, const int idx){
      // editor's note: this type-puns the FP bit-pattern to int and converts to float
      return _mm_extract_ps(a,idx);
  }
  </code></pre>
  
  <p>or </p>
  
  <pre class="lang-c++ prettyprint-override"><code>float get(const __m128i&amp; a, const int idx){
      return _mm_cvtss_f32(_mm_shuffle_ps(a,_MM_SHUFFLE(0,0,0,idx));
  }
  </code></pre>
  
  <p>or even using a shift instead of a shuffle. The problem is that these all require idx to be known at compile time (shuffle, shift, and extract all require an 8bit immediate).</p>
  
  <p>I could also do it using <code>_mm_store_ps()</code> and then using the resulting array, but that would require going out to memory. Is there any way of doing it faster than that?</p>
  
  <p>Edit: Ignore the first code snippet, I wanted the float at that position, not as an int, like <code>_mm_extract_ps</code> returns.</p>