title: Fast interleave 2 double arrays into an array of structs with 2 float and 1 int (loop invariant) member, with SIMD double->float conversion?
body: <p>I have a section of code which is a bottleneck in a C++ application running on x86 processors, where we take double values from two arrays, cast to float and store in an array of structs. The reason this is a bottleneck is it is called either with very large loops, or thousands of times.</p>
  
  <p>Is there a faster way to do this copy &amp; cast operation using SIMD Intrinsics? I have seen <a href="https://stackoverflow.com/a/44948720/303612">this answer on faster memcpy</a> but doesn't address the cast. </p>
  
  <p>The simple C++ loop case looks like this</p>
  
  <pre><code>        int _iNum;
          const unsigned int _uiDefaultOffset; // a constant 
  
          double * pInputValues1; // array of double values, count = _iNum;
          double * pInputValues2; 
  
          MyStruct * pOutput;    // array of outputs defined as
          // struct MyStruct 
          // { 
          //    float O1;
          //    float O2;
          //    unsigned int Offset;
          // };
  
          for (int i = 0; i &lt; _iNum; ++i)
          {
              _pPoints[i].O1 = static_cast&lt;float&gt;(pInputValues1[i]);
              _pPoints[i].O2 = static_cast&lt;float&gt;(pInputValues2[i]);
              _pPoints[i].Offset = _uiDefaultOffset;
          }
  </code></pre>
  
  <p><strong><em>Note:</strong> The struct format is [Float,Float,Int] (24 bytes) but we could (if it will help performance) add an extra 4bytes padding making it 32 bytes.</em> </p>