97 lines
1.6 KiB
C
97 lines
1.6 KiB
C
// 몇가지 시스템 콜의 성능이 마음에 안들어서 디스어셈블 해서 원하는것만 뽑아냄.
|
|
//
|
|
// by Testors 2004/03/12
|
|
|
|
#pragma once
|
|
|
|
inline void break_point()
|
|
{
|
|
__asm { int 3 }
|
|
}
|
|
|
|
inline int is_debugger_present()
|
|
{
|
|
__asm {
|
|
mov eax,dword ptr fs:[00000018h]
|
|
mov eax,dword ptr [eax+30h]
|
|
movzx eax,byte ptr [eax+2]
|
|
}
|
|
}
|
|
|
|
inline int interlocked_increment( volatile int * target, int count = 1 )
|
|
{
|
|
__asm {
|
|
mov ebx, target
|
|
mov eax, count
|
|
lock xadd dword ptr [ebx],eax
|
|
}
|
|
}
|
|
|
|
inline int interlocked_decrement( volatile int * target, int count = 1 )
|
|
{
|
|
__asm {
|
|
mov ebx, target
|
|
mov eax, count
|
|
neg eax
|
|
lock xadd dword ptr [ebx],eax
|
|
}
|
|
}
|
|
|
|
inline int interlocked_exchange( volatile int * target, int value )
|
|
{
|
|
__asm {
|
|
mov ebx, target
|
|
mov eax, value
|
|
lock xchg dword ptr [ebx],eax
|
|
}
|
|
}
|
|
|
|
inline unsigned __int64 getElapsedPicoSecond()
|
|
{
|
|
__asm
|
|
{
|
|
mov edx,dword ptr ds:7FFE000Ch
|
|
mov eax,dword ptr ds:7FFE0008h
|
|
}
|
|
}
|
|
|
|
|
|
inline unsigned int getElapsedMilliSecond()
|
|
{
|
|
return static_cast< unsigned int >( getElapsedPicoSecond()/(long)10000 );
|
|
}
|
|
|
|
inline unsigned __int64 getRDTSC()
|
|
{
|
|
__asm
|
|
{
|
|
rdtsc
|
|
}
|
|
}
|
|
|
|
|
|
|
|
inline void spinlock_init( volatile int * lock )
|
|
{
|
|
*lock = 0;
|
|
}
|
|
|
|
inline void spinlock_enter( volatile int * lock )
|
|
{
|
|
enter:
|
|
if( interlocked_exchange( lock, 1 ) == 0 ) return;
|
|
|
|
goto enter;
|
|
}
|
|
|
|
inline void spinlock_leave( volatile int * lock )
|
|
{
|
|
interlocked_exchange( lock, 0 );
|
|
}
|
|
|
|
inline bool spinlock_tryenter( volatile int * lock )
|
|
{
|
|
if( interlocked_exchange( lock, 1 ) == 0 ) return true;
|
|
|
|
return false;
|
|
}
|