x86emitter: use memcpy to avoid aliasing issue

Code is only called once anyway.
This commit is contained in:
Gregory Hainaut 2016-07-27 23:27:21 +02:00
parent 90707f8d4e
commit e8e66ec4b5
2 changed files with 12 additions and 11 deletions

View File

@ -19,9 +19,9 @@
enum x86VendorType
{
x86Vendor_Intel=0,
x86Vendor_AMD,
x86Vendor_Unknown,
x86Vendor_Intel = 0,
x86Vendor_AMD = 1,
x86Vendor_Unknown = 2
};
// --------------------------------------------------------------------------------------

View File

@ -22,9 +22,6 @@ using namespace x86Emitter;
__aligned16 x86capabilities x86caps;
// Recompiled code buffer for SSE and MXCSR feature testing.
static __pagealigned u8 targetFXSAVE[512];
x86capabilities::x86capabilities() :
isIdentified(false),
VendorID(x86Vendor_Unknown),
@ -65,10 +62,13 @@ void x86capabilities::SIMD_EstablishMXCSRmask()
MXCSR_Mask.bitmask = 0xFFFF; // SSE2 features added
}
__aligned16 u8 targetFXSAVE[512];
// Work for recent enough GCC/CLANG/MSVC 2012
_fxsave(&targetFXSAVE);
u32 result = (u32&)targetFXSAVE[28]; // bytes 28->32 are the MXCSR_Mask.
u32 result;
memcpy(&result, &targetFXSAVE[28], 4); // bytes 28->32 are the MXCSR_Mask.
if( result != 0 )
MXCSR_Mask.bitmask = result;
}
@ -194,20 +194,21 @@ void x86capabilities::Identify()
cpuid( regs, 0 );
cmds = regs[ 0 ];
((u32*)VendorName)[ 0 ] = regs[ 1 ];
((u32*)VendorName)[ 1 ] = regs[ 3 ];
((u32*)VendorName)[ 2 ] = regs[ 2 ];
memcpy(&VendorName[0], &regs[1], 4);
memcpy(&VendorName[4], &regs[3], 4);
memcpy(&VendorName[8], &regs[2], 4);
// Determine Vendor Specifics!
// It's really not recommended that we base much (if anything) on CPU vendor names,
// however it's currently necessary in order to gain a (pseudo)reliable count of cores
// and threads used by the CPU (AMD and Intel can't agree on how to make this info available).
int& vid = (int&)VendorID;
int vid;
for( vid=0; vid<x86Vendor_Unknown; ++vid )
{
if( memcmp( VendorName, tbl_x86vendors[vid], 12 ) == 0 ) break;
}
VendorID = static_cast<x86VendorType>(vid);
if ( cmds >= 0x00000001 )
{