This question came up in a Power8 in-core crypto patch. The patch provides AES using Power8 built-ins. When loading a VSX register we need to perform a 128-bit endian reversal when running on a little-endian machine to ensure the VSX register loads the proper value.
At compile time we can check macros like __BYTE_ORDER__
. However, I believe we are supposed to check the machine status register at runtime. If msr.le=1
, then we perform the endian swap. Also see the AltiVec Programming Environment Manual, Section 3.1.4, p. 3-5.
How do we check the machine status register at runtime using built-ins?