c++ how to write code the compiler can easily optimize for SIMD?

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

So the compiler will try to batch instructions together in order to make use of SIMD instructions?

Are there any rules one can follow in how to optimize code such that the compiler can make effiecient assembler using these extensions?

For example currently i'm working on a raytracer. A shader takes some input and calculates from the input an output color, like this:

PixelData data = RayTracer::gatherPixelData(pixel.x, pixel.y);
Color col = shadePixel(data);

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:

PixelData data1 = RayTracer::gatherPixelData(pixel1.x, pixel1.y);
...
shadePixels(data1, data2, data3, data4, &col1out, &col2out, &col3out, &col4out);

to process multiple dataunits at once. would This be beneficial for making the compiler use SSE instructions?

thanks!

7
задан Mat 26 October 2010 в 20:27
поделиться