| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| #if defined(__GNUC__) || defined(__INTEL_COMPILER) |
| #if defined(__i386__) || defined(__i386) |
| #define pg_memory_barrier_impl() \ |
| __asm__ __volatile__ ("lock; addl $0,0(%%esp)" : : : "memory", "cc") |
| #elif defined(__x86_64__) |
| #define pg_memory_barrier_impl() \ |
| __asm__ __volatile__ ("lock; addl $0,0(%%rsp)" : : : "memory", "cc") |
| #endif |
| #endif |
|
|
| #define pg_read_barrier_impl() pg_compiler_barrier_impl() |
| #define pg_write_barrier_impl() pg_compiler_barrier_impl() |
|
|
| |
| |
| |
| |
| |
| #if defined(HAVE_ATOMICS) |
|
|
| #if defined(__GNUC__) || defined(__INTEL_COMPILER) |
|
|
| #define PG_HAVE_ATOMIC_FLAG_SUPPORT |
| typedef struct pg_atomic_flag |
| { |
| volatile char value; |
| } pg_atomic_flag; |
|
|
| #define PG_HAVE_ATOMIC_U32_SUPPORT |
| typedef struct pg_atomic_uint32 |
| { |
| volatile uint32 value; |
| } pg_atomic_uint32; |
|
|
| |
| |
| |
| |
| #ifdef __x86_64__ |
| #define PG_HAVE_ATOMIC_U64_SUPPORT |
| typedef struct pg_atomic_uint64 |
| { |
| |
| volatile uint64 value; |
| } pg_atomic_uint64; |
| #endif |
|
|
| #endif |
|
|
| #endif |
|
|
| #if !defined(PG_HAVE_SPIN_DELAY) |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| #if defined(__GNUC__) || defined(__INTEL_COMPILER) |
| #define PG_HAVE_SPIN_DELAY |
| static __inline__ void |
| pg_spin_delay_impl(void) |
| { |
| __asm__ __volatile__(" rep; nop \n"); |
| } |
| #elif defined(_MSC_VER) && defined(__x86_64__) |
| #define PG_HAVE_SPIN_DELAY |
| static __forceinline void |
| pg_spin_delay_impl(void) |
| { |
| _mm_pause(); |
| } |
| #elif defined(_MSC_VER) |
| #define PG_HAVE_SPIN_DELAY |
| static __forceinline void |
| pg_spin_delay_impl(void) |
| { |
| |
| __asm rep nop; |
| } |
| #endif |
| #endif |
|
|
|
|
| #if defined(HAVE_ATOMICS) |
|
|
| #if defined(__GNUC__) || defined(__INTEL_COMPILER) |
|
|
| #define PG_HAVE_ATOMIC_TEST_SET_FLAG |
| static inline bool |
| pg_atomic_test_set_flag_impl(volatile pg_atomic_flag *ptr) |
| { |
| char _res = 1; |
|
|
| __asm__ __volatile__( |
| " lock \n" |
| " xchgb %0,%1 \n" |
| : "+q"(_res), "+m"(ptr->value) |
| : |
| : "memory"); |
| return _res == 0; |
| } |
|
|
| #define PG_HAVE_ATOMIC_CLEAR_FLAG |
| static inline void |
| pg_atomic_clear_flag_impl(volatile pg_atomic_flag *ptr) |
| { |
| |
| |
| |
| |
| __asm__ __volatile__("" ::: "memory"); |
| ptr->value = 0; |
| } |
|
|
| #define PG_HAVE_ATOMIC_COMPARE_EXCHANGE_U32 |
| static inline bool |
| pg_atomic_compare_exchange_u32_impl(volatile pg_atomic_uint32 *ptr, |
| uint32 *expected, uint32 newval) |
| { |
| char ret; |
|
|
| |
| |
| |
| |
| __asm__ __volatile__( |
| " lock \n" |
| " cmpxchgl %4,%5 \n" |
| " setz %2 \n" |
| : "=a" (*expected), "=m"(ptr->value), "=q" (ret) |
| : "a" (*expected), "r" (newval), "m"(ptr->value) |
| : "memory", "cc"); |
| return (bool) ret; |
| } |
|
|
| #define PG_HAVE_ATOMIC_FETCH_ADD_U32 |
| static inline uint32 |
| pg_atomic_fetch_add_u32_impl(volatile pg_atomic_uint32 *ptr, int32 add_) |
| { |
| uint32 res; |
| __asm__ __volatile__( |
| " lock \n" |
| " xaddl %0,%1 \n" |
| : "=q"(res), "=m"(ptr->value) |
| : "0" (add_), "m"(ptr->value) |
| : "memory", "cc"); |
| return res; |
| } |
|
|
| #ifdef __x86_64__ |
|
|
| #define PG_HAVE_ATOMIC_COMPARE_EXCHANGE_U64 |
| static inline bool |
| pg_atomic_compare_exchange_u64_impl(volatile pg_atomic_uint64 *ptr, |
| uint64 *expected, uint64 newval) |
| { |
| char ret; |
|
|
| |
| |
| |
| |
| __asm__ __volatile__( |
| " lock \n" |
| " cmpxchgq %4,%5 \n" |
| " setz %2 \n" |
| : "=a" (*expected), "=m"(ptr->value), "=q" (ret) |
| : "a" (*expected), "r" (newval), "m"(ptr->value) |
| : "memory", "cc"); |
| return (bool) ret; |
| } |
|
|
| #define PG_HAVE_ATOMIC_FETCH_ADD_U64 |
| static inline uint64 |
| pg_atomic_fetch_add_u64_impl(volatile pg_atomic_uint64 *ptr, int64 add_) |
| { |
| uint64 res; |
| __asm__ __volatile__( |
| " lock \n" |
| " xaddq %0,%1 \n" |
| : "=q"(res), "=m"(ptr->value) |
| : "0" (add_), "m"(ptr->value) |
| : "memory", "cc"); |
| return res; |
| } |
|
|
| #endif |
|
|
| #endif |
|
|
| |
| |
| |
| |
| #if defined(__i568__) || defined(__i668__) || \ |
| (defined(_M_IX86) && _M_IX86 >= 500) || \ |
| defined(__x86_64__) || defined(__x86_64) || defined(_M_X64) |
| #define PG_HAVE_8BYTE_SINGLE_COPY_ATOMICITY |
| #endif |
|
|
| #endif |
|
|