内联程序集发生Clang错误

Clang error with inline assembly

本文关键字:Clang 错误 程序集      更新时间:2023-10-16
  1 #ifndef ATOMIC_UTILS_H
  2 #define ATOMIC_UTILS_H
  3
  4 #include<cstddef>
  5
  6 class AtomicUtils
  7 {
  8     public:
  9
 10     /**
 11      * check if the value at addr is equal to oldval, if so replace it with newval
 12      * and return the oldval
 13      */
 14     static size_t compareAndExchange( volatile size_t* addr, size_t oldval, size_t newval )
 15     {
 16       size_t ret;
 17       __asm__ volatile( "lock cmpxchgl %2, %1nt"
 18                     :"=a"(ret), "+m"(*addr)
 19                     : "r"(newval), "0"(oldval)
 20                     : "memory" );
 21       return ret;
 22     }
 23 };
 24
 25 #endif
<>之前在atomics_test.cpp包含的文件中:./atoms .hpp:17:25:错误:指令的操作数无效__asm__ volatile("锁定CMPXCHGL %2, %1nt")^:1:16:注意:在这里实例化为汇编锁定CMPXCHGL %rsi, (%rdx)^ ~ ~ ~ ~之前我完全不知道这个错误。有人能帮帮忙吗??我用的是64位mac book pro,安装了clang。

错误是您正在使用64位值的cmpxchgl (cmpxchgl需要32位值)。

相关文章: