Original Post
I’m having a lot of second thoughts about using inline ASM. I have this code that enumerates support for SSE. The code checks to see if the OS and CPU supports SSE and what not. I have to write different code for each type of SSE. What a load of work. Is it work it. Do I really get that much speed out of using these extensions? I need to make the engine fast as possible. Also, the engine uses it’s own types, not Direct3Ds. Because a lot of the sprites and meshes work with the engines types. The only conversion they need is to be uses with the VB. I can’t decide if I want to use ASM with a lot of the math. I need most the math to be lightning fast because it will be uses extensively by the engine. Most of the math is done with 3D or 4D vectors types. So what do you guys think?
// ----------------------------------------------------------------------------
// Name : EnumCPUInfo( )
// Desc : Enumerates the CPU for special MMX / 3DNow! technologies
// ----------------------------------------------------------------------------
BOOL EnumCPUInfo( CPUINFO Info )
{
CHAR* pStr = Info.szVendor;
int n = 1;
int* pn = &n;
memset( &Info, 0, sizeof( Info ) );
__try
{
_asm xorps xmm0, xmm0
}
__except ( EXECEPTION_EXECUTE_HANDLER )
{
if ( _exception_code( ) == STATUS_ILLEGAL_INSTRUCTION )
{
return ( FALSE );
}
}
__try
{
__asm
{
mov eax, 0
CPUID
mov esi, pStr
mov [esi], ebx
mov [esi+4], edx
mov [esi+8], ecx
mov eax, 1
CPUID
test edx, 04000000h
jz __NOSSE2
mov [Info.szVendor], 1
__NOSSE2: test edx, 02000000h
jz __NOSSE
mov [Info.bSSE], 1
__NOSSE: test edx, 00800000h
jz __EXIT1
mov [Info.bMMX], 1
__EXIT1:
}
}
__except( EXCEPTION_EXECUTE_HANDLER )
{
if ( _exception_code( ) == STATUS_ILLEGAL_INSTRUCTION )
{
return Info;
}
return Info;
}
__asm
{
mov eax, 80000000h
CPUID
cmp eax, 80000000h
jz __EXIT2
mov [Info.bEXT], 1
__EXIT2:
}
if ( ( strncmp( Info.szVendor, "GenuineIntel", 12 ) == 0 ) && Info.bEXT )
{
__asm
{
mov eax, 1
CPUID
mov esi, pn
mov [esi], ebx
}
int m = 0;
memcpy( &m, pn, sizeof( char ) );
n = m;
}
else if ( ( strncmp( Info.szVendor, "AuthenticAMD", 12 ) == 0 ) && Info.bEXT )
{
__asm
{
mov eax, 1
CPUID
mov esi, pn
mov [esi], eax
mov eax, 0x80000001
CPUID
test edx, 0x40000000
jz __AMD1
mov [Info.b3DNow], 1
__AMD1: test edx, 0x00400000
jz __AMD2
mov [Info.bMMXEX ], 1
__AMD2:
}
}
else
{
if ( Info.bEXT )
;
else
;
}
Info.szVendor[ 13 ] = '\0';
return Info;
}