Dear guys, what is the best way to implement a swap of floating point registers in X86? For the integer registers, I am using xchg. Is there a similar instruction for floating point? My function to insert swaps is like: void X86RegisterInfo::swapRegs( MachineBasicBlock & mbb, MachineBasicBlock::iterator mi, unsigned r1, unsigned r2, const TargetRegisterClass *rc ) const { unsigned Opc; if (rc == &X86::GR32RegClass) { Opc = X86::XCHG32rr; } else if (rc == &X86::GR16RegClass) { Opc = X86::XCHG16rr; } else if (rc == &X86::GR8RegClass) { Opc = X86::XCHG8rr; } else { assert(0 && "Unknown regclass in add swap"); abort(); } BuildMI(mbb, mi, Opc, 1, r1).addReg(r2); } thanks, Fernando
On 7/3/07, Fernando Magno Quintao Pereira <fernando at cs.ucla.edu> wrote:> > what is the best way to implement a swap of floating point registers > in X86? For the integer registers, I am using xchg. Is there a similar > instruction for floating point?FXCH swaps stN with st0, but you'd have to use memory for arbitrary swaps I believe. I have no idea if it's the "best" though. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20070703/a30febcb/attachment.html>
On 04 Jul 2007, at 02:10, Scott Graham wrote:> On 7/3/07, Fernando Magno Quintao Pereira <fernando at cs.ucla.edu> > wrote: >> >> what is the best way to implement a swap of floating point >> registers >> in X86? For the integer registers, I am using xchg. Is there a >> similar >> instruction for floating point? > > FXCH swaps stN with st0, but you'd have to use memory for arbitrary > swaps I > believe.Well, you can use 3 FXCH's too (stX<->st0, stY<->st0, stX<->st0). I guess that would still be a lot faster than passing via memory (not to mention that you need an extra fpu stack location if you'd do it via memory). Jonas