Attribute macro changed
__forceinline -> force_inline __noinline -> never_inline printf_alike(x,y) added
This commit is contained in:
+53
-43
@@ -2,22 +2,34 @@
|
||||
|
||||
#include <emmintrin.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#if defined(_MSC_VER)
|
||||
#define thread_local __declspec(thread)
|
||||
#elif __APPLE__
|
||||
#define thread_local __thread
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#define __noinline __declspec(noinline)
|
||||
#if defined(_MSC_VER)
|
||||
#define never_inline __declspec(noinline)
|
||||
#else
|
||||
#define __noinline __attribute__((noinline))
|
||||
#define never_inline __attribute__((noinline))
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#define __safebuffers __declspec(safebuffers)
|
||||
#if defined(_MSC_VER)
|
||||
#define safe_buffers __declspec(safebuffers)
|
||||
#else
|
||||
#define __safebuffers
|
||||
#define safe_buffers
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#define printf_alike(x, y)
|
||||
#else
|
||||
#define printf_alike(x, y) __attribute__((format(printf, x, y)))
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#define force_inline __forceinline
|
||||
#else
|
||||
#define force_inline __attribute__((always_inline))
|
||||
#endif
|
||||
|
||||
template<size_t size>
|
||||
@@ -46,12 +58,10 @@ void strcpy_trunc(char(&dst)[size], const char(&src)[rsize])
|
||||
#endif
|
||||
|
||||
#define _fpclass(x) std::fpclassify(x)
|
||||
#define __forceinline __attribute__((always_inline))
|
||||
#define _byteswap_ushort(x) __builtin_bswap16(x)
|
||||
#define _byteswap_ulong(x) __builtin_bswap32(x)
|
||||
#define _byteswap_uint64(x) __builtin_bswap64(x)
|
||||
#define INFINITE 0xFFFFFFFF
|
||||
#define _CRT_ALIGN(x) __attribute__((aligned(x)))
|
||||
|
||||
inline uint64_t __umulh(uint64_t a, uint64_t b)
|
||||
{
|
||||
@@ -124,181 +134,181 @@ template<typename T, typename T2> static inline typename std::enable_if<std::is_
|
||||
|
||||
// atomic compare and swap functions
|
||||
|
||||
static __forceinline uint8_t sync_val_compare_and_swap(volatile uint8_t* dest, uint8_t comp, uint8_t exch)
|
||||
static force_inline uint8_t sync_val_compare_and_swap(volatile uint8_t* dest, uint8_t comp, uint8_t exch)
|
||||
{
|
||||
return _InterlockedCompareExchange8((volatile char*)dest, exch, comp);
|
||||
}
|
||||
|
||||
static __forceinline uint16_t sync_val_compare_and_swap(volatile uint16_t* dest, uint16_t comp, uint16_t exch)
|
||||
static force_inline uint16_t sync_val_compare_and_swap(volatile uint16_t* dest, uint16_t comp, uint16_t exch)
|
||||
{
|
||||
return _InterlockedCompareExchange16((volatile short*)dest, exch, comp);
|
||||
}
|
||||
|
||||
static __forceinline uint32_t sync_val_compare_and_swap(volatile uint32_t* dest, uint32_t comp, uint32_t exch)
|
||||
static force_inline uint32_t sync_val_compare_and_swap(volatile uint32_t* dest, uint32_t comp, uint32_t exch)
|
||||
{
|
||||
return _InterlockedCompareExchange((volatile long*)dest, exch, comp);
|
||||
}
|
||||
|
||||
static __forceinline uint64_t sync_val_compare_and_swap(volatile uint64_t* dest, uint64_t comp, uint64_t exch)
|
||||
static force_inline uint64_t sync_val_compare_and_swap(volatile uint64_t* dest, uint64_t comp, uint64_t exch)
|
||||
{
|
||||
return _InterlockedCompareExchange64((volatile long long*)dest, exch, comp);
|
||||
}
|
||||
|
||||
static __forceinline bool sync_bool_compare_and_swap(volatile uint8_t* dest, uint8_t comp, uint8_t exch)
|
||||
static force_inline bool sync_bool_compare_and_swap(volatile uint8_t* dest, uint8_t comp, uint8_t exch)
|
||||
{
|
||||
return (uint8_t)_InterlockedCompareExchange8((volatile char*)dest, exch, comp) == comp;
|
||||
}
|
||||
|
||||
static __forceinline bool sync_bool_compare_and_swap(volatile uint16_t* dest, uint16_t comp, uint16_t exch)
|
||||
static force_inline bool sync_bool_compare_and_swap(volatile uint16_t* dest, uint16_t comp, uint16_t exch)
|
||||
{
|
||||
return (uint16_t)_InterlockedCompareExchange16((volatile short*)dest, exch, comp) == comp;
|
||||
}
|
||||
|
||||
static __forceinline bool sync_bool_compare_and_swap(volatile uint32_t* dest, uint32_t comp, uint32_t exch)
|
||||
static force_inline bool sync_bool_compare_and_swap(volatile uint32_t* dest, uint32_t comp, uint32_t exch)
|
||||
{
|
||||
return (uint32_t)_InterlockedCompareExchange((volatile long*)dest, exch, comp) == comp;
|
||||
}
|
||||
|
||||
static __forceinline bool sync_bool_compare_and_swap(volatile uint64_t* dest, uint64_t comp, uint64_t exch)
|
||||
static force_inline bool sync_bool_compare_and_swap(volatile uint64_t* dest, uint64_t comp, uint64_t exch)
|
||||
{
|
||||
return (uint64_t)_InterlockedCompareExchange64((volatile long long*)dest, exch, comp) == comp;
|
||||
}
|
||||
|
||||
// atomic exchange functions
|
||||
|
||||
static __forceinline uint8_t sync_lock_test_and_set(volatile uint8_t* dest, uint8_t value)
|
||||
static force_inline uint8_t sync_lock_test_and_set(volatile uint8_t* dest, uint8_t value)
|
||||
{
|
||||
return _InterlockedExchange8((volatile char*)dest, value);
|
||||
}
|
||||
|
||||
static __forceinline uint16_t sync_lock_test_and_set(volatile uint16_t* dest, uint16_t value)
|
||||
static force_inline uint16_t sync_lock_test_and_set(volatile uint16_t* dest, uint16_t value)
|
||||
{
|
||||
return _InterlockedExchange16((volatile short*)dest, value);
|
||||
}
|
||||
|
||||
static __forceinline uint32_t sync_lock_test_and_set(volatile uint32_t* dest, uint32_t value)
|
||||
static force_inline uint32_t sync_lock_test_and_set(volatile uint32_t* dest, uint32_t value)
|
||||
{
|
||||
return _InterlockedExchange((volatile long*)dest, value);
|
||||
}
|
||||
|
||||
static __forceinline uint64_t sync_lock_test_and_set(volatile uint64_t* dest, uint64_t value)
|
||||
static force_inline uint64_t sync_lock_test_and_set(volatile uint64_t* dest, uint64_t value)
|
||||
{
|
||||
return _InterlockedExchange64((volatile long long*)dest, value);
|
||||
}
|
||||
|
||||
// atomic add functions
|
||||
|
||||
static __forceinline uint8_t sync_fetch_and_add(volatile uint8_t* dest, uint8_t value)
|
||||
static force_inline uint8_t sync_fetch_and_add(volatile uint8_t* dest, uint8_t value)
|
||||
{
|
||||
return _InterlockedExchangeAdd8((volatile char*)dest, value);
|
||||
}
|
||||
|
||||
static __forceinline uint16_t sync_fetch_and_add(volatile uint16_t* dest, uint16_t value)
|
||||
static force_inline uint16_t sync_fetch_and_add(volatile uint16_t* dest, uint16_t value)
|
||||
{
|
||||
return _InterlockedExchangeAdd16((volatile short*)dest, value);
|
||||
}
|
||||
|
||||
static __forceinline uint32_t sync_fetch_and_add(volatile uint32_t* dest, uint32_t value)
|
||||
static force_inline uint32_t sync_fetch_and_add(volatile uint32_t* dest, uint32_t value)
|
||||
{
|
||||
return _InterlockedExchangeAdd((volatile long*)dest, value);
|
||||
}
|
||||
|
||||
static __forceinline uint64_t sync_fetch_and_add(volatile uint64_t* dest, uint64_t value)
|
||||
static force_inline uint64_t sync_fetch_and_add(volatile uint64_t* dest, uint64_t value)
|
||||
{
|
||||
return _InterlockedExchangeAdd64((volatile long long*)dest, value);
|
||||
}
|
||||
|
||||
// atomic sub functions
|
||||
|
||||
static __forceinline uint8_t sync_fetch_and_sub(volatile uint8_t* dest, uint8_t value)
|
||||
static force_inline uint8_t sync_fetch_and_sub(volatile uint8_t* dest, uint8_t value)
|
||||
{
|
||||
return _InterlockedExchangeAdd8((volatile char*)dest, -(char)value);
|
||||
}
|
||||
|
||||
static __forceinline uint16_t sync_fetch_and_sub(volatile uint16_t* dest, uint16_t value)
|
||||
static force_inline uint16_t sync_fetch_and_sub(volatile uint16_t* dest, uint16_t value)
|
||||
{
|
||||
return _InterlockedExchangeAdd16((volatile short*)dest, -(short)value);
|
||||
}
|
||||
|
||||
static __forceinline uint32_t sync_fetch_and_sub(volatile uint32_t* dest, uint32_t value)
|
||||
static force_inline uint32_t sync_fetch_and_sub(volatile uint32_t* dest, uint32_t value)
|
||||
{
|
||||
return _InterlockedExchangeAdd((volatile long*)dest, -(long)value);
|
||||
}
|
||||
|
||||
static __forceinline uint64_t sync_fetch_and_sub(volatile uint64_t* dest, uint64_t value)
|
||||
static force_inline uint64_t sync_fetch_and_sub(volatile uint64_t* dest, uint64_t value)
|
||||
{
|
||||
return _InterlockedExchangeAdd64((volatile long long*)dest, -(long long)value);
|
||||
}
|
||||
|
||||
// atomic bitwise or functions
|
||||
|
||||
static __forceinline uint8_t sync_fetch_and_or(volatile uint8_t* dest, uint8_t value)
|
||||
static force_inline uint8_t sync_fetch_and_or(volatile uint8_t* dest, uint8_t value)
|
||||
{
|
||||
return _InterlockedOr8((volatile char*)dest, value);
|
||||
}
|
||||
|
||||
static __forceinline uint16_t sync_fetch_and_or(volatile uint16_t* dest, uint16_t value)
|
||||
static force_inline uint16_t sync_fetch_and_or(volatile uint16_t* dest, uint16_t value)
|
||||
{
|
||||
return _InterlockedOr16((volatile short*)dest, value);
|
||||
}
|
||||
|
||||
static __forceinline uint32_t sync_fetch_and_or(volatile uint32_t* dest, uint32_t value)
|
||||
static force_inline uint32_t sync_fetch_and_or(volatile uint32_t* dest, uint32_t value)
|
||||
{
|
||||
return _InterlockedOr((volatile long*)dest, value);
|
||||
}
|
||||
|
||||
static __forceinline uint64_t sync_fetch_and_or(volatile uint64_t* dest, uint64_t value)
|
||||
static force_inline uint64_t sync_fetch_and_or(volatile uint64_t* dest, uint64_t value)
|
||||
{
|
||||
return _InterlockedOr64((volatile long long*)dest, value);
|
||||
}
|
||||
|
||||
// atomic bitwise and functions
|
||||
|
||||
static __forceinline uint8_t sync_fetch_and_and(volatile uint8_t* dest, uint8_t value)
|
||||
static force_inline uint8_t sync_fetch_and_and(volatile uint8_t* dest, uint8_t value)
|
||||
{
|
||||
return _InterlockedAnd8((volatile char*)dest, value);
|
||||
}
|
||||
|
||||
static __forceinline uint16_t sync_fetch_and_and(volatile uint16_t* dest, uint16_t value)
|
||||
static force_inline uint16_t sync_fetch_and_and(volatile uint16_t* dest, uint16_t value)
|
||||
{
|
||||
return _InterlockedAnd16((volatile short*)dest, value);
|
||||
}
|
||||
|
||||
static __forceinline uint32_t sync_fetch_and_and(volatile uint32_t* dest, uint32_t value)
|
||||
static force_inline uint32_t sync_fetch_and_and(volatile uint32_t* dest, uint32_t value)
|
||||
{
|
||||
return _InterlockedAnd((volatile long*)dest, value);
|
||||
}
|
||||
|
||||
static __forceinline uint64_t sync_fetch_and_and(volatile uint64_t* dest, uint64_t value)
|
||||
static force_inline uint64_t sync_fetch_and_and(volatile uint64_t* dest, uint64_t value)
|
||||
{
|
||||
return _InterlockedAnd64((volatile long long*)dest, value);
|
||||
}
|
||||
|
||||
// atomic bitwise xor functions
|
||||
|
||||
static __forceinline uint8_t sync_fetch_and_xor(volatile uint8_t* dest, uint8_t value)
|
||||
static force_inline uint8_t sync_fetch_and_xor(volatile uint8_t* dest, uint8_t value)
|
||||
{
|
||||
return _InterlockedXor8((volatile char*)dest, value);
|
||||
}
|
||||
|
||||
static __forceinline uint16_t sync_fetch_and_xor(volatile uint16_t* dest, uint16_t value)
|
||||
static force_inline uint16_t sync_fetch_and_xor(volatile uint16_t* dest, uint16_t value)
|
||||
{
|
||||
return _InterlockedXor16((volatile short*)dest, value);
|
||||
}
|
||||
|
||||
static __forceinline uint32_t sync_fetch_and_xor(volatile uint32_t* dest, uint32_t value)
|
||||
static force_inline uint32_t sync_fetch_and_xor(volatile uint32_t* dest, uint32_t value)
|
||||
{
|
||||
return _InterlockedXor((volatile long*)dest, value);
|
||||
}
|
||||
|
||||
static __forceinline uint64_t sync_fetch_and_xor(volatile uint64_t* dest, uint64_t value)
|
||||
static force_inline uint64_t sync_fetch_and_xor(volatile uint64_t* dest, uint64_t value)
|
||||
{
|
||||
return _InterlockedXor64((volatile long long*)dest, value);
|
||||
}
|
||||
|
||||
#endif /* _MSC_VER */
|
||||
|
||||
static __forceinline uint32_t cntlz32(uint32_t arg)
|
||||
static force_inline uint32_t cntlz32(uint32_t arg)
|
||||
{
|
||||
#if defined(_MSC_VER)
|
||||
unsigned long res;
|
||||
@@ -322,7 +332,7 @@ static __forceinline uint32_t cntlz32(uint32_t arg)
|
||||
#endif
|
||||
}
|
||||
|
||||
static __forceinline uint64_t cntlz64(uint64_t arg)
|
||||
static force_inline uint64_t cntlz64(uint64_t arg)
|
||||
{
|
||||
#if defined(_MSC_VER)
|
||||
unsigned long res;
|
||||
|
||||
Reference in New Issue
Block a user