title: c++ how to write code the compiler can easily optimize for SIMD?
body: <p>i'm working in Visual Studio 2008 and in the project settings I see the option for "activate Extended Instruction set" which I can set to None, SSE or SSE2</p>
  
  <p>So the compiler will try to batch instructions together in order to make use of SIMD instructions?</p>
  
  <p>Are there any rules one can follow in how to optimize code such that the compiler can make effiecient assembler using these extensions?</p>
  
  <p>For example currently i'm working on a raytracer. A shader takes some input and calculates from the input an output color, like this:</p>
  
  <pre><code>PixelData data = RayTracer::gatherPixelData(pixel.x, pixel.y);
  Color col = shadePixel(data);
  </code></pre>
  
  <p>would it for example be beneficial to write the shadercode such that it would shade 4 different pixels within one instruction call? something like this:</p>
  
  <pre><code>PixelData data1 = RayTracer::gatherPixelData(pixel1.x, pixel1.y);
  ...
  shadePixels(data1, data2, data3, data4, &amp;col1out, &amp;col2out, &amp;col3out, &amp;col4out);
  </code></pre>
  
  <p>to process multiple dataunits at once. would This be beneficial for making the compiler use SSE instructions?</p>
  
  <p>thanks!</p>