Introducing SM_ASM_X86, a compiler-agnostic inline assembly macro
This commit is contained in:
@@ -364,7 +364,7 @@ long __stdcall CrashHandler::ExceptionHandler( EXCEPTION_POINTERS *pExc )
|
|||||||
int iSize = 1024*32;
|
int iSize = 1024*32;
|
||||||
char *pStack = (char *) VirtualAlloc( NULL, iSize, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE );
|
char *pStack = (char *) VirtualAlloc( NULL, iSize, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE );
|
||||||
pStack += iSize;
|
pStack += iSize;
|
||||||
_asm mov esp, pStack;
|
SM_ASM_X86(mov esp, pStack);
|
||||||
|
|
||||||
return MainExceptionHandler( pExc );
|
return MainExceptionHandler( pExc );
|
||||||
}
|
}
|
||||||
@@ -532,10 +532,10 @@ void CrashHandler::do_backtrace( const void **buf, size_t size,
|
|||||||
static void NORETURN debug_crash()
|
static void NORETURN debug_crash()
|
||||||
{
|
{
|
||||||
__try {
|
__try {
|
||||||
__asm xor ebx,ebx
|
SM_ASM_X86(xor ebx,ebx);
|
||||||
__asm mov eax,dword ptr [ebx]
|
SM_ASM_X86(mov eax,dword ptr [ebx]);
|
||||||
// __asm mov dword ptr [ebx],eax
|
// SM_ASM_X86(mov dword ptr [ebx],eax);
|
||||||
// __asm lock add dword ptr cs:[00000000h], 12345678h
|
// SM_ASM_X86(lock add dword ptr cs:[00000000h], 12345678h);
|
||||||
} __except( CrashHandler::ExceptionHandler((EXCEPTION_POINTERS*)_exception_info()) ) {
|
} __except( CrashHandler::ExceptionHandler((EXCEPTION_POINTERS*)_exception_info()) ) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -145,8 +145,8 @@ inline long int lrintf( float f )
|
|||||||
{
|
{
|
||||||
int retval;
|
int retval;
|
||||||
|
|
||||||
_asm fld f;
|
SM_ASM_X86(fld f);
|
||||||
_asm fistp retval;
|
SM_ASM_X86(fistp retval);
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
@@ -175,21 +175,19 @@ inline long int lrintf( float f )
|
|||||||
|
|
||||||
inline uint32_t ArchSwap32( uint32_t n )
|
inline uint32_t ArchSwap32( uint32_t n )
|
||||||
{
|
{
|
||||||
__asm
|
SM_ASM_X86(
|
||||||
{
|
|
||||||
mov eax, n
|
mov eax, n
|
||||||
xchg al, ah
|
xchg al, ah
|
||||||
ror eax, 16
|
ror eax, 16
|
||||||
xchg al, ah
|
xchg al, ah
|
||||||
mov n, eax
|
mov n, eax
|
||||||
};
|
);
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline uint32_t ArchSwap24( uint32_t n )
|
inline uint32_t ArchSwap24( uint32_t n )
|
||||||
{
|
{
|
||||||
__asm
|
SM_ASM_X86(
|
||||||
{
|
|
||||||
mov eax, n
|
mov eax, n
|
||||||
xchg al, ah
|
xchg al, ah
|
||||||
ror eax, 16
|
ror eax, 16
|
||||||
@@ -202,12 +200,11 @@ inline uint32_t ArchSwap24( uint32_t n )
|
|||||||
|
|
||||||
inline uint16_t ArchSwap16( uint16_t n )
|
inline uint16_t ArchSwap16( uint16_t n )
|
||||||
{
|
{
|
||||||
__asm
|
SM_ASM_X86(
|
||||||
{
|
|
||||||
mov ax, n
|
mov ax, n
|
||||||
xchg al, ah
|
xchg al, ah
|
||||||
mov n, ax
|
mov n, ax
|
||||||
};
|
);
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+1
-5
@@ -42,11 +42,7 @@ void NORETURN sm_crash( const char *reason )
|
|||||||
#if defined(_WINDOWS)
|
#if defined(_WINDOWS)
|
||||||
/* Do something after the above, so the call/return isn't optimized to a jmp; that
|
/* Do something after the above, so the call/return isn't optimized to a jmp; that
|
||||||
* way, this function will appear in backtrace stack traces. */
|
* way, this function will appear in backtrace stack traces. */
|
||||||
#if defined(_MSC_VER)
|
SM_ASM_X86(nop)
|
||||||
_asm nop;
|
|
||||||
#elif defined(__GNUC__) // MinGW or similar
|
|
||||||
asm("nop");
|
|
||||||
#endif
|
|
||||||
#else
|
#else
|
||||||
_exit( 1 );
|
_exit( 1 );
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+12
-1
@@ -240,9 +240,20 @@ float roundf( float f ) { if( f < 0.0f ) return truncf( f-0.5f ); return truncf(
|
|||||||
inline float strtof( const char *s, char **se ) { return (float) strtod( s, se ); }
|
inline float strtof( const char *s, char **se ) { return (float) strtod( s, se ); }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Compiler-agnostic macro for inline x86 assembly
|
||||||
|
#if defined(CPU_X86) || defined(CPU_X86_64)
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
// TESTME: is a single instruction legal for this syntax?
|
||||||
|
#define SM_ASM_X86(x) __asm { x }
|
||||||
|
#elif defined(__GNUC__)
|
||||||
|
#define SM_ASM_X86(x) __asm__("x")
|
||||||
|
#else
|
||||||
|
#error Inline assembly not implemented for your compiler.
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Don't include our own headers here, since they tend to change often. */
|
/* Don't include our own headers here, since they tend to change often. */
|
||||||
|
|
||||||
#endif
|
#endif // GLOBAL_H
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file
|
* @file
|
||||||
|
|||||||
Reference in New Issue
Block a user