Hi, 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), "xadd{l} {$src1|$src2}, {$src2|$src1}">; 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 fails the assertion isMem. Any help with this would be appreciated. Thanks, Brent
Brent Monroe wrote:> Hi, > > 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 think it might be easier if you drop by my office. I'll be here until 5:30, and I'll be here until 5:00 tomorrow.> > I've added the following entry to X86InstrInfo.td: > def XADD32mr : I<0x87, MRMDestMem, > (ops i32mem:$src1, R32:$src2), > "xadd{l} {$src1|$src2}, {$src2|$src1}">;Comparing it to the XCHG32mr instruction, the last line as $src1 and $src2 reversed. Is this correct?> > 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 fails the assertion isMem. Any help with this would be > appreciated. > > Thanks, > > Brent > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://mail.cs.uiuc.edu/mailman/listinfo/llvmdev-- John T. -- ********************************************************************* * John T. Criswell Email: criswell at uiuc.edu * * Research Programmer * * University of Illinois at Urbana-Champaign * * * * "It's today!" said Piglet. "My favorite day," said Pooh. * *********************************************************************
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/
Chris Lattner wrote:> 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.How do we define an instruction as a two-operand instruction?> > -Chris >-- John T.
Apparently Analagous Threads
- [LLVMdev] Adding xadd instruction to X86
- [LLVMdev] Adding xadd instruction to X86
- [PATCH] x86 spinlock: Fix memory corruption on completing completions
- [PATCH] x86 spinlock: Fix memory corruption on completing completions
- [PATCH] x86 spinlock: Fix memory corruption on completing completions