// Warning, do not use the resulting operand with pop instructions, since they // compute the effective destination address after altering the stack pointer. // Use toPopOperand if an Operand is needed for a pop. Operand MoveEmitterMIPS::toOperand(const MoveOperand &operand) const { if (operand.isMemory() || operand.isEffectiveAddress() || operand.isFloatAddress()) return Operand(toAddress(operand)); if (operand.isGeneralReg()) return Operand(operand.reg()); JS_ASSERT(operand.isFloatReg()); return Operand(operand.floatReg()); }
void MoveEmitterMIPS::emitMove(const MoveOperand &from, const MoveOperand &to) { if (from.isGeneralReg()) { // Second scratch register should not be moved by MoveEmitter. MOZ_ASSERT(from.reg() != spilledReg_); if (to.isGeneralReg()) masm.movePtr(from.reg(), to.reg()); else if (to.isMemory()) masm.storePtr(from.reg(), getAdjustedAddress(to)); else MOZ_ASSUME_UNREACHABLE("Invalid emitMove arguments."); } else if (from.isMemory()) { if (to.isGeneralReg()) { masm.loadPtr(getAdjustedAddress(from), to.reg()); } else if (to.isMemory()) { masm.loadPtr(getAdjustedAddress(from), tempReg()); masm.storePtr(tempReg(), getAdjustedAddress(to)); } else { MOZ_ASSUME_UNREACHABLE("Invalid emitMove arguments."); } } else if (from.isEffectiveAddress()) { if (to.isGeneralReg()) { masm.computeEffectiveAddress(getAdjustedAddress(from), to.reg()); } else if (to.isMemory()) { masm.computeEffectiveAddress(getAdjustedAddress(from), tempReg()); masm.storePtr(tempReg(), getAdjustedAddress(to)); } else { MOZ_ASSUME_UNREACHABLE("Invalid emitMove arguments."); } } else { MOZ_ASSUME_UNREACHABLE("Invalid emitMove arguments."); } }
void MoveEmitterARM::emitFloat32Move(const MoveOperand& from, const MoveOperand& to) { // Register pairs are used to store Double values during calls. MOZ_ASSERT(!from.isGeneralRegPair()); MOZ_ASSERT(!to.isGeneralRegPair()); if (from.isFloatReg()) { if (to.isFloatReg()) masm.ma_vmov_f32(from.floatReg(), to.floatReg()); else if (to.isGeneralReg()) masm.ma_vxfer(from.floatReg(), to.reg()); else masm.ma_vstr(VFPRegister(from.floatReg()).singleOverlay(), toAddress(to)); } else if (from.isGeneralReg()) { if (to.isFloatReg()) masm.ma_vxfer(from.reg(), to.floatReg()); else if (to.isGeneralReg()) masm.ma_mov(from.reg(), to.reg()); else masm.ma_str(from.reg(), toAddress(to)); } else if (to.isFloatReg()) { masm.ma_vldr(toAddress(from), VFPRegister(to.floatReg()).singleOverlay()); } else if (to.isGeneralReg()) { masm.ma_ldr(toAddress(from), to.reg()); } else { // Memory to memory move. MOZ_ASSERT(from.isMemory()); FloatRegister reg = ScratchFloat32Reg; masm.ma_vldr(toAddress(from), VFPRegister(reg).singleOverlay()); masm.ma_vstr(VFPRegister(reg).singleOverlay(), toAddress(to)); } }
void MoveEmitterX86::emitInt32Move(const MoveOperand &from, const MoveOperand &to) { if (from.isGeneralReg()) { masm.move32(from.reg(), toOperand(to)); } else if (to.isGeneralReg()) { JS_ASSERT(from.isMemory()); masm.load32(toAddress(from), to.reg()); } else { // Memory to memory gpr move. JS_ASSERT(from.isMemory()); #ifdef JS_CODEGEN_X64 // x64 has a ScratchReg. Use it. masm.load32(toAddress(from), ScratchReg); masm.move32(ScratchReg, toOperand(to)); #else // No ScratchReg; bounce it off the stack. masm.Push(toOperand(from)); masm.Pop(toPopOperand(to)); #endif } }
void MoveEmitterX86::emitGeneralMove(const MoveOperand &from, const MoveOperand &to) { if (from.isGeneralReg()) { masm.mov(from.reg(), toOperand(to)); } else if (to.isGeneralReg()) { JS_ASSERT(from.isMemoryOrEffectiveAddress()); if (from.isMemory()) masm.loadPtr(toAddress(from), to.reg()); else masm.lea(toOperand(from), to.reg()); } else if (from.isMemory()) { // Memory to memory gpr move. #ifdef JS_CODEGEN_X64 // x64 has a ScratchReg. Use it. masm.loadPtr(toAddress(from), ScratchReg); masm.mov(ScratchReg, toOperand(to)); #else // No ScratchReg; bounce it off the stack. masm.Push(toOperand(from)); masm.Pop(toPopOperand(to)); #endif } else { // Effective address to memory move. JS_ASSERT(from.isEffectiveAddress()); #ifdef JS_CODEGEN_X64 // x64 has a ScratchReg. Use it. masm.lea(toOperand(from), ScratchReg); masm.mov(ScratchReg, toOperand(to)); #else // This is tricky without a ScratchReg. We can't do an lea. Bounce the // base register off the stack, then add the offset in place. Note that // this clobbers FLAGS! masm.Push(from.base()); masm.Pop(toPopOperand(to)); masm.addPtr(Imm32(from.disp()), toOperand(to)); #endif } }
void MoveEmitterMIPS::emitMove(const MoveOperand &from, const MoveOperand &to) { if (to.isGeneralReg() && to.reg() == spilledReg_) { // If the destination is the spilled register, make sure we // don't re-clobber its value. spilledReg_ = InvalidReg; } if (from.isGeneralReg()) { if (from.reg() == spilledReg_) { // If the source is a register that has been spilled, make sure // to load the source back into that register. masm.mov(spillSlot(), spilledReg_); spilledReg_ = InvalidReg; } masm.mov(from.reg(), toOperand(to)); } else if (to.isGeneralReg()) { JS_ASSERT(from.isMemory() || from.isEffectiveAddress()); if (from.isMemory()) masm.mov(toOperand(from), to.reg()); else masm.lea(toOperand(from), to.reg()); } else { // Memory to memory gpr move. Register reg = tempReg(); // Reload its previous value from the stack. if (reg == from.base()) masm.mov(spillSlot(), from.base()); JS_ASSERT(from.isMemory() || from.isEffectiveAddress()); if (from.isMemory()) masm.mov(toOperand(from), reg); else masm.lea(toOperand(from), reg); JS_ASSERT(to.base() != reg); masm.mov(reg, toOperand(to)); } }
void MoveEmitterX86::emitInt32Move(const MoveOperand& from, const MoveOperand& to) { if (from.isGeneralReg()) { masm.move32(from.reg(), toOperand(to)); } else if (to.isGeneralReg()) { MOZ_ASSERT(from.isMemory()); masm.load32(toAddress(from), to.reg()); } else { // Memory to memory gpr move. MOZ_ASSERT(from.isMemory()); if (hasScratchRegister()) { Register reg = scratchRegister(); masm.load32(toAddress(from), reg); masm.move32(reg, toOperand(to)); } else { // No scratch register available; bounce it off the stack. masm.Push(toOperand(from)); masm.Pop(toPopOperand(to)); } } }
void MoveEmitterX86::emitGeneralMove(const MoveOperand& from, const MoveOperand& to) { if (from.isGeneralReg()) { masm.mov(from.reg(), toOperand(to)); } else if (to.isGeneralReg()) { MOZ_ASSERT(from.isMemoryOrEffectiveAddress()); if (from.isMemory()) masm.loadPtr(toAddress(from), to.reg()); else masm.lea(toOperand(from), to.reg()); } else if (from.isMemory()) { // Memory to memory gpr move. if (hasScratchRegister()) { Register reg = scratchRegister(); masm.loadPtr(toAddress(from), reg); masm.mov(reg, toOperand(to)); } else { // No scratch register available; bounce it off the stack. masm.Push(toOperand(from)); masm.Pop(toPopOperand(to)); } } else { // Effective address to memory move. MOZ_ASSERT(from.isEffectiveAddress()); if (hasScratchRegister()) { Register reg = scratchRegister(); masm.lea(toOperand(from), reg); masm.mov(reg, toOperand(to)); } else { // This is tricky without a scratch reg. We can't do an lea. Bounce the // base register off the stack, then add the offset in place. Note that // this clobbers FLAGS! masm.Push(from.base()); masm.Pop(toPopOperand(to)); masm.addPtr(Imm32(from.disp()), toOperand(to)); } } }
void MoveEmitterX86::completeCycle(const MoveOperand &to, MoveOp::Type type) { // There is some pattern: // (A -> B) // (B -> A) // // This case handles (B -> A), which we reach last. We emit a move from the // saved value of B, to A. switch (type) { case MoveOp::FLOAT32: JS_ASSERT(pushedAtCycle_ != -1); JS_ASSERT(pushedAtCycle_ - pushedAtStart_ >= sizeof(float)); if (to.isMemory()) { masm.loadFloat32(cycleSlot(), ScratchFloatReg); masm.storeFloat32(ScratchFloatReg, toAddress(to)); } else { masm.loadFloat32(cycleSlot(), to.floatReg()); } break; case MoveOp::DOUBLE: JS_ASSERT(pushedAtCycle_ != -1); JS_ASSERT(pushedAtCycle_ - pushedAtStart_ >= sizeof(double)); if (to.isMemory()) { masm.loadDouble(cycleSlot(), ScratchFloatReg); masm.storeDouble(ScratchFloatReg, toAddress(to)); } else { masm.loadDouble(cycleSlot(), to.floatReg()); } break; case MoveOp::INT32: #ifdef JS_CODEGEN_X64 JS_ASSERT(pushedAtCycle_ != -1); JS_ASSERT(pushedAtCycle_ - pushedAtStart_ >= sizeof(int32_t)); // x64 can't pop to a 32-bit destination. if (to.isMemory()) { masm.load32(cycleSlot(), ScratchReg); masm.store32(ScratchReg, toAddress(to)); } else { masm.load32(cycleSlot(), to.reg()); } break; #endif case MoveOp::GENERAL: JS_ASSERT(masm.framePushed() - pushedAtStart_ >= sizeof(intptr_t)); masm.Pop(toPopOperand(to)); break; default: MOZ_ASSUME_UNREACHABLE("Unexpected move type"); } }
void MoveEmitterX86::breakCycle(const MoveOperand &to, MoveOp::Type type) { // There is some pattern: // (A -> B) // (B -> A) // // This case handles (A -> B), which we reach first. We save B, then allow // the original move to continue. switch (type) { case MoveOp::FLOAT32: if (to.isMemory()) { masm.loadFloat32(toAddress(to), ScratchFloatReg); masm.storeFloat32(ScratchFloatReg, cycleSlot()); } else { masm.storeFloat32(to.floatReg(), cycleSlot()); } break; case MoveOp::DOUBLE: if (to.isMemory()) { masm.loadDouble(toAddress(to), ScratchFloatReg); masm.storeDouble(ScratchFloatReg, cycleSlot()); } else { masm.storeDouble(to.floatReg(), cycleSlot()); } break; #ifdef JS_CPU_X64 case MoveOp::INT32: // x64 can't pop to a 32-bit destination, so don't push. if (to.isMemory()) { masm.load32(toAddress(to), ScratchReg); masm.store32(ScratchReg, cycleSlot()); } else { masm.store32(to.reg(), cycleSlot()); } break; #endif #ifndef JS_CPU_X64 case MoveOp::INT32: #endif case MoveOp::GENERAL: masm.Push(toOperand(to)); break; default: MOZ_ASSUME_UNREACHABLE("Unexpected move type"); } }
void MacroAssemblerX64::passABIArg(const MoveOperand& from, MoveOp::Type type) { MoveOperand to; switch (type) { case MoveOp::FLOAT32: case MoveOp::DOUBLE: { FloatRegister dest; if (GetFloatArgReg(passedIntArgs_, passedFloatArgs_++, &dest)) { // Convert to the right type of register. if (type == MoveOp::FLOAT32) dest = dest.asSingle(); if (from.isFloatReg() && from.floatReg() == dest) { // Nothing to do; the value is in the right register already return; } to = MoveOperand(dest); } else { to = MoveOperand(StackPointer, stackForCall_); switch (type) { case MoveOp::FLOAT32: stackForCall_ += sizeof(float); break; case MoveOp::DOUBLE: stackForCall_ += sizeof(double); break; default: MOZ_CRASH("Unexpected float register class argument type"); } } break; } case MoveOp::GENERAL: { Register dest; if (GetIntArgReg(passedIntArgs_++, passedFloatArgs_, &dest)) { if (from.isGeneralReg() && from.reg() == dest) { // Nothing to do; the value is in the right register already return; } to = MoveOperand(dest); } else { to = MoveOperand(StackPointer, stackForCall_); stackForCall_ += sizeof(int64_t); } break; } default: MOZ_CRASH("Unexpected argument type"); } enoughMemory_ = moveResolver_.addMove(from, to, type); }
// Warning, do not use the resulting operand with pop instructions, since they // compute the effective destination address after altering the stack pointer. // Use toPopOperand if an Operand is needed for a pop. Operand MoveEmitterX86::toOperand(const MoveOperand &operand) const { if (operand.isMemory() || operand.isEffectiveAddress() || operand.isFloatAddress()) { if (operand.base() != StackPointer) return Operand(operand.base(), operand.disp()); JS_ASSERT(operand.disp() >= 0); // Otherwise, the stack offset may need to be adjusted. return Operand(StackPointer, operand.disp() + (masm.framePushed() - pushedAtStart_)); } if (operand.isGeneralReg()) return Operand(operand.reg()); JS_ASSERT(operand.isFloatReg()); return Operand(operand.floatReg()); }
void MoveEmitterARM::emitMove(const MoveOperand &from, const MoveOperand &to) { if (to.isGeneralReg() && to.reg() == spilledReg_) { // If the destination is the spilled register, make sure we // don't re-clobber its value. spilledReg_ = InvalidReg; } if (from.isGeneralReg()) { if (from.reg() == spilledReg_) { // If the source is a register that has been spilled, make sure // to load the source back into that register. masm.ma_ldr(spillSlot(), spilledReg_); spilledReg_ = InvalidReg; } switch (toOperand(to, false).getTag()) { case Operand::OP2: // secretly must be a register masm.ma_mov(from.reg(), to.reg()); break; case Operand::MEM: masm.ma_str(from.reg(), toOperand(to, false)); break; default: MOZ_ASSUME_UNREACHABLE("strange move!"); } } else if (to.isGeneralReg()) { JS_ASSERT(from.isMemory() || from.isEffectiveAddress()); if (from.isMemory()) masm.ma_ldr(toOperand(from, false), to.reg()); else masm.ma_add(from.base(), Imm32(from.disp()), to.reg()); } else { // Memory to memory gpr move. Register reg = tempReg(); JS_ASSERT(from.isMemory() || from.isEffectiveAddress()); if (from.isMemory()) masm.ma_ldr(toOperand(from, false), reg); else masm.ma_add(from.base(), Imm32(from.disp()), reg); JS_ASSERT(to.base() != reg); masm.ma_str(reg, toOperand(to, false)); } }
// This is the same as toOperand except that it computes an Operand suitable for // use in a pop. Operand MoveEmitterX86::toPopOperand(const MoveOperand& operand) const { if (operand.isMemory()) { if (operand.base() != StackPointer) return Operand(operand.base(), operand.disp()); MOZ_ASSERT(operand.disp() >= 0); // Otherwise, the stack offset may need to be adjusted. // Note the adjustment by the stack slot here, to offset for the fact that pop // computes its effective address after incrementing the stack pointer. return Operand(StackPointer, operand.disp() + (masm.framePushed() - sizeof(void*) - pushedAtStart_)); } if (operand.isGeneralReg()) return Operand(operand.reg()); MOZ_ASSERT(operand.isFloatReg()); return Operand(operand.floatReg()); }
void MoveEmitterARM::emitMove(const MoveOperand& from, const MoveOperand& to) { // Register pairs are used to store Double values during calls. MOZ_ASSERT(!from.isGeneralRegPair()); MOZ_ASSERT(!to.isGeneralRegPair()); if (to.isGeneralReg() && to.reg() == spilledReg_) { // If the destination is the spilled register, make sure we // don't re-clobber its value. spilledReg_ = InvalidReg; } if (from.isGeneralReg()) { if (from.reg() == spilledReg_) { // If the source is a register that has been spilled, make sure // to load the source back into that register. masm.ma_ldr(spillSlot(), spilledReg_); spilledReg_ = InvalidReg; } if (to.isMemoryOrEffectiveAddress()) masm.ma_str(from.reg(), toAddress(to)); else masm.ma_mov(from.reg(), to.reg()); } else if (to.isGeneralReg()) { MOZ_ASSERT(from.isMemoryOrEffectiveAddress()); if (from.isMemory()) masm.ma_ldr(toAddress(from), to.reg()); else masm.ma_add(from.base(), Imm32(from.disp()), to.reg()); } else { // Memory to memory gpr move. Register reg = tempReg(); MOZ_ASSERT(from.isMemoryOrEffectiveAddress()); if (from.isMemory()) masm.ma_ldr(toAddress(from), reg); else masm.ma_add(from.base(), Imm32(from.disp()), reg); MOZ_ASSERT(to.base() != reg); masm.ma_str(reg, toAddress(to)); } }
void MoveEmitterX86::breakCycle(const MoveOperand &to, Move::Kind kind) { // There is some pattern: // (A -> B) // (B -> A) // // This case handles (A -> B), which we reach first. We save B, then allow // the original move to continue. if (kind == Move::DOUBLE) { if (to.isMemory()) { masm.movsd(toOperand(to), ScratchFloatReg); masm.movsd(ScratchFloatReg, cycleSlot()); } else { masm.movsd(to.floatReg(), cycleSlot()); } } else { if (to.isMemory()) masm.Push(toOperand(to)); else masm.Push(to.reg()); } }
void MoveEmitterX86::completeCycle(const MoveOperand &to, Move::Kind kind) { // There is some pattern: // (A -> B) // (B -> A) // // This case handles (B -> A), which we reach last. We emit a move from the // saved value of B, to A. if (kind == Move::DOUBLE) { if (to.isMemory()) { masm.movsd(cycleSlot(), ScratchFloatReg); masm.movsd(ScratchFloatReg, toOperand(to)); } else { masm.movsd(cycleSlot(), to.floatReg()); } } else { if (to.isMemory()) { masm.Pop(toPopOperand(to)); } else { masm.Pop(to.reg()); } } }
void MoveEmitterARM::completeCycle(const MoveOperand& from, const MoveOperand& to, MoveOp::Type type, uint32_t slotId) { // There is some pattern: // (A -> B) // (B -> A) // // This case handles (B -> A), which we reach last. We emit a move from the // saved value of B, to A. switch (type) { case MoveOp::FLOAT32: MOZ_ASSERT(!to.isGeneralRegPair()); if (to.isMemory()) { ScratchFloat32Scope scratch(masm); masm.ma_vldr(cycleSlot(slotId, 0), scratch); masm.ma_vstr(scratch, toAddress(to)); } else if (to.isGeneralReg()) { MOZ_ASSERT(type == MoveOp::FLOAT32); masm.ma_ldr(toAddress(from), to.reg()); } else { uint32_t offset = 0; if ((!from.isMemory()) && from.floatReg().numAlignedAliased() == 1) offset = sizeof(float); masm.ma_vldr(cycleSlot(slotId, offset), to.floatReg()); } break; case MoveOp::DOUBLE: MOZ_ASSERT(!to.isGeneralReg()); if (to.isMemory()) { ScratchDoubleScope scratch(masm); masm.ma_vldr(cycleSlot(slotId, 0), scratch); masm.ma_vstr(scratch, toAddress(to)); } else if (to.isGeneralRegPair()) { MOZ_ASSERT(type == MoveOp::DOUBLE); ScratchDoubleScope scratch(masm); masm.ma_vldr(toAddress(from), scratch); masm.ma_vxfer(scratch, to.evenReg(), to.oddReg()); } else { uint32_t offset = 0; if ((!from.isMemory()) && from.floatReg().numAlignedAliased() == 1) offset = sizeof(float); masm.ma_vldr(cycleSlot(slotId, offset), to.floatReg()); } break; case MoveOp::INT32: case MoveOp::GENERAL: MOZ_ASSERT(slotId == 0); if (to.isMemory()) { Register temp = tempReg(); masm.ma_ldr(cycleSlot(slotId, 0), temp); masm.ma_str(temp, toAddress(to)); } else { if (to.reg() == spilledReg_) { // Make sure we don't re-clobber the spilled register later. spilledReg_ = InvalidReg; } masm.ma_ldr(cycleSlot(slotId, 0), to.reg()); } break; default: MOZ_CRASH("Unexpected move type"); } }
void MoveEmitterARM::breakCycle(const MoveOperand& from, const MoveOperand& to, MoveOp::Type type, uint32_t slotId) { // There is some pattern: // (A -> B) // (B -> A) // // This case handles (A -> B), which we reach first. We save B, then allow // the original move to continue. switch (type) { case MoveOp::FLOAT32: if (to.isMemory()) { VFPRegister temp = ScratchFloat32Reg; masm.ma_vldr(toAddress(to), temp); // Since it is uncertain if the load will be aligned or not // just fill both of them with the same value. masm.ma_vstr(temp, cycleSlot(slotId, 0)); masm.ma_vstr(temp, cycleSlot(slotId, 4)); } else if (to.isGeneralReg()) { // Since it is uncertain if the load will be aligned or not // just fill both of them with the same value. masm.ma_str(to.reg(), cycleSlot(slotId, 0)); masm.ma_str(to.reg(), cycleSlot(slotId, 4)); } else { FloatRegister src = to.floatReg(); // Just always store the largest possible size. Currently, this is // a double. When SIMD is added, two doubles will need to be stored. masm.ma_vstr(src.doubleOverlay(), cycleSlot(slotId, 0)); } break; case MoveOp::DOUBLE: if (to.isMemory()) { ScratchDoubleScope scratch(masm); masm.ma_vldr(toAddress(to), scratch); masm.ma_vstr(scratch, cycleSlot(slotId, 0)); } else if (to.isGeneralRegPair()) { ScratchDoubleScope scratch(masm); masm.ma_vxfer(to.evenReg(), to.oddReg(), scratch); masm.ma_vstr(scratch, cycleSlot(slotId, 0)); } else { masm.ma_vstr(to.floatReg().doubleOverlay(), cycleSlot(slotId, 0)); } break; case MoveOp::INT32: case MoveOp::GENERAL: // an non-vfp value if (to.isMemory()) { Register temp = tempReg(); masm.ma_ldr(toAddress(to), temp); masm.ma_str(temp, cycleSlot(0,0)); } else { if (to.reg() == spilledReg_) { // If the destination was spilled, restore it first. masm.ma_ldr(spillSlot(), spilledReg_); spilledReg_ = InvalidReg; } masm.ma_str(to.reg(), cycleSlot(0,0)); } break; default: MOZ_CRASH("Unexpected move type"); } }