Skip to content

Commit

Permalink
avoid using "xchg reg, [mem]"
Browse files Browse the repository at this point in the history
xchg reg, [mem] leads to long latency due to its implicit lock prefix.
  • Loading branch information
weilianglin committed Mar 18, 2015
1 parent 0e2329c commit b1ae698
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/compiler/x64/code-generator-x64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2101,18 +2101,22 @@ void CodeGenerator::AssembleSwap(InstructionOperand* source,
__ xchgq(g.ToRegister(source), g.ToRegister(destination));
} else if (source->IsRegister() && destination->IsStackSlot()) {
Register src = g.ToRegister(source);
Register tmp = kScratchRegister;
Operand dst = g.ToOperand(destination);
__ xchgq(src, dst);
__ movq(tmp, dst);
__ movq(dst, src);
__ movq(src, tmp);
} else if ((source->IsStackSlot() && destination->IsStackSlot()) ||
(source->IsDoubleStackSlot() &&
destination->IsDoubleStackSlot())) {
// Memory-memory.
Register tmp = kScratchRegister;
Operand src = g.ToOperand(source);
Operand dst = g.ToOperand(destination);
__ movsd(xmm0, src);
__ movq(tmp, dst);
__ xchgq(tmp, src);
__ movq(dst, tmp);
__ movsd(dst, xmm0);
__ movq(src, tmp);
} else if ((source->IsSIMD128StackSlot() &&
destination->IsSIMD128StackSlot())) {
// Swap two XMM stack slots.
Expand Down

0 comments on commit b1ae698

Please sign in to comment.