在cmpxchg16b的汇编代码中编译时出错

时间:2013-09-21 15:28:37

标签: c++ inline-assembly

我正在开发一个需要双宽度比较和交换操作的项目(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服务器。它是一个NUMA系统,带有四个AMD Opteron 6272 CPU(每个芯片16个核心,2.1 GHz)和314 GB的共享内存。

代码:

#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 );
}

1 个答案:

答案 0 :(得分:2)

在x86上,GCC默认使用AT&amp; T语法汇编,但您的源代码是Intel语法。你可能还需要clobber列表中的“memory”。

相关问题