Advertisement

Returning XMMATRIX & XMVECTOR from a function

Started by November 19, 2017 05:53 PM
3 comments, last by MJP 7 years, 2 months ago

As far as I know, the size of XMMATRIX must be 64 bytes, which is way too big to be returned by a function. However, DirectXMath functions do return this struct. I suppose this has something to do with the SIMD optimization. Should I return this huge struct from my own functions or should I pass it by a reference or pointer?

This question will look silly to you if you know how SIMD works, but I don't.

The DirectXMath library is inline, so no copy will happen on return, the function is just expanded in place.

Advertisement

Thanks.

DirectXMath uses the vectorcall calling convention that's available in VC++, which allows returning values in XMM0 through XMM3. This is enough to fit a 4x4 matrix, so even if the functions aren't inlined the return value doesn't have to go on the stack.

This topic is closed to new replies.

Advertisement