二重幅の比較と交換操作 (cmpxchg16b) を必要とするプロジェクトに取り組んでいます。luke hで次のコードを見つけましたが、「g++-4.7 -g -DDEBUG=1 -std=c++0x dwcas2.c -o dwcas2.o」でコンパイルすると、次のエラーが発生します。
エラー:
g++-4.7 -g -DDEBUG=1 -m64 -std=c++0x dwcas2.c -o dwcas2.o
dwcas2.c: Assembler messages:
dwcas2.c:29: Error: junk `ptr ' after expression
なぜ何か考えがありますか?, 小さくて簡単に修正できるような気がします.私はそれを見ることができません.
コンピューターの仕様: Ubuntu 12.04 LTS を実行する 64 コアの ThinkMate RAX QS5-4410 サーバー。これは、4 つの AMD Opteron 6272 CPU (1 チップあたり 16 コア @2.1 GHz) と 314 GB の共有メモリを備えた NUMA システムです。
コード:
#include <stdint.h>
namespace types
{
struct uint128_t
{
uint64_t lo;
uint64_t hi;
}
__attribute__ (( __aligned__( 16 ) ));
}
template< class T > inline bool cas( volatile T * src, T cmp, T with );
template<> inline bool cas( volatile types::uint128_t * src, types::uint128_t cmp, types::uint128_t with )
{
bool result;
__asm__ __volatile__
(
"lock cmpxchg16b oword ptr %1\n\t"
"setz %0"
: "=q" ( result )
, "+m" ( *src )
, "+d" ( cmp.hi )
, "+a" ( cmp.lo )
: "c" ( with.hi )
, "b" ( with.lo )
: "cc"
);
return result;
}
int main()
{
using namespace types;
uint128_t test = { 0xdecafbad, 0xfeedbeef };
uint128_t cmp = test;
uint128_t with = { 0x55555555, 0xaaaaaaaa };
return ! cas( & test, cmp, with );
}