title: Stream intrinsic degrades performance
body: <p>I'm playing around with the _mm_stream_ps intrinsic and I'm having some trouble with understanding its performance.</p>
  
  <p>Here is a code snippet that I'm working with... 
  Stream version:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdint.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;omp.h&gt;
  
  #include &lt;immintrin.h&gt;
  
  #define NUM_ELEMENTS 10000000L
  
  static void copy_temporal(float* restrict x, float* restrict y)
  {
     for(uint64_t i = 0; i &lt; NUM_ELEMENTS/2; ++i){
        _mm_store_ps(y,_mm_load_ps(x));
        _mm_store_ps(y+4,_mm_load_ps(x+4));
        x+=8;
        y+=8;
     }
  }
  static void copy_nontemporal(float* restrict x, float* restrict y)
  {
     for(uint64_t i = 0; i &lt; NUM_ELEMENTS/2; ++i){
        _mm_stream_ps(y,_mm_load_ps(x));
        _mm_stream_ps(y+4,_mm_load_ps(x+4));
        x+=8;
        y+=8;
     }
  }
  
  int main(int argc, char** argv)
  {
     uint64_t sizeX = sizeof(float) * 4 * NUM_ELEMENTS;
     float *x = (float*) _mm_malloc(sizeX,32);
     float *y = (float*) _mm_malloc(sizeX,32);
  
     //initialization
     for(uint64_t i = 0 ; i &lt; 4 * NUM_ELEMENTS; ++i){
        x[i] = (float)rand()/RAND_MAX;
        y[i] = 0;
     }
  
     printf("%g MB allocated\n",(2 * sizeX)/1024.0/1024.0); 
  
     double start = omp_get_wtime();
     copy_nontemporal(x, y);
     double time = omp_get_wtime() - start;
     printf("Bandwidth (non-temporal): %g GB/s\n",((3 * sizeX)/1024.0/1024.0/1024.0)/time);
  
     start = omp_get_wtime();
     copy_temporal(x, y);
     time = omp_get_wtime() - start;
     printf("Bandwidth: %g GB/s\n",((3 * sizeX)/1024.0/1024.0/1024.0)/time);
  
     _mm_free(x);
     _mm_free(y);
  
     return 0;
  }
  </code></pre>
  
  <p>Performance results:</p>
  
  <pre><code>2.3 GHz Core i7 (I7-3615QM) (Laptop):
      305.176 MB allocated
      Bandwidth (non-temporal): 24.2242 GB/s
      Bandwidth: 21.4136 GB/s
  
  Xeon(R) CPU E5-2650 0 @ 2.00GHz (cluster (exclusive job)):
      305.176 MB allocated
      Bandwidth (non-temporal): 8.33133 GB/s
      Bandwidth: 8.20684 GB/s
  </code></pre>
  
  <p>What really puzzles me is that I see better performance -- on the Xeon CPU (not on my laptop) -- if I use the non-aligned loads and stores (i.e. storeu_ps/ loadu_ps):</p>
  
  <pre><code>305.176 MB allocated
  Bandwidth (non-temporal): 8.30105 GB/s
  Bandwidth: 12.7056 GB/s
  </code></pre>
  
  <p>I would expect the stream-version to be faster than the non-stream version -- due to the redundant loads of y. However, measurements show that the stream-version is actually two times slower than the non-stream version.</p>
  
  <p>Do you have any explanation for this?</p>
  
  <p>Compiler used: Intel 14.0.1;
  Compiler flags: -O3 -restrict -xAVX;
  CPU used: Intel Xeon E5-2650;</p>
  
  <p>Thank you.</p>