SIMD – Matrix3x3 Transpose

Just recently I finished implementing my own personal SIMD math library using SSE intrinsics. There are two major resources for learning how to write effective SIMD code:

While inspecting the DirectXMath source I came across the implementation of transposing a 4×4 matrix:

Lately I have been working only with 3×3 matrices and vectors. This is nice since often times 4×4 matrices store mostly useless data in the bottom row. In effect some kind of 3×4 matrix can be stored in memory to represent an affine transformation:

Depending on what the code is used for the rotation matrix can have scaling built in, or not. Often times only uniform scaling is desired so that chains of transformations can easily be reversed an decomposed freely.

Since I’m only dealing with 3×3 matrices I decided to cut down on the number of shuffles as best I could, and ended up with this implementation:

Only 5 shuffles are used here instead of the 8 from DirectXMath for the 4×4 transpose. I did not really take care of handling the w component of any of the __m128’s during the whole process. In general I just left the shuffles for w as 0.

I really don’t think another shuffle can be removed in the 3×3 case, so any further optimizations would probably be outside my realm of knowledge. If anyone knows of anything else interesting as far as transposition goes feel free to comment below.

Note: On Windows if anyone is wondering why my function does not incur a compiler error complaining about parameter alignment, be sure to lookup __vectorcall for Visual Studio 2013.

TwitterRedditFacebookShare

2 thoughts on “SIMD – Matrix3x3 Transpose

  1. Troy

    Greetings!

    So I first found your website starting on Teamliquid.net’s website. I read your post titled; “I want to learn programming, but I know nothing”, and was curious on how I should move forward from there?

    I’m very interested in learning more in programming and eventually moving on to game design/programming.

    I know I have your website as a great resource tool, but I’m still unclear on where to start.

    Thanks.

    Reply
    1. Randy Gaul Post author

      I would recommend the book C Programming: A Modern Approach, 2nd Ed. by K.N. King. If you go through that book you’ll become a fairly competent programmer. If you like you can email me directly (email on my resume on this site) to ask specific questions :)

      Reply

Leave a Reply

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