libport: Added an interlocked_cmpxchg128 function for 64-bit.

This commit is contained in:
Alexandre Julliard 2009-09-01 12:39:17 +02:00
parent a60f32739b
commit 192fcc5bb3
2 changed files with 37 additions and 6 deletions

View File

@ -412,6 +412,22 @@ extern inline int interlocked_xchg_add( int *dest, int incr )
return ret;
}
#ifdef __x86_64__
extern inline unsigned char interlocked_cmpxchg128( __int64 *dest, __int64 xchg_high,
__int64 xchg_low, __int64 *compare );
extern inline unsigned char interlocked_cmpxchg128( __int64 *dest, __int64 xchg_high,
__int64 xchg_low, __int64 *compare )
{
unsigned char ret;
__asm__ __volatile__( "lock cmpxchg16b %0; setz %b2"
: "=m" (dest[0]), "=m" (dest[1]), "=r" (ret),
"=a" (compare[0]), "=d" (compare[1])
: "m" (dest[0]), "m" (dest[1]), "3" (compare[0]), "4" (compare[1]),
"c" (xchg_high), "b" (xchg_low) );
return ret;
}
#endif
#else /* __GNUC__ */
extern int interlocked_cmpxchg( int *dest, int xchg, int compare );
@ -420,6 +436,10 @@ extern __int64 interlocked_cmpxchg64( __int64 *dest, __int64 xchg, __int64 compa
extern int interlocked_xchg( int *dest, int val );
extern void *interlocked_xchg_ptr( void **dest, void *val );
extern int interlocked_xchg_add( int *dest, int incr );
#ifdef _WIN64
extern unsigned char interlocked_cmpxchg128( __int64 *dest, __int64 xchg_high,
__int64 xchg_low, __int64 *compare );
#endif
#endif /* __GNUC__ */

View File

@ -139,8 +139,6 @@ __declspec(naked) int interlocked_xchg_add( int *dest, int incr )
#elif defined(__x86_64__)
#ifdef __GNUC__
__ASM_GLOBAL_FUNC(interlocked_cmpxchg,
"mov %edx, %eax\n\t"
"lock cmpxchgl %esi,(%rdi)\n\t"
@ -165,10 +163,23 @@ __ASM_GLOBAL_FUNC(interlocked_xchg_add,
"mov %esi, %eax\n\t"
"lock xaddl %eax, (%rdi)\n\t"
"ret")
#else
# error You must implement the interlocked* functions for your compiler
#endif
__ASM_GLOBAL_FUNC(interlocked_cmpxchg128,
"push %rbx\n\t"
".cfi_adjust_cfa_offset 8\n\t"
".cfi_rel_offset %rbx,0\n\t"
"mov %rcx,%r8\n\t" /* compare */
"mov %rdx,%rbx\n\t" /* xchg_low */
"mov %rsi,%rcx\n\t" /* xchg_high */
"mov 0(%r8),%rax\n\t"
"mov 8(%r8),%rdx\n\t"
"lock cmpxchg16b (%rdi)\n\t"
"mov %rax,0(%r8)\n\t"
"mov %rdx,8(%r8)\n\t"
"setz %al\n\t"
"pop %rbx\n\t"
".cfi_adjust_cfa_offset -8\n\t"
".cfi_same_value %rbx\n\t"
"ret")
#elif defined(__powerpc__)
void* interlocked_cmpxchg_ptr( void **dest, void* xchg, void* compare)