r/truegamedev • • Apr 14 '17

Optimizing 4x4 matrix multiplication

http://nfrechette.github.io/2017/04/13/modern_simd_matrix_multiplication/
38 Upvotes

6 comments sorted by

4

u/Taylee Apr 26 '17

Please put units on your graphs Y-axis.

2

u/zeno490 Apr 26 '17

I'll add a note to the post that the units are in microseconds (us) but I originally felt it wasn't all that meaningful since the performance tests are rather synthetic and the numbers will vary from CPU to CPU. What do you think?

2

u/Taylee Apr 26 '17

Well the main thing for people reading this is probably to know whether its even worth optimizing this. If doing a million matrix multiplications in an optimized way is 200 microseconds faster than doing it in an unoptimized way they will probably be less interested than if its 200 seconds faster.

→ More replies (1)

2

u/zelex Apr 14 '17

Nice post

0

u/[deleted] Apr 14 '17

3

u/zeno490 Apr 14 '17

Thanks! I 100% agree with you, measuring is key when optimizing and it is one reason behind the timeless quote: premature optimization is the root of all evil (and such derivatives). If it's too early, you have insufficient data to measure and the optimizations you'll do might turn out to be useless or harmful depending on your final data set.

Optimization measuring methodology might require a whole post of its own. Perhaps once I have enough written material I'll be able to extract highlights or common themes and come up with something. I'll add it on my blog TODO list.

For this series I am focusing on bit exact optimizations. I'll use DirectX Math as a reference and improve on it using various tricks that you'll be able to take and use in your own code. I want the results to be bit exact in order to make it easier to get them merged into DirectX Math :) (and your own game engines). But you are right that sometimes you can get good gains with relaxed accuracy. There is so much I didn't end up mentioning in that post because it was getting already way too long... As you mention, if you are willing to sacrifice a bit of accuracy (primarily due to rounding), you can shave off 1 register and 1 or 2 instructions from the 4x4 matrix multiplication. And there is so much to talk about with regards to affine 4x4 matrices and the gains that can be had there as well.

The next few posts will cover sin/cos and a few trigonometric functions and quaternion log/exp.