Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
michael@0 | 2 | * vim: set ts=8 sts=4 et sw=4 tw=99: |
michael@0 | 3 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #include "jit/mips/MoveEmitter-mips.h" |
michael@0 | 8 | |
michael@0 | 9 | using namespace js; |
michael@0 | 10 | using namespace js::jit; |
michael@0 | 11 | |
michael@0 | 12 | MoveEmitterMIPS::MoveEmitterMIPS(MacroAssemblerMIPSCompat &masm) |
michael@0 | 13 | : inCycle_(false), |
michael@0 | 14 | masm(masm), |
michael@0 | 15 | pushedAtCycle_(-1), |
michael@0 | 16 | pushedAtSpill_(-1), |
michael@0 | 17 | spilledReg_(InvalidReg), |
michael@0 | 18 | spilledFloatReg_(InvalidFloatReg) |
michael@0 | 19 | { |
michael@0 | 20 | pushedAtStart_ = masm.framePushed(); |
michael@0 | 21 | } |
michael@0 | 22 | |
michael@0 | 23 | void |
michael@0 | 24 | MoveEmitterMIPS::emit(const MoveResolver &moves) |
michael@0 | 25 | { |
michael@0 | 26 | if (moves.hasCycles()) { |
michael@0 | 27 | // Reserve stack for cycle resolution |
michael@0 | 28 | masm.reserveStack(sizeof(double)); |
michael@0 | 29 | pushedAtCycle_ = masm.framePushed(); |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | for (size_t i = 0; i < moves.numMoves(); i++) |
michael@0 | 33 | emit(moves.getMove(i)); |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | MoveEmitterMIPS::~MoveEmitterMIPS() |
michael@0 | 37 | { |
michael@0 | 38 | assertDone(); |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | Address |
michael@0 | 42 | MoveEmitterMIPS::cycleSlot() const |
michael@0 | 43 | { |
michael@0 | 44 | int offset = masm.framePushed() - pushedAtCycle_; |
michael@0 | 45 | MOZ_ASSERT(Imm16::isInSignedRange(offset)); |
michael@0 | 46 | return Address(StackPointer, offset); |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | int32_t |
michael@0 | 50 | MoveEmitterMIPS::getAdjustedOffset(const MoveOperand &operand) |
michael@0 | 51 | { |
michael@0 | 52 | MOZ_ASSERT(operand.isMemoryOrEffectiveAddress()); |
michael@0 | 53 | if (operand.base() != StackPointer) |
michael@0 | 54 | return operand.disp(); |
michael@0 | 55 | |
michael@0 | 56 | // Adjust offset if stack pointer has been moved. |
michael@0 | 57 | return operand.disp() + masm.framePushed() - pushedAtStart_; |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | Address |
michael@0 | 61 | MoveEmitterMIPS::getAdjustedAddress(const MoveOperand &operand) |
michael@0 | 62 | { |
michael@0 | 63 | return Address(operand.base(), getAdjustedOffset(operand)); |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | |
michael@0 | 67 | Register |
michael@0 | 68 | MoveEmitterMIPS::tempReg() |
michael@0 | 69 | { |
michael@0 | 70 | spilledReg_ = SecondScratchReg; |
michael@0 | 71 | return SecondScratchReg; |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | void |
michael@0 | 75 | MoveEmitterMIPS::breakCycle(const MoveOperand &from, const MoveOperand &to, MoveOp::Type type) |
michael@0 | 76 | { |
michael@0 | 77 | // There is some pattern: |
michael@0 | 78 | // (A -> B) |
michael@0 | 79 | // (B -> A) |
michael@0 | 80 | // |
michael@0 | 81 | // This case handles (A -> B), which we reach first. We save B, then allow |
michael@0 | 82 | // the original move to continue. |
michael@0 | 83 | switch (type) { |
michael@0 | 84 | case MoveOp::FLOAT32: |
michael@0 | 85 | if (to.isMemory()) { |
michael@0 | 86 | FloatRegister temp = ScratchFloatReg; |
michael@0 | 87 | masm.loadFloat32(getAdjustedAddress(to), temp); |
michael@0 | 88 | masm.storeFloat32(temp, cycleSlot()); |
michael@0 | 89 | } else { |
michael@0 | 90 | masm.storeFloat32(to.floatReg(), cycleSlot()); |
michael@0 | 91 | } |
michael@0 | 92 | break; |
michael@0 | 93 | case MoveOp::DOUBLE: |
michael@0 | 94 | if (to.isMemory()) { |
michael@0 | 95 | FloatRegister temp = ScratchFloatReg; |
michael@0 | 96 | masm.loadDouble(getAdjustedAddress(to), temp); |
michael@0 | 97 | masm.storeDouble(temp, cycleSlot()); |
michael@0 | 98 | } else { |
michael@0 | 99 | masm.storeDouble(to.floatReg(), cycleSlot()); |
michael@0 | 100 | } |
michael@0 | 101 | break; |
michael@0 | 102 | case MoveOp::INT32: |
michael@0 | 103 | MOZ_ASSERT(sizeof(uintptr_t) == sizeof(int32_t)); |
michael@0 | 104 | case MoveOp::GENERAL: |
michael@0 | 105 | if (to.isMemory()) { |
michael@0 | 106 | Register temp = tempReg(); |
michael@0 | 107 | masm.loadPtr(getAdjustedAddress(to), temp); |
michael@0 | 108 | masm.storePtr(temp, cycleSlot()); |
michael@0 | 109 | } else { |
michael@0 | 110 | // Second scratch register should not be moved by MoveEmitter. |
michael@0 | 111 | MOZ_ASSERT(to.reg() != spilledReg_); |
michael@0 | 112 | masm.storePtr(to.reg(), cycleSlot()); |
michael@0 | 113 | } |
michael@0 | 114 | break; |
michael@0 | 115 | default: |
michael@0 | 116 | MOZ_ASSUME_UNREACHABLE("Unexpected move type"); |
michael@0 | 117 | } |
michael@0 | 118 | } |
michael@0 | 119 | |
michael@0 | 120 | void |
michael@0 | 121 | MoveEmitterMIPS::completeCycle(const MoveOperand &from, const MoveOperand &to, MoveOp::Type type) |
michael@0 | 122 | { |
michael@0 | 123 | // There is some pattern: |
michael@0 | 124 | // (A -> B) |
michael@0 | 125 | // (B -> A) |
michael@0 | 126 | // |
michael@0 | 127 | // This case handles (B -> A), which we reach last. We emit a move from the |
michael@0 | 128 | // saved value of B, to A. |
michael@0 | 129 | switch (type) { |
michael@0 | 130 | case MoveOp::FLOAT32: |
michael@0 | 131 | if (to.isMemory()) { |
michael@0 | 132 | FloatRegister temp = ScratchFloatReg; |
michael@0 | 133 | masm.loadFloat32(cycleSlot(), temp); |
michael@0 | 134 | masm.storeFloat32(temp, getAdjustedAddress(to)); |
michael@0 | 135 | } else { |
michael@0 | 136 | masm.loadFloat32(cycleSlot(), to.floatReg()); |
michael@0 | 137 | } |
michael@0 | 138 | break; |
michael@0 | 139 | case MoveOp::DOUBLE: |
michael@0 | 140 | if (to.isMemory()) { |
michael@0 | 141 | FloatRegister temp = ScratchFloatReg; |
michael@0 | 142 | masm.loadDouble(cycleSlot(), temp); |
michael@0 | 143 | masm.storeDouble(temp, getAdjustedAddress(to)); |
michael@0 | 144 | } else { |
michael@0 | 145 | masm.loadDouble(cycleSlot(), to.floatReg()); |
michael@0 | 146 | } |
michael@0 | 147 | break; |
michael@0 | 148 | case MoveOp::INT32: |
michael@0 | 149 | MOZ_ASSERT(sizeof(uintptr_t) == sizeof(int32_t)); |
michael@0 | 150 | case MoveOp::GENERAL: |
michael@0 | 151 | if (to.isMemory()) { |
michael@0 | 152 | Register temp = tempReg(); |
michael@0 | 153 | masm.loadPtr(cycleSlot(), temp); |
michael@0 | 154 | masm.storePtr(temp, getAdjustedAddress(to)); |
michael@0 | 155 | } else { |
michael@0 | 156 | // Second scratch register should not be moved by MoveEmitter. |
michael@0 | 157 | MOZ_ASSERT(to.reg() != spilledReg_); |
michael@0 | 158 | masm.loadPtr(cycleSlot(), to.reg()); |
michael@0 | 159 | } |
michael@0 | 160 | break; |
michael@0 | 161 | default: |
michael@0 | 162 | MOZ_ASSUME_UNREACHABLE("Unexpected move type"); |
michael@0 | 163 | } |
michael@0 | 164 | } |
michael@0 | 165 | |
michael@0 | 166 | void |
michael@0 | 167 | MoveEmitterMIPS::emitMove(const MoveOperand &from, const MoveOperand &to) |
michael@0 | 168 | { |
michael@0 | 169 | if (from.isGeneralReg()) { |
michael@0 | 170 | // Second scratch register should not be moved by MoveEmitter. |
michael@0 | 171 | MOZ_ASSERT(from.reg() != spilledReg_); |
michael@0 | 172 | |
michael@0 | 173 | if (to.isGeneralReg()) |
michael@0 | 174 | masm.movePtr(from.reg(), to.reg()); |
michael@0 | 175 | else if (to.isMemory()) |
michael@0 | 176 | masm.storePtr(from.reg(), getAdjustedAddress(to)); |
michael@0 | 177 | else |
michael@0 | 178 | MOZ_ASSUME_UNREACHABLE("Invalid emitMove arguments."); |
michael@0 | 179 | } else if (from.isMemory()) { |
michael@0 | 180 | if (to.isGeneralReg()) { |
michael@0 | 181 | masm.loadPtr(getAdjustedAddress(from), to.reg()); |
michael@0 | 182 | } else if (to.isMemory()) { |
michael@0 | 183 | masm.loadPtr(getAdjustedAddress(from), tempReg()); |
michael@0 | 184 | masm.storePtr(tempReg(), getAdjustedAddress(to)); |
michael@0 | 185 | } else { |
michael@0 | 186 | MOZ_ASSUME_UNREACHABLE("Invalid emitMove arguments."); |
michael@0 | 187 | } |
michael@0 | 188 | } else if (from.isEffectiveAddress()) { |
michael@0 | 189 | if (to.isGeneralReg()) { |
michael@0 | 190 | masm.computeEffectiveAddress(getAdjustedAddress(from), to.reg()); |
michael@0 | 191 | } else if (to.isMemory()) { |
michael@0 | 192 | masm.computeEffectiveAddress(getAdjustedAddress(from), tempReg()); |
michael@0 | 193 | masm.storePtr(tempReg(), getAdjustedAddress(to)); |
michael@0 | 194 | } else { |
michael@0 | 195 | MOZ_ASSUME_UNREACHABLE("Invalid emitMove arguments."); |
michael@0 | 196 | } |
michael@0 | 197 | } else { |
michael@0 | 198 | MOZ_ASSUME_UNREACHABLE("Invalid emitMove arguments."); |
michael@0 | 199 | } |
michael@0 | 200 | } |
michael@0 | 201 | |
michael@0 | 202 | void |
michael@0 | 203 | MoveEmitterMIPS::emitFloat32Move(const MoveOperand &from, const MoveOperand &to) |
michael@0 | 204 | { |
michael@0 | 205 | // Ensure that we can use ScratchFloatReg in memory move. |
michael@0 | 206 | MOZ_ASSERT_IF(from.isFloatReg(), from.floatReg() != ScratchFloatReg); |
michael@0 | 207 | MOZ_ASSERT_IF(to.isFloatReg(), to.floatReg() != ScratchFloatReg); |
michael@0 | 208 | |
michael@0 | 209 | if (from.isFloatReg()) { |
michael@0 | 210 | if (to.isFloatReg()) { |
michael@0 | 211 | masm.moveFloat32(from.floatReg(), to.floatReg()); |
michael@0 | 212 | } else if (to.isGeneralReg()) { |
michael@0 | 213 | // This should only be used when passing float parameter in a1,a2,a3 |
michael@0 | 214 | MOZ_ASSERT(to.reg() == a1 || to.reg() == a2 || to.reg() == a3); |
michael@0 | 215 | masm.moveFromFloat32(from.floatReg(), to.reg()); |
michael@0 | 216 | } else { |
michael@0 | 217 | MOZ_ASSERT(to.isMemory()); |
michael@0 | 218 | masm.storeFloat32(from.floatReg(), getAdjustedAddress(to)); |
michael@0 | 219 | } |
michael@0 | 220 | } else if (to.isFloatReg()) { |
michael@0 | 221 | MOZ_ASSERT(from.isMemory()); |
michael@0 | 222 | masm.loadFloat32(getAdjustedAddress(from), to.floatReg()); |
michael@0 | 223 | } else if (to.isGeneralReg()) { |
michael@0 | 224 | MOZ_ASSERT(from.isMemory()); |
michael@0 | 225 | // This should only be used when passing float parameter in a1,a2,a3 |
michael@0 | 226 | MOZ_ASSERT(to.reg() == a1 || to.reg() == a2 || to.reg() == a3); |
michael@0 | 227 | masm.loadPtr(getAdjustedAddress(from), to.reg()); |
michael@0 | 228 | } else { |
michael@0 | 229 | MOZ_ASSERT(from.isMemory()); |
michael@0 | 230 | MOZ_ASSERT(to.isMemory()); |
michael@0 | 231 | masm.loadFloat32(getAdjustedAddress(from), ScratchFloatReg); |
michael@0 | 232 | masm.storeFloat32(ScratchFloatReg, getAdjustedAddress(to)); |
michael@0 | 233 | } |
michael@0 | 234 | } |
michael@0 | 235 | |
michael@0 | 236 | void |
michael@0 | 237 | MoveEmitterMIPS::emitDoubleMove(const MoveOperand &from, const MoveOperand &to) |
michael@0 | 238 | { |
michael@0 | 239 | // Ensure that we can use ScratchFloatReg in memory move. |
michael@0 | 240 | MOZ_ASSERT_IF(from.isFloatReg(), from.floatReg() != ScratchFloatReg); |
michael@0 | 241 | MOZ_ASSERT_IF(to.isFloatReg(), to.floatReg() != ScratchFloatReg); |
michael@0 | 242 | |
michael@0 | 243 | if (from.isFloatReg()) { |
michael@0 | 244 | if (to.isFloatReg()) { |
michael@0 | 245 | masm.moveDouble(from.floatReg(), to.floatReg()); |
michael@0 | 246 | } else if (to.isGeneralReg()) { |
michael@0 | 247 | // Used for passing double parameter in a2,a3 register pair. |
michael@0 | 248 | // Two moves are added for one double parameter by |
michael@0 | 249 | // MacroAssemblerMIPSCompat::passABIArg |
michael@0 | 250 | if(to.reg() == a2) |
michael@0 | 251 | masm.moveFromDoubleLo(from.floatReg(), a2); |
michael@0 | 252 | else if(to.reg() == a3) |
michael@0 | 253 | masm.moveFromDoubleHi(from.floatReg(), a3); |
michael@0 | 254 | else |
michael@0 | 255 | MOZ_ASSUME_UNREACHABLE("Invalid emitDoubleMove arguments."); |
michael@0 | 256 | } else { |
michael@0 | 257 | MOZ_ASSERT(to.isMemory()); |
michael@0 | 258 | masm.storeDouble(from.floatReg(), getAdjustedAddress(to)); |
michael@0 | 259 | } |
michael@0 | 260 | } else if (to.isFloatReg()) { |
michael@0 | 261 | MOZ_ASSERT(from.isMemory()); |
michael@0 | 262 | masm.loadDouble(getAdjustedAddress(from), to.floatReg()); |
michael@0 | 263 | } else if (to.isGeneralReg()) { |
michael@0 | 264 | MOZ_ASSERT(from.isMemory()); |
michael@0 | 265 | // Used for passing double parameter in a2,a3 register pair. |
michael@0 | 266 | // Two moves are added for one double parameter by |
michael@0 | 267 | // MacroAssemblerMIPSCompat::passABIArg |
michael@0 | 268 | if(to.reg() == a2) |
michael@0 | 269 | masm.loadPtr(getAdjustedAddress(from), a2); |
michael@0 | 270 | else if(to.reg() == a3) |
michael@0 | 271 | masm.loadPtr(Address(from.base(), getAdjustedOffset(from) + sizeof(uint32_t)), a3); |
michael@0 | 272 | else |
michael@0 | 273 | MOZ_ASSUME_UNREACHABLE("Invalid emitDoubleMove arguments."); |
michael@0 | 274 | } else { |
michael@0 | 275 | MOZ_ASSERT(from.isMemory()); |
michael@0 | 276 | MOZ_ASSERT(to.isMemory()); |
michael@0 | 277 | masm.loadDouble(getAdjustedAddress(from), ScratchFloatReg); |
michael@0 | 278 | masm.storeDouble(ScratchFloatReg, getAdjustedAddress(to)); |
michael@0 | 279 | } |
michael@0 | 280 | } |
michael@0 | 281 | |
michael@0 | 282 | void |
michael@0 | 283 | MoveEmitterMIPS::emit(const MoveOp &move) |
michael@0 | 284 | { |
michael@0 | 285 | const MoveOperand &from = move.from(); |
michael@0 | 286 | const MoveOperand &to = move.to(); |
michael@0 | 287 | |
michael@0 | 288 | if (move.isCycleEnd()) { |
michael@0 | 289 | MOZ_ASSERT(inCycle_); |
michael@0 | 290 | completeCycle(from, to, move.type()); |
michael@0 | 291 | inCycle_ = false; |
michael@0 | 292 | return; |
michael@0 | 293 | } |
michael@0 | 294 | |
michael@0 | 295 | if (move.isCycleBegin()) { |
michael@0 | 296 | MOZ_ASSERT(!inCycle_); |
michael@0 | 297 | breakCycle(from, to, move.endCycleType()); |
michael@0 | 298 | inCycle_ = true; |
michael@0 | 299 | } |
michael@0 | 300 | |
michael@0 | 301 | switch (move.type()) { |
michael@0 | 302 | case MoveOp::FLOAT32: |
michael@0 | 303 | emitFloat32Move(from, to); |
michael@0 | 304 | break; |
michael@0 | 305 | case MoveOp::DOUBLE: |
michael@0 | 306 | emitDoubleMove(from, to); |
michael@0 | 307 | break; |
michael@0 | 308 | case MoveOp::INT32: |
michael@0 | 309 | MOZ_ASSERT(sizeof(uintptr_t) == sizeof(int32_t)); |
michael@0 | 310 | case MoveOp::GENERAL: |
michael@0 | 311 | emitMove(from, to); |
michael@0 | 312 | break; |
michael@0 | 313 | default: |
michael@0 | 314 | MOZ_ASSUME_UNREACHABLE("Unexpected move type"); |
michael@0 | 315 | } |
michael@0 | 316 | } |
michael@0 | 317 | |
michael@0 | 318 | void |
michael@0 | 319 | MoveEmitterMIPS::assertDone() |
michael@0 | 320 | { |
michael@0 | 321 | MOZ_ASSERT(!inCycle_); |
michael@0 | 322 | } |
michael@0 | 323 | |
michael@0 | 324 | void |
michael@0 | 325 | MoveEmitterMIPS::finish() |
michael@0 | 326 | { |
michael@0 | 327 | assertDone(); |
michael@0 | 328 | |
michael@0 | 329 | masm.freeStack(masm.framePushed() - pushedAtStart_); |
michael@0 | 330 | } |