November 2nd, 2017

What are the dire consequences of accessing the fields of __m128i directly?

The MSDN documentation for __m128i says

You should not access the __m128i fields directly.

What are the dire consequences of accessing the fields directly?

The first consequence is portability: The contents of the __m128i structure are not standardized. It is a 16-byte value stored on a 16-byte boundary, but that’s all that is required. If you go digging around inside it, you are tying yourself to a particular implementation’s definition of __m128i.

The other consequence is performance: If a __m128i value is in an XMM register, and you try to access a field from it, the compiler will store the XMM register to memory, so that it can then extract the appropriate field. If you want to pull out specific fields, you are better-served using an intrinsic if an applicable one is available.

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.