Commit 4c2b6af1 authored by Alexandre Julliard's avatar Alexandre Julliard

include: Define a few more intrinsic functions.

parent a7f0e61e
......@@ -6262,60 +6262,12 @@ typedef enum _PROCESS_MITIGATION_POLICY
MaxProcessMitigationPolicy
} PROCESS_MITIGATION_POLICY, *PPROCESS_MITIGATION_POLICY;
#ifdef _MSC_VER
BOOLEAN _BitScanForward(unsigned long*,unsigned long);
BOOLEAN _BitScanReverse(unsigned long*,unsigned long);
#pragma intrinsic(_BitScanForward)
#pragma intrinsic(_BitScanReverse)
static inline BOOLEAN BitScanForward(DWORD *index, DWORD mask)
{
return _BitScanForward((unsigned long*)index, mask);
}
static inline BOOLEAN BitScanReverse(DWORD *index, DWORD mask)
{
return _BitScanReverse((unsigned long*)index, mask);
}
#elif defined(__GNUC__) && ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)))
static inline BOOLEAN BitScanForward(DWORD *index, DWORD mask)
{
*index = __builtin_ctz(mask);
return mask != 0;
}
static inline BOOLEAN BitScanReverse(DWORD *index, DWORD mask)
{
*index = 31 - __builtin_clz(mask);
return mask != 0;
}
#else
static inline BOOLEAN BitScanForward(DWORD *index, DWORD mask)
{
unsigned int r = 0;
while (r < 31 && !(mask & (1 << r))) r++;
*index = r;
return mask != 0;
}
static inline BOOLEAN BitScanReverse(DWORD *index, DWORD mask)
{
unsigned int r = 31;
while (r > 0 && !(mask & (1 << r))) r--;
*index = r;
return mask != 0;
}
#endif
/* Interlocked functions */
/* Intrinsic functions */
#define BitScanForward _BitScanForward
#define BitScanReverse _BitScanReverse
#define InterlockedAdd _InlineInterlockedAdd
#define InterlockedAnd _InterlockedAnd
#define InterlockedCompareExchange _InterlockedCompareExchange
#define InterlockedCompareExchange64 _InterlockedCompareExchange64
......@@ -6328,9 +6280,12 @@ static inline BOOLEAN BitScanReverse(DWORD *index, DWORD mask)
#define InterlockedIncrement _InterlockedIncrement
#define InterlockedIncrement16 _InterlockedIncrement16
#define InterlockedOr _InterlockedOr
#define InterlockedXor _InterlockedXor
#ifdef _MSC_VER
#pragma intrinsic(_BitScanForward)
#pragma intrinsic(_BitScanReverse)
#pragma intrinsic(_InterlockedAnd)
#pragma intrinsic(_InterlockedCompareExchange)
#pragma intrinsic(_InterlockedCompareExchange64)
......@@ -6341,7 +6296,10 @@ static inline BOOLEAN BitScanReverse(DWORD *index, DWORD mask)
#pragma intrinsic(_InterlockedDecrement)
#pragma intrinsic(_InterlockedDecrement16)
#pragma intrinsic(_InterlockedOr)
#pragma intrinsic(_InterlockedXor)
BOOLEAN _BitScanForward(unsigned long*,unsigned long);
BOOLEAN _BitScanReverse(unsigned long*,unsigned long);
long _InterlockedAnd(long volatile *,long);
long _InterlockedCompareExchange(long volatile*,long,long);
long long _InterlockedCompareExchange64(long long volatile*,long long,long long);
......@@ -6352,6 +6310,12 @@ long _InterlockedExchangeAdd(long volatile*,long);
long _InterlockedIncrement(long volatile*);
short _InterlockedIncrement16(short volatile*);
long _InterlockedOr(long volatile *,long);
long _InterlockedXor(long volatile *,long);
static FORCEINLINE long InterlockedAdd( long volatile *dest, long val )
{
return InterlockedExchangeAdd( dest, val ) + val;
}
#if !defined(__i386__) || _MSC_VER >= 1600
......@@ -6412,6 +6376,23 @@ static FORCEINLINE void MemoryBarrier(void)
#elif defined(__GNUC__)
static FORCEINLINE BOOLEAN WINAPI BitScanForward(DWORD *index, DWORD mask)
{
*index = __builtin_ctz( mask );
return mask != 0;
}
static FORCEINLINE BOOLEAN WINAPI BitScanReverse(DWORD *index, DWORD mask)
{
*index = 31 - __builtin_clz( mask );
return mask != 0;
}
static FORCEINLINE LONG WINAPI InterlockedAdd( LONG volatile *dest, LONG val )
{
return __sync_add_and_fetch( dest, val );
}
static FORCEINLINE LONG WINAPI InterlockedAnd( LONG volatile *dest, LONG val )
{
return __sync_fetch_and_and( dest, val );
......@@ -6491,6 +6472,11 @@ static FORCEINLINE LONG WINAPI InterlockedOr( LONG volatile *dest, LONG val )
return __sync_fetch_and_or( dest, val );
}
static FORCEINLINE LONG WINAPI InterlockedXor( LONG volatile *dest, LONG val )
{
return __sync_fetch_and_xor( dest, val );
}
static FORCEINLINE void MemoryBarrier(void)
{
__sync_synchronize();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment