x86 equivalent for LWARX and STWCX

前端 未结 6 1663
天命终不由人
天命终不由人 2020-12-17 22:07

I\'m looking for an equivalent of LWARX and STWCX (as found on the PowerPC processors) or a way to implement similar functionality on the x86 platform. Also, where would be

6条回答
  •  青春惊慌失措
    2020-12-17 22:16

    You're probably looking for the cmpxchg family of instructions.

    You'll need to precede these with a lock instruction to get equivalent behaviour.

    Have a look here for a quick overview of what's available.

    You'll likely end up with something similar to this:

    mov ecx,dword ptr [esp+4]
    mov edx,dword ptr [esp+8]
    mov eax,dword ptr [esp+12]
    lock cmpxchg dword ptr [ecx],edx
    ret 12
    

    You should read this paper...

    Edit

    In response to the updated question, are you looking to do something like the Boost shared_ptr? If so, have a look at that code and the files in that directory - they'll definitely get you started.

提交回复
热议问题