Does _control87() also set the SSE MXCSR Control R

2019-07-05 19:57发布

问题:

The documentation for _control87 notes:

_control87 [...] affect[s] the control words for both the x87 and the SSE2, if present.

It seems that the SSE and SSE2 MXCSR control registers are identical, however, there is no mention of the SSE unit in the documentation. Does _control87 affect an SSE unit's MXCSR control register or is this only true for SSE2?

回答1:

I dug out an old Pentium III and checked with the following code:

#include <Windows.h>
#include <float.h>
#include <xmmintrin.h>
#include <iostream>
#include <iomanip>

int _tmain( int argc, _TCHAR* argv[] ) {
    using namespace std;

    // Unmask all SSE/SSE2 exceptions
    _MM_SET_EXCEPTION_MASK( 0 );
    // Get SSE/SSE2 exception mask
    DWORD dwExceptionMask = _MM_GET_EXCEPTION_MASK();
    cout << "Exception Mask: 0x" << hex << setw( 8 )
         << setfill( '0' ) << dwExceptionMask << endl;

    // Mask all FPU exceptions
    _control87( 0xFFFF, _MCW_EM );

    // Get SSE/SSE2 exception mask
    dwExceptionMask = _MM_GET_EXCEPTION_MASK();
    cout << "Exception Mask: 0x" << hex << setw( 8 )
         << setfill( '0' ) << dwExceptionMask << endl;

    return 0;
}

Result on Pentium III (SSE):

Exception Mask: 0x00000000
Exception Mask: 0x00000000

Result on Xeon (SSE, SSE2, SSE3, SSSE3):

Exception Mask: 0x00000000
Exception Mask: 0x00001e80

The results are surprising, but in line with the documentation. _control87 only has an effect on the MXCSR control register if at least an SSE2 unit is available.



回答2:

One MXCSR controls both sse and sse2 (and sse3 and ssse3 and sse4.1 and ...)