[LLVMdev] Adding xadd instruction to X86
Chris Lattner
sabre at nondot.org
Thu Dec 2 15:19:44 PST 2004
On Thu, 2 Dec 2004, Brent Monroe wrote:
> I'm trying to add the xadd instruction to the X86 back end.
> xadd r/m32, r32
> exchanges r/m32 and r32, and loads the sum into r/m32. I'm
> interested in the case where the destination operand is a
> memory location.
>
> I've added the following entry to X86InstrInfo.td:
> def XADD32mr : I<0x87, MRMDestMem,
> (ops i32mem:$src1, R32:$src2),
This looks fine.
> "xadd{l} {$src1|$src2}, {$src2|$src1}">;
I haven't checked this, but it's probably fine.
> The xadd is emitted for the intrinsic function:
> call int (<integer type>*, <integer type>)*
> %llvm.atomic_fetch_add_store(<integer type>* <pointer>,
>
> <integer type> <value>)
>
> I currently have the following code (PtrReg contains the
> pointer argument, ValReg the value arg, and TmpReg an unused
> register.):
>
> addDirectMem(BuildMI(BB, X86::XADD32mr, 4,
> TmpReg).addReg(TwoReg), ValReg);
This is the problem. Try this:
addDirectMem(BuildMI(BB, X86::XADD32mr, 4, TmpReg), ValReg).addReg(TwoReg);
In particular, you want to add the memory address before the other reg.
Another problem though, is that (without looking at manual) I think xadd
modifies the register value. If this is the case, you will want to define
it as a "two-operand" instruction. Making the above change should get the
assertion to go away though.
-Chris
--
http://nondot.org/sabre/
http://llvm.cs.uiuc.edu/
More information about the llvm-dev
mailing list