diff --git a/src/x86.cpp b/src/x86.cpp index df06d34e61..7c2ff572be 100644 --- a/src/x86.cpp +++ b/src/x86.cpp @@ -642,6 +642,18 @@ negateRR(Context* c, unsigned aSize, Assembler::Register* a, negateR(c, aSize, a); } +void +swapRR(Context* c, unsigned aSize UNUSED, Assembler::Register* a, + unsigned bSize UNUSED, Assembler::Register* b) +{ + assert(c, aSize == bSize); + assert(c, aSize == BytesPerWord); + + rex(c); + c->code.append(0x87); + c->code.append(0xc0 | (b->low << 3) | a->low); +} + void moveRR(Context* c, unsigned aSize, Assembler::Register* a, unsigned bSize, Assembler::Register* b) @@ -650,8 +662,17 @@ moveRR(Context* c, unsigned aSize, Assembler::Register* a, Assembler::Register ah(a->high); Assembler::Register bh(b->high); - moveRR(c, 4, a, 4, b); - moveRR(c, 4, &ah, 4, &bh); + if (a->high == b->low) { + if (a->low == b->high) { + swapRR(c, 4, a, 4, b); + } else { + moveRR(c, 4, &ah, 4, &bh); + moveRR(c, 4, a, 4, b); + } + } else { + moveRR(c, 4, a, 4, b); + moveRR(c, 4, &ah, 4, &bh); + } } else { switch (aSize) { case 1: @@ -937,18 +958,6 @@ moveZMR(Context* c, unsigned aSize UNUSED, Assembler::Memory* a, encode2(c, 0x0fb7, b->low, a, true); } -void -swapRR(Context* c, unsigned aSize UNUSED, Assembler::Register* a, - unsigned bSize UNUSED, Assembler::Register* b) -{ - assert(c, aSize == bSize); - assert(c, aSize == BytesPerWord); - - rex(c); - c->code.append(0x87); - c->code.append(0xc0 | (b->low << 3) | a->low); -} - void compareRR(Context* c, unsigned aSize, Assembler::Register* a, unsigned bSize UNUSED, Assembler::Register* b)