Enable SIMD support in Mango

We had all heard of the upcoming SIMD support in Mango and how it greatly improved the performance of XNA’s Vector and Matrix types.  What we didn’t know was that it is not enabled on your game by default.  Read on for how to get it enabled in your game.

SIMD code generation is controlled by specifying an attribute on your assembly.  The new CodeGenerationAttribute uses the CodeGenerationFlags enum to tell the JIT compiler that it “may use SIMD instructions for certain vector and matrix operations”.  Add the following line to your AssemblyInfo.cs file:

[assembly: CodeGeneration(CodeGenerationFlags.EnableFPIntrinsicsUsingSIMD)]

 

For any CPU-heavy operations, such as physics (as long as the physics code uses XNA’s vector and matrix types) and CPU animation skinning, this should certainly give a performance boost to your game.  Or at least free up some CPU for other things.

Thanks Nick Gravelyn for the AppHub post.

Addendum: I should add that SIMD instructions may produce slightly different results than the regular versions.  If you do enable SIMD instructions, make sure you comprehensively test your game to make sure there are no unexpected surprises, say an AI might go slightly to the left and brush up against something when it missed that object previously.  These differences are expected to be minor and mostly insignificant, and most developers won’t even notice.  Some intensive mathematic operations that have little room for error may end up with slightly different results.

Leave a Reply

Your email address will not be published. Required fields are marked *

*


− 3 = five

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>