title: Casting an [Float] to [simd_float4] in Swift
body: <p>I have this c function that I call from Swift but I think it should be possible to implement in Swift, the trick is to be able to cast the memory for the array of floats to an array of simd_float4. Below is my c function and how I call it in Swift</p>
  
  <p>swift</p>
  
  <pre><code>sumFloats(&amp;y, y1, n, anAmplitudes[z]);
  </code></pre>
  
  <p>C</p>
  
  <pre><code>void sumFloats(float * y, const float * x, const int yc, const float a) {
      simd_float4 theA = simd_make_float4(a,a,a,a);
      simd_float4 * theY = (simd_float4*)y;
      simd_float4 * theX = (simd_float4*)x;
      assert( (yc&amp;0x3) == 0 );
      for( int t = 0, theYC = yc &gt;&gt; 2; t &lt; theYC; t ++ ) {
          theY[t] += theA * theX[t];
      }
  }
  </code></pre>
  
  <p>also my understanding is an Array doesn't guarantee a continuous block of memory so there must some conversion going on when calling the C code, I can probable fix that by using a ContiguousArray, but I can't use a ContiguousArray to call C.</p>