Does anyone knows how can this function be changed to deal with 64bits?
{
unsigned int prev;
__asm__ __volatile__ (
" lock; cmpxchgl %1,%2; "
: "=a"(prev)
: "q"(new_value), "m"(*(int *)ptr), "0"(old_value)
: "memory");
return prev;
}
Using unsigned long prev;
and cmpxchgq
instead of cmpxchgl
as kindly suggested by Brett Hale results in these errors:
include/cs.h: Assembler messages:
include/cs.h:26: Error: incorrect register `%esi' used with `q' suffix
include/cs.h:26: Error: incorrect register `%esi' used with `q' suffix
include/cs.h:26: Error: incorrect register `%esi' used with `q' suffix
include/cs.h:26: Error: incorrect register `%r13d' used with `q' suffix
error: command 'gcc' failed with exit status 1
I think I found the reason why Brett's suggestion did not work for me. I had to the change the variable types in the function input from int
to long
. For completeness I am adding it here:
#ifndef __cs__include
#define __cs__include
static inline unsigned int CS(volatile void *ptr,
unsigned long old_value, /* was int */
unsigned long new_value) /* was int too */
{
unsigned long prev; /* result */
volatile unsigned long *vptr = (volatile unsigned long *) ptr;
__asm__ __volatile__ (
" lock; cmpxchgq %2, %1; "
: "=a" (prev), "+m" (*vptr)
: "r" (new_value), "0" (old_value)
: "memory");
return prev;
}
The code compiles without errors (though there are many warnings). However, the program does unfortunately still not work on 64bit.