CMPXCHG16B correct?

后端 未结 5 806
粉色の甜心
粉色の甜心 2021-02-08 17:34

This doesn\'t exactly seem to be right although I am unsure why. Advice would be great as the documentation for CMPXCHG16B is pretty minimal (I don\'t own any intel manuals...)<

5条回答
  •  不要未来只要你来
    2021-02-08 17:56

    It's good to note that if you're using GCC, you don't need to use inline asm to get at this instruction. You can use one of the __sync functions, like:

    template<>
    inline bool cas(volatile types::uint128_t *src,
                    types::uint128_t cmp,
                    types::uint128_t with)
    {
        return __sync_bool_compare_and_swap(src, cmp, with);
    }
    

    Microsoft has a similar function for VC++:

    __int64 exchhi = __int64(with >> 64);
    __int64 exchlo = (__int64)(with);
    
    return _InterlockedCompareExchange128(a, exchhi, exchlo, &cmp) != 0;
    

提交回复
热议问题