cmpxch8b instruction

From: James Brown (spamtrap_at_crayne.org)
Date: 03/28/05


Date: Mon, 28 Mar 2005 18:01:20 +0000 (UTC)

All,

I have a requirement to write 8 bytes to a memory location
in an "atomic" operation - i.e. with the LOCK instruction prefix. I'm
working
in 32bit protected mode (x86 ms-windows)

The CMPXCHG8B instruction seems promising, but there is no
corresponding XCHG8B instruction. From the description of
the cmpxchg8b instruction it looks as if I will need to execute it twice:
once to load the destination memory contents into EDX:EAX,
then when I know what this 64bit value is, execute it again to
actually write my intended values.

mov eax, 0
mov edx, 0
mov ebx, [low_dword]
mov ecx, [high_dword]
lock cmpxchg8b [address] ; call once to load edx:eax
lock cmpxchg8b [address] ; call again to force write

The problem is my "atomic" write operation is now flawed
(two operations not one) Any advise on what to do here?
Speed is not an issue, would prefer short+simple rather than clever+obscure
:-)

Thanks,
James



Relevant Pages

  • [PATCH -tip -v13 01/11] x86: instruction decoder API
    ... This version introduces instruction attributes for decoding instructions. ... The instruction attribute tables are generated from the opcode map file ... +88: MOV Eb,Gb ... +e0: LOOPNE/LOOPNZ Jb (f64) ...
    (Linux-Kernel)
  • [PATCH -tip v14 01/12] x86: instruction decoder API
    ... This version introduces instruction attributes for decoding instructions. ... The instruction attribute tables are generated from the opcode map file ... +88: MOV Eb,Gb ... +e0: LOOPNE/LOOPNZ Jb (f64) ...
    (Linux-Kernel)
  • [PATCH 01/18] x86: Instruction decoder API
    ... Add x86 instruction decoder to arch-specific libraries. ... The instruction attribute tables are generated from the opcode map file ... +88: MOV Eb,Gb ... +e0: LOOPNE/LOOPNZ Jb (f64) ...
    (Linux-Kernel)
  • [PATCH -tip v6 1/5] x86: instruction decorder API
    ... This version introduces instruction attributes for decoding instructions. ... The instruction attribute tables are generated from the opcode map file ... +88: MOV Eb,Gb ... +e0: LOOPNE/LOOPNZ Jb (f64) ...
    (Linux-Kernel)
  • [PATCH -tip v6.1 1/5] x86: instruction decorder API
    ... This version introduces instruction attributes for decoding instructions. ... The instruction attribute tables are generated from the opcode map file ... +88: MOV Eb,Gb ... +e0: LOOPNE/LOOPNZ Jb (f64) ...
    (Linux-Kernel)