64ビットを処理するためにこの関数を変更する方法を知っている人はいますか?
{
unsigned int prev;
__asm__ __volatile__ (
" lock; cmpxchgl %1,%2; "
: "=a"(prev)
: "q"(new_value), "m"(*(int *)ptr), "0"(old_value)
: "memory");
return prev;
}
Brett Hale が親切に提案した代わりにunsigned long prev;
andを使用すると、次のエラーが発生します。cmpxchgq
cmpxchgl
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
ブレットの提案がうまくいかなかった理由がわかったと思います。関数入力の変数の型を から に変更する必要がありましint
たlong
。完全を期すために、ここに追加します。
#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;
}
コードはエラーなしでコンパイルされます (ただし、多くの警告があります)。ただし、残念ながらこのプログラムは 64 ビットではまだ動作しません。