Floating point math on the Xbox360

From XNAWiki
Jump to: navigation, search

Floating point math using the Xbox360 CLR is less than desirable at the moment. It isn't that the 360 itself isn't capable of fast floating point calculations, it is just that through XNA we must use the Xbox CLR (common language runtime), which is immature and does very little to optimize any floating point math in the code.

You can help out by doing your own optimizations. Here are some of the easy ways to increase the floating point performance.

Use the math functions in place of overloaded operators

// Standard vector addition Vector3 first; Vector3 second; first += second;

// This will produce slightly more optimized results Vector3.Add(first, second);

Do your own inlining

This method will perform better than the method above: // Standard vector addition Vector3 first; Vector3 second; first += second;

// Manually inlined addition (will be faster on the 360) first.X += second.X; first.Y += second.Y; first.Z += second.Z;

This isn't just for vectors, it is for all floating point related math. Vectors and Matrices tend to be a good portion of floating point math for games. I haven't done much with them, but Quaternions may be affected as well.

If you would like to use the first method, know that there are Add(), Subtract(), Multiply() and Divide() functions for Vectors and Matrices both.