2010-05-25 14:14:13 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
* vim: set ts=4 sw=4 et tw=99:
|
|
|
|
*
|
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla SpiderMonkey JavaScript 1.9 code, released
|
|
|
|
* May 28, 2008.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Brendan Eich <brendan@mozilla.org>
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* David Anderson <danderson@mozilla.com>
|
|
|
|
* David Mandelin <dmandelin@mozilla.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2010-06-05 21:20:34 -07:00
|
|
|
#include "jsbool.h"
|
2010-05-26 00:21:47 -07:00
|
|
|
#include "methodjit/MethodJIT.h"
|
|
|
|
#include "methodjit/Compiler.h"
|
2010-05-26 17:08:08 -07:00
|
|
|
#include "methodjit/StubCalls.h"
|
2010-05-29 22:43:38 -07:00
|
|
|
#include "methodjit/FrameState-inl.h"
|
2010-05-25 14:14:13 -07:00
|
|
|
|
|
|
|
#include "jsautooplen.h"
|
|
|
|
|
|
|
|
using namespace js;
|
2010-05-26 17:08:08 -07:00
|
|
|
using namespace js::mjit;
|
2010-05-25 14:14:13 -07:00
|
|
|
|
|
|
|
void
|
|
|
|
mjit::Compiler::jsop_bindname(uint32 index)
|
|
|
|
{
|
2010-05-25 22:31:08 -07:00
|
|
|
RegisterID reg = frame.allocReg();
|
2010-05-27 21:26:19 -07:00
|
|
|
masm.loadPtr(Address(Assembler::FpReg, offsetof(JSStackFrame, scopeChain)), reg);
|
2010-05-25 22:31:08 -07:00
|
|
|
|
|
|
|
Address address(reg, offsetof(JSObject, fslots) + JSSLOT_PARENT * sizeof(jsval));
|
|
|
|
|
2010-05-29 21:48:13 -07:00
|
|
|
Jump j = masm.branch32(Assembler::NotEqual, masm.payloadOf(address), Imm32(0));
|
2010-05-25 22:31:08 -07:00
|
|
|
|
2010-05-27 21:26:19 -07:00
|
|
|
stubcc.linkExit(j);
|
|
|
|
stubcc.leave();
|
|
|
|
stubcc.call(stubs::BindName);
|
2010-05-25 22:31:08 -07:00
|
|
|
|
2010-05-29 21:48:13 -07:00
|
|
|
frame.pushTypedPayload(JSVAL_MASK32_NONFUNOBJ, reg);
|
2010-05-27 21:26:19 -07:00
|
|
|
|
|
|
|
stubcc.rejoin(1);
|
2010-05-25 14:14:13 -07:00
|
|
|
}
|
|
|
|
|
2010-06-05 17:21:56 -07:00
|
|
|
void
|
|
|
|
mjit::Compiler::jsop_bitnot()
|
|
|
|
{
|
|
|
|
FrameEntry *top = frame.peek(-1);
|
|
|
|
|
|
|
|
/* We only want to handle integers here. */
|
|
|
|
if (top->isTypeKnown() && top->getTypeTag() != JSVAL_MASK32_INT32) {
|
|
|
|
prepareStubCall();
|
|
|
|
stubCall(stubs::BitNot, Uses(1), Defs(1));
|
|
|
|
frame.pop();
|
|
|
|
frame.pushSyncedType(JSVAL_MASK32_INT32);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Test the type. */
|
|
|
|
bool stubNeeded = false;
|
|
|
|
if (!top->isTypeKnown()) {
|
|
|
|
RegisterID reg = frame.tempRegForType(top);
|
|
|
|
Jump intFail = masm.testInt32(Assembler::NotEqual, reg);
|
|
|
|
stubcc.linkExit(intFail);
|
|
|
|
frame.learnType(top, JSVAL_MASK32_INT32);
|
|
|
|
stubNeeded = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stubNeeded) {
|
|
|
|
stubcc.leave();
|
|
|
|
stubcc.call(stubs::BitNot);
|
|
|
|
}
|
|
|
|
|
|
|
|
RegisterID reg = frame.ownRegForData(top);
|
|
|
|
masm.not32(reg);
|
|
|
|
frame.pop();
|
|
|
|
frame.pushTypedPayload(JSVAL_MASK32_INT32, reg);
|
|
|
|
|
|
|
|
if (stubNeeded)
|
|
|
|
stubcc.rejoin(1);
|
|
|
|
}
|
|
|
|
|
2010-05-29 21:48:13 -07:00
|
|
|
void
|
|
|
|
mjit::Compiler::jsop_bitop(JSOp op)
|
|
|
|
{
|
|
|
|
FrameEntry *rhs = frame.peek(-1);
|
|
|
|
FrameEntry *lhs = frame.peek(-2);
|
|
|
|
|
2010-06-03 23:05:32 -07:00
|
|
|
VoidStub stub;
|
|
|
|
switch (op) {
|
2010-06-05 16:32:12 -07:00
|
|
|
case JSOP_BITOR:
|
|
|
|
stub = stubs::BitOr;
|
|
|
|
break;
|
2010-06-03 23:05:32 -07:00
|
|
|
case JSOP_BITAND:
|
|
|
|
stub = stubs::BitAnd;
|
|
|
|
break;
|
2010-06-05 15:27:56 -07:00
|
|
|
case JSOP_BITXOR:
|
|
|
|
stub = stubs::BitXor;
|
|
|
|
break;
|
2010-06-03 23:05:32 -07:00
|
|
|
case JSOP_LSH:
|
|
|
|
stub = stubs::Lsh;
|
|
|
|
break;
|
|
|
|
case JSOP_RSH:
|
|
|
|
stub = stubs::Rsh;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
JS_NOT_REACHED("wat");
|
2010-06-05 16:32:57 -07:00
|
|
|
return;
|
2010-06-03 23:05:32 -07:00
|
|
|
}
|
|
|
|
|
2010-05-29 21:48:13 -07:00
|
|
|
/* We only want to handle integers here. */
|
|
|
|
if ((rhs->isTypeKnown() && rhs->getTypeTag() != JSVAL_MASK32_INT32) ||
|
|
|
|
(lhs->isTypeKnown() && lhs->getTypeTag() != JSVAL_MASK32_INT32)) {
|
|
|
|
prepareStubCall();
|
2010-06-03 23:05:32 -07:00
|
|
|
stubCall(stub, Uses(2), Defs(1));
|
2010-05-29 21:48:13 -07:00
|
|
|
frame.popn(2);
|
|
|
|
frame.pushSyncedType(JSVAL_MASK32_INT32);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Test the types. */
|
2010-06-02 18:57:52 -07:00
|
|
|
bool stubNeeded = false;
|
2010-05-29 21:48:13 -07:00
|
|
|
if (!rhs->isTypeKnown()) {
|
|
|
|
RegisterID reg = frame.tempRegForType(rhs);
|
2010-05-30 19:44:29 -07:00
|
|
|
Jump rhsFail = masm.testInt32(Assembler::NotEqual, reg);
|
2010-05-29 21:48:13 -07:00
|
|
|
stubcc.linkExit(rhsFail);
|
2010-05-29 23:33:51 -07:00
|
|
|
frame.learnType(rhs, JSVAL_MASK32_INT32);
|
2010-06-02 18:57:52 -07:00
|
|
|
stubNeeded = true;
|
2010-05-29 21:48:13 -07:00
|
|
|
}
|
|
|
|
if (!lhs->isTypeKnown()) {
|
|
|
|
RegisterID reg = frame.tempRegForType(lhs);
|
2010-05-30 19:44:29 -07:00
|
|
|
Jump lhsFail = masm.testInt32(Assembler::NotEqual, reg);
|
2010-05-29 21:48:13 -07:00
|
|
|
stubcc.linkExit(lhsFail);
|
2010-06-02 18:57:52 -07:00
|
|
|
stubNeeded = true;
|
2010-05-29 21:48:13 -07:00
|
|
|
}
|
|
|
|
|
2010-06-02 18:57:52 -07:00
|
|
|
if (stubNeeded) {
|
|
|
|
stubcc.leave();
|
2010-06-03 23:05:32 -07:00
|
|
|
stubcc.call(stub);
|
2010-06-02 18:57:52 -07:00
|
|
|
}
|
2010-05-29 21:48:13 -07:00
|
|
|
|
2010-05-30 01:01:41 -07:00
|
|
|
if (lhs->isConstant() && rhs->isConstant()) {
|
|
|
|
int32 L = lhs->getValue().asInt32();
|
|
|
|
int32 R = rhs->getValue().asInt32();
|
|
|
|
|
|
|
|
frame.popn(2);
|
|
|
|
switch (op) {
|
2010-06-05 16:32:12 -07:00
|
|
|
case JSOP_BITOR:
|
|
|
|
frame.push(Int32Tag(L | R));
|
|
|
|
break;
|
2010-06-05 15:27:56 -07:00
|
|
|
case JSOP_BITXOR:
|
|
|
|
frame.push(Int32Tag(L ^ R));
|
|
|
|
break;
|
2010-05-30 01:01:41 -07:00
|
|
|
case JSOP_BITAND:
|
2010-06-03 23:05:32 -07:00
|
|
|
frame.push(Int32Tag(L & R));
|
|
|
|
return;
|
|
|
|
case JSOP_LSH:
|
|
|
|
frame.push(Int32Tag(L << R));
|
|
|
|
return;
|
|
|
|
case JSOP_RSH:
|
|
|
|
frame.push(Int32Tag(L >> R));
|
2010-05-30 01:01:41 -07:00
|
|
|
return;
|
|
|
|
default:
|
|
|
|
JS_NOT_REACHED("say wat");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RegisterID reg;
|
|
|
|
|
|
|
|
switch (op) {
|
2010-06-05 16:32:12 -07:00
|
|
|
case JSOP_BITOR:
|
2010-06-05 15:27:56 -07:00
|
|
|
case JSOP_BITXOR:
|
2010-05-30 01:01:41 -07:00
|
|
|
case JSOP_BITAND:
|
|
|
|
{
|
|
|
|
/* Commutative, and we're guaranteed both are ints. */
|
|
|
|
if (lhs->isConstant()) {
|
|
|
|
JS_ASSERT(!rhs->isConstant());
|
|
|
|
FrameEntry *temp = rhs;
|
|
|
|
rhs = lhs;
|
|
|
|
lhs = temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
reg = frame.ownRegForData(lhs);
|
|
|
|
if (rhs->isConstant()) {
|
2010-06-05 15:27:56 -07:00
|
|
|
if (op == JSOP_BITAND)
|
|
|
|
masm.and32(Imm32(rhs->getValue().asInt32()), reg);
|
|
|
|
else if (op == JSOP_BITXOR)
|
|
|
|
masm.xor32(Imm32(rhs->getValue().asInt32()), reg);
|
2010-06-05 16:32:12 -07:00
|
|
|
else
|
|
|
|
masm.or32(Imm32(rhs->getValue().asInt32()), reg);
|
2010-05-30 01:01:41 -07:00
|
|
|
} else if (frame.shouldAvoidDataRemat(rhs)) {
|
2010-06-05 15:27:56 -07:00
|
|
|
if (op == JSOP_BITAND)
|
|
|
|
masm.and32(masm.payloadOf(frame.addressOf(rhs)), reg);
|
|
|
|
else if (op == JSOP_BITXOR)
|
|
|
|
masm.xor32(masm.payloadOf(frame.addressOf(rhs)), reg);
|
2010-06-05 16:32:12 -07:00
|
|
|
else
|
|
|
|
masm.or32(masm.payloadOf(frame.addressOf(rhs)), reg);
|
2010-05-30 01:01:41 -07:00
|
|
|
} else {
|
|
|
|
RegisterID rhsReg = frame.tempRegForData(rhs);
|
2010-06-05 15:27:56 -07:00
|
|
|
if (op == JSOP_BITAND)
|
|
|
|
masm.and32(rhsReg, reg);
|
|
|
|
else if (op == JSOP_BITXOR)
|
|
|
|
masm.xor32(rhsReg, reg);
|
2010-06-05 16:32:12 -07:00
|
|
|
else
|
|
|
|
masm.or32(rhsReg, reg);
|
2010-05-30 01:01:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-06-03 23:05:32 -07:00
|
|
|
case JSOP_LSH:
|
|
|
|
case JSOP_RSH:
|
|
|
|
{
|
|
|
|
/* Not commutative. */
|
|
|
|
if (rhs->isConstant()) {
|
|
|
|
int32 shift = rhs->getValue().asInt32() & 0x1F;
|
|
|
|
|
2010-06-08 22:54:16 -07:00
|
|
|
reg = frame.ownRegForData(lhs);
|
|
|
|
|
2010-06-03 23:05:32 -07:00
|
|
|
if (!shift) {
|
|
|
|
/*
|
|
|
|
* Just pop RHS - leave LHS. ARM can't shift by 0.
|
|
|
|
* Type of LHS should be learned already.
|
|
|
|
*/
|
2010-06-08 22:54:16 -07:00
|
|
|
frame.popn(2);
|
|
|
|
frame.pushTypedPayload(JSVAL_MASK32_INT32, reg);
|
2010-06-03 23:05:32 -07:00
|
|
|
if (stubNeeded)
|
2010-06-08 22:27:28 -07:00
|
|
|
stubcc.rejoin(1);
|
2010-06-03 23:05:32 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (op) {
|
|
|
|
case JSOP_LSH:
|
|
|
|
masm.lshift32(Imm32(shift), reg);
|
|
|
|
break;
|
|
|
|
case JSOP_RSH:
|
|
|
|
masm.rshift32(Imm32(shift), reg);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
JS_NOT_REACHED("NYI");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
#if defined(JS_CPU_X86) || defined(JS_CPU_X64)
|
|
|
|
/* Grosssssss! RHS _must_ be in ECX, on x86 */
|
|
|
|
RegisterID rr = frame.tempRegForData(rhs, JSC::X86Registers::ecx);
|
|
|
|
#else
|
|
|
|
RegisterID rr = frame.tempRegForData(rhs);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
frame.pinReg(rr);
|
|
|
|
if (lhs->isConstant()) {
|
|
|
|
reg = frame.allocReg();
|
|
|
|
masm.move(Imm32(lhs->getValue().asInt32()), reg);
|
|
|
|
} else {
|
|
|
|
reg = frame.ownRegForData(lhs);
|
|
|
|
}
|
|
|
|
frame.unpinReg(rr);
|
|
|
|
|
|
|
|
switch (op) {
|
|
|
|
case JSOP_LSH:
|
|
|
|
masm.lshift32(rr, reg);
|
|
|
|
break;
|
|
|
|
case JSOP_RSH:
|
|
|
|
masm.rshift32(rr, reg);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
JS_NOT_REACHED("NYI");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-05-30 01:01:41 -07:00
|
|
|
default:
|
|
|
|
JS_NOT_REACHED("NYI");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-05-29 21:48:13 -07:00
|
|
|
frame.pop();
|
|
|
|
frame.pop();
|
2010-05-30 01:01:41 -07:00
|
|
|
frame.pushTypedPayload(JSVAL_MASK32_INT32, reg);
|
|
|
|
|
2010-06-02 18:57:52 -07:00
|
|
|
if (stubNeeded)
|
|
|
|
stubcc.rejoin(2);
|
2010-05-29 21:48:13 -07:00
|
|
|
}
|
|
|
|
|
2010-05-30 19:44:29 -07:00
|
|
|
void
|
|
|
|
mjit::Compiler::jsop_globalinc(JSOp op, uint32 index)
|
|
|
|
{
|
|
|
|
uint32 slot = script->getGlobalSlot(index);
|
|
|
|
|
|
|
|
bool popped = false;
|
|
|
|
PC += JSOP_GLOBALINC_LENGTH;
|
|
|
|
if (JSOp(*PC) == JSOP_POP && !analysis[PC].nincoming) {
|
|
|
|
popped = true;
|
|
|
|
PC += JSOP_POP_LENGTH;
|
|
|
|
}
|
|
|
|
|
|
|
|
int amt = (js_CodeSpec[op].format & JOF_INC) ? 1 : -1;
|
|
|
|
bool post = !!(js_CodeSpec[op].format & JOF_POST);
|
|
|
|
|
|
|
|
RegisterID data;
|
|
|
|
RegisterID reg = frame.allocReg();
|
|
|
|
Address addr = masm.objSlotRef(globalObj, reg, slot);
|
2010-06-10 17:29:57 -07:00
|
|
|
uint32 depth = frame.stackDepth();
|
2010-05-30 19:44:29 -07:00
|
|
|
|
|
|
|
if (post && !popped) {
|
|
|
|
frame.push(addr);
|
|
|
|
FrameEntry *fe = frame.peek(-1);
|
|
|
|
Jump notInt = frame.testInt32(Assembler::NotEqual, fe);
|
|
|
|
stubcc.linkExit(notInt);
|
|
|
|
data = frame.copyData(fe);
|
|
|
|
} else {
|
|
|
|
Jump notInt = masm.testInt32(Assembler::NotEqual, addr);
|
|
|
|
stubcc.linkExit(notInt);
|
|
|
|
data = frame.allocReg();
|
|
|
|
masm.loadData32(addr, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
Jump ovf;
|
|
|
|
if (amt > 0)
|
|
|
|
ovf = masm.branchAdd32(Assembler::Overflow, Imm32(1), data);
|
|
|
|
else
|
|
|
|
ovf = masm.branchSub32(Assembler::Overflow, Imm32(1), data);
|
|
|
|
stubcc.linkExit(ovf);
|
|
|
|
|
|
|
|
stubcc.leave();
|
|
|
|
stubcc.masm.lea(addr, Registers::ArgReg1);
|
2010-06-10 17:29:57 -07:00
|
|
|
stubcc.vpInc(op, depth);
|
2010-05-30 19:44:29 -07:00
|
|
|
|
|
|
|
masm.storeData32(data, addr);
|
|
|
|
|
|
|
|
if (!post && !popped)
|
|
|
|
frame.pushUntypedPayload(JSVAL_MASK32_INT32, data);
|
|
|
|
else
|
|
|
|
frame.freeReg(data);
|
|
|
|
|
|
|
|
frame.freeReg(reg);
|
|
|
|
|
|
|
|
stubcc.rejoin(1);
|
|
|
|
}
|
|
|
|
|
2010-05-31 02:17:05 -07:00
|
|
|
void
|
2010-05-31 22:44:00 -07:00
|
|
|
mjit::Compiler::jsop_relational(JSOp op, BoolStub stub, jsbytecode *target, JSOp fused)
|
2010-05-31 02:17:05 -07:00
|
|
|
{
|
2010-05-31 03:19:46 -07:00
|
|
|
FrameEntry *rhs = frame.peek(-1);
|
|
|
|
FrameEntry *lhs = frame.peek(-2);
|
|
|
|
|
2010-05-31 22:44:00 -07:00
|
|
|
/* The compiler should have handled constant folding. */
|
|
|
|
JS_ASSERT(!(rhs->isConstant() && lhs->isConstant()));
|
|
|
|
|
|
|
|
/* Always slow path... */
|
|
|
|
if ((rhs->isTypeKnown() && rhs->getTypeTag() != JSVAL_MASK32_INT32) ||
|
|
|
|
(lhs->isTypeKnown() && lhs->getTypeTag() != JSVAL_MASK32_INT32)) {
|
|
|
|
emitStubCmpOp(stub, target, fused);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-05-31 03:19:46 -07:00
|
|
|
/* Test the types. */
|
|
|
|
if (!rhs->isTypeKnown()) {
|
|
|
|
RegisterID reg = frame.tempRegForType(rhs);
|
|
|
|
Jump rhsFail = masm.testInt32(Assembler::NotEqual, reg);
|
|
|
|
stubcc.linkExit(rhsFail);
|
|
|
|
frame.learnType(rhs, JSVAL_MASK32_INT32);
|
|
|
|
}
|
|
|
|
if (!lhs->isTypeKnown()) {
|
|
|
|
RegisterID reg = frame.tempRegForType(lhs);
|
|
|
|
Jump lhsFail = masm.testInt32(Assembler::NotEqual, reg);
|
|
|
|
stubcc.linkExit(lhsFail);
|
|
|
|
}
|
2010-05-31 22:44:00 -07:00
|
|
|
|
|
|
|
Assembler::Condition cond;
|
|
|
|
switch (op) {
|
|
|
|
case JSOP_LT:
|
|
|
|
cond = Assembler::LessThan;
|
|
|
|
break;
|
|
|
|
case JSOP_LE:
|
|
|
|
cond = Assembler::LessThanOrEqual;
|
|
|
|
break;
|
|
|
|
case JSOP_GT:
|
|
|
|
cond = Assembler::GreaterThan;
|
|
|
|
break;
|
|
|
|
case JSOP_GE:
|
|
|
|
cond = Assembler::GreaterThanOrEqual;
|
|
|
|
break;
|
2010-06-03 21:29:03 -07:00
|
|
|
case JSOP_EQ:
|
|
|
|
cond = Assembler::Equal;
|
|
|
|
break;
|
|
|
|
case JSOP_NE:
|
|
|
|
cond = Assembler::NotEqual;
|
|
|
|
break;
|
2010-05-31 22:44:00 -07:00
|
|
|
default:
|
|
|
|
JS_NOT_REACHED("wat");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Swap the LHS and RHS if it makes register allocation better... or possible. */
|
|
|
|
bool swapped = false;
|
|
|
|
if (lhs->isConstant() ||
|
|
|
|
(frame.shouldAvoidDataRemat(lhs) && !rhs->isConstant())) {
|
|
|
|
FrameEntry *temp = rhs;
|
|
|
|
rhs = lhs;
|
|
|
|
lhs = temp;
|
|
|
|
swapped = true;
|
|
|
|
|
|
|
|
switch (cond) {
|
|
|
|
case Assembler::LessThan:
|
|
|
|
cond = Assembler::GreaterThan;
|
|
|
|
break;
|
|
|
|
case Assembler::LessThanOrEqual:
|
|
|
|
cond = Assembler::GreaterThanOrEqual;
|
|
|
|
break;
|
|
|
|
case Assembler::GreaterThan:
|
|
|
|
cond = Assembler::LessThan;
|
|
|
|
break;
|
|
|
|
case Assembler::GreaterThanOrEqual:
|
|
|
|
cond = Assembler::LessThanOrEqual;
|
|
|
|
break;
|
2010-06-03 21:29:03 -07:00
|
|
|
case Assembler::Equal: /* fall through */
|
|
|
|
case Assembler::NotEqual:
|
|
|
|
/* Equal and NotEqual are commutative. */
|
|
|
|
break;
|
2010-05-31 22:44:00 -07:00
|
|
|
default:
|
|
|
|
JS_NOT_REACHED("wat");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stubcc.leave();
|
|
|
|
stubcc.call(stub);
|
|
|
|
|
|
|
|
if (target) {
|
|
|
|
/* We can do a little better when we know the opcode is fused. */
|
|
|
|
RegisterID lr = frame.ownRegForData(lhs);
|
|
|
|
|
|
|
|
/* Initialize stuff to quell GCC warnings. */
|
|
|
|
bool rhsConst;
|
|
|
|
int32 rval = 0;
|
|
|
|
RegisterID rr = Registers::ReturnReg;
|
|
|
|
if (!(rhsConst = rhs->isConstant()))
|
|
|
|
rr = frame.ownRegForData(rhs);
|
|
|
|
else
|
|
|
|
rval = rhs->getValue().asInt32();
|
|
|
|
|
|
|
|
frame.pop();
|
|
|
|
frame.pop();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Note: this resets the regster allocator, so rr and lr don't need
|
|
|
|
* to be freed. We're not going to touch the frame.
|
|
|
|
*/
|
|
|
|
frame.forgetEverything();
|
|
|
|
|
|
|
|
/* Invert the test for IFEQ. */
|
|
|
|
if (fused == JSOP_IFEQ) {
|
|
|
|
switch (cond) {
|
|
|
|
case Assembler::LessThan:
|
|
|
|
cond = Assembler::GreaterThanOrEqual;
|
|
|
|
break;
|
|
|
|
case Assembler::LessThanOrEqual:
|
|
|
|
cond = Assembler::GreaterThan;
|
|
|
|
break;
|
|
|
|
case Assembler::GreaterThan:
|
|
|
|
cond = Assembler::LessThanOrEqual;
|
|
|
|
break;
|
|
|
|
case Assembler::GreaterThanOrEqual:
|
|
|
|
cond = Assembler::LessThan;
|
|
|
|
break;
|
2010-06-04 19:29:43 -07:00
|
|
|
case Assembler::Equal:
|
|
|
|
cond = Assembler::NotEqual;
|
|
|
|
break;
|
2010-06-03 21:29:03 -07:00
|
|
|
case Assembler::NotEqual:
|
2010-06-04 19:29:43 -07:00
|
|
|
cond = Assembler::Equal;
|
2010-06-03 21:29:03 -07:00
|
|
|
break;
|
2010-05-31 22:44:00 -07:00
|
|
|
default:
|
|
|
|
JS_NOT_REACHED("hello");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Jump j;
|
|
|
|
if (!rhsConst)
|
|
|
|
j = masm.branch32(cond, lr, rr);
|
|
|
|
else
|
|
|
|
j = masm.branch32(cond, lr, Imm32(rval));
|
|
|
|
|
|
|
|
jumpInScript(j, target);
|
|
|
|
|
|
|
|
JaegerSpew(JSpew_Insns, " ---- BEGIN SLOW RESTORE CODE ---- \n");
|
|
|
|
/*
|
|
|
|
* The stub call has no need to rejoin, since state is synced.
|
|
|
|
* Instead, we can just test the return value.
|
|
|
|
*/
|
|
|
|
Assembler::Condition cond = (fused == JSOP_IFEQ)
|
|
|
|
? Assembler::Zero
|
|
|
|
: Assembler::NonZero;
|
|
|
|
j = stubcc.masm.branchTest32(cond, Registers::ReturnReg, Registers::ReturnReg);
|
|
|
|
stubcc.jumpInScript(j, target);
|
2010-06-02 15:57:36 -07:00
|
|
|
|
|
|
|
/* Rejoin unnecessary - state is flushed. */
|
|
|
|
j = stubcc.masm.jump();
|
|
|
|
stubcc.crossJump(j, masm.label());
|
2010-05-31 22:44:00 -07:00
|
|
|
JaegerSpew(JSpew_Insns, " ---- END SLOW RESTORE CODE ---- \n");
|
|
|
|
} else {
|
|
|
|
/* No fusing. Compare, set, and push a boolean. */
|
|
|
|
|
|
|
|
RegisterID reg = frame.ownRegForData(lhs);
|
|
|
|
|
|
|
|
/* x86/64's SET instruction can only take single-byte regs.*/
|
|
|
|
RegisterID resultReg = reg;
|
|
|
|
if (!(Registers::maskReg(reg) & Registers::SingleByteRegs))
|
|
|
|
resultReg = frame.allocReg(Registers::SingleByteRegs);
|
|
|
|
|
|
|
|
/* Emit the compare & set. */
|
|
|
|
if (rhs->isConstant()) {
|
|
|
|
masm.set32(cond, reg, Imm32(rhs->getValue().asInt32()), resultReg);
|
|
|
|
} else if (frame.shouldAvoidDataRemat(rhs)) {
|
|
|
|
masm.set32(cond, reg,
|
|
|
|
masm.payloadOf(frame.addressOf(rhs)),
|
|
|
|
resultReg);
|
|
|
|
} else {
|
|
|
|
masm.set32(cond, reg, frame.tempRegForData(rhs), resultReg);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clean up and push a boolean. */
|
|
|
|
frame.pop();
|
|
|
|
frame.pop();
|
|
|
|
if (reg != resultReg)
|
|
|
|
frame.freeReg(reg);
|
|
|
|
frame.pushTypedPayload(JSVAL_MASK32_BOOLEAN, resultReg);
|
|
|
|
stubcc.rejoin(1);
|
|
|
|
}
|
2010-05-31 02:17:05 -07:00
|
|
|
}
|
|
|
|
|
2010-06-05 14:26:00 -07:00
|
|
|
void
|
|
|
|
mjit::Compiler::jsop_neg()
|
|
|
|
{
|
|
|
|
prepareStubCall();
|
|
|
|
stubCall(stubs::Neg, Uses(1), Defs(1));
|
|
|
|
frame.pop();
|
|
|
|
frame.pushSynced();
|
|
|
|
}
|
|
|
|
|
2010-06-05 15:20:36 -07:00
|
|
|
void
|
|
|
|
mjit::Compiler::jsop_objtostr()
|
|
|
|
{
|
|
|
|
prepareStubCall();
|
|
|
|
stubCall(stubs::ObjToStr, Uses(1), Defs(1));
|
|
|
|
frame.pop();
|
|
|
|
frame.pushSynced();
|
|
|
|
}
|
|
|
|
|
2010-06-05 21:20:34 -07:00
|
|
|
void
|
|
|
|
mjit::Compiler::jsop_not()
|
|
|
|
{
|
|
|
|
FrameEntry *top = frame.peek(-1);
|
|
|
|
|
|
|
|
if (top->isConstant()) {
|
|
|
|
const Value &v = top->getValue();
|
|
|
|
frame.pop();
|
|
|
|
frame.push(BooleanTag(!js_ValueToBoolean(v)));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (top->isTypeKnown()) {
|
|
|
|
uint32 mask = top->getTypeTag();
|
|
|
|
switch (mask) {
|
|
|
|
case JSVAL_MASK32_INT32:
|
|
|
|
case JSVAL_MASK32_BOOLEAN:
|
|
|
|
{
|
|
|
|
/* :FIXME: X64 */
|
|
|
|
/* :FIXME: Faster to xor 1, zero-extend */
|
|
|
|
RegisterID reg = frame.ownRegForData(top);
|
|
|
|
Jump t = masm.branchTest32(Assembler::NotEqual, reg, reg);
|
|
|
|
masm.move(Imm32(1), reg);
|
|
|
|
Jump d = masm.jump();
|
|
|
|
t.linkTo(masm.label(), &masm);
|
|
|
|
masm.move(Imm32(0), reg);
|
|
|
|
d.linkTo(masm.label(), &masm);
|
|
|
|
frame.pop();
|
|
|
|
frame.pushTypedPayload(JSVAL_MASK32_BOOLEAN, reg);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case JSVAL_MASK32_NONFUNOBJ:
|
|
|
|
case JSVAL_MASK32_FUNOBJ:
|
|
|
|
{
|
|
|
|
frame.pop();
|
|
|
|
frame.push(BooleanTag(false));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
/* :FIXME: overkill to spill everything - can use same xor trick too */
|
|
|
|
RegisterID reg = Registers::ReturnReg;
|
|
|
|
prepareStubCall();
|
|
|
|
stubCall(stubs::ValueToBoolean, Uses(0), Defs(0));
|
|
|
|
frame.takeReg(reg);
|
|
|
|
Jump t = masm.branchTest32(Assembler::NotEqual, reg, reg);
|
|
|
|
masm.move(Imm32(1), reg);
|
|
|
|
Jump d = masm.jump();
|
|
|
|
t.linkTo(masm.label(), &masm);
|
|
|
|
masm.move(Imm32(0), reg);
|
|
|
|
d.linkTo(masm.label(), &masm);
|
|
|
|
frame.pop();
|
|
|
|
frame.pushTypedPayload(JSVAL_MASK32_BOOLEAN, reg);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fast-path here is boolean. */
|
|
|
|
Jump boolFail = frame.testBoolean(Assembler::NotEqual, top);
|
|
|
|
stubcc.linkExit(boolFail);
|
|
|
|
frame.learnType(top, JSVAL_MASK32_BOOLEAN);
|
|
|
|
|
|
|
|
stubcc.leave();
|
|
|
|
stubcc.call(stubs::Not);
|
|
|
|
|
|
|
|
RegisterID reg = frame.ownRegForData(top);
|
|
|
|
masm.xor32(Imm32(1), reg);
|
|
|
|
frame.pop();
|
|
|
|
frame.pushTypedPayload(JSVAL_MASK32_BOOLEAN, reg);
|
|
|
|
|
|
|
|
stubcc.rejoin(1);
|
|
|
|
}
|
|
|
|
|
2010-06-06 00:34:14 -07:00
|
|
|
void
|
|
|
|
mjit::Compiler::jsop_typeof()
|
|
|
|
{
|
|
|
|
FrameEntry *fe = frame.peek(-1);
|
|
|
|
|
|
|
|
if (fe->isTypeKnown()) {
|
|
|
|
JSRuntime *rt = cx->runtime;
|
|
|
|
|
|
|
|
JSAtom *atom = NULL;
|
|
|
|
switch (fe->getTypeTag()) {
|
|
|
|
case JSVAL_MASK32_STRING:
|
|
|
|
atom = rt->atomState.typeAtoms[JSTYPE_STRING];
|
|
|
|
break;
|
|
|
|
case JSVAL_MASK32_UNDEFINED:
|
|
|
|
atom = rt->atomState.typeAtoms[JSTYPE_VOID];
|
|
|
|
break;
|
|
|
|
case JSVAL_MASK32_NULL:
|
|
|
|
atom = rt->atomState.typeAtoms[JSTYPE_OBJECT];
|
|
|
|
break;
|
|
|
|
case JSVAL_MASK32_FUNOBJ:
|
|
|
|
case JSVAL_MASK32_NONFUNOBJ:
|
|
|
|
atom = NULL;
|
|
|
|
break;
|
|
|
|
case JSVAL_MASK32_BOOLEAN:
|
|
|
|
atom = rt->atomState.typeAtoms[JSTYPE_BOOLEAN];
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
atom = rt->atomState.typeAtoms[JSTYPE_NUMBER];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (atom) {
|
|
|
|
frame.pop();
|
|
|
|
frame.push(StringTag(ATOM_TO_STRING(atom)));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
prepareStubCall();
|
|
|
|
stubCall(stubs::TypeOf, Uses(1), Defs(1));
|
|
|
|
frame.pop();
|
|
|
|
frame.takeReg(Registers::ReturnReg);
|
|
|
|
frame.pushTypedPayload(JSVAL_MASK32_STRING, Registers::ReturnReg);
|
|
|
|
}
|
|
|
|
|
2010-06-10 17:29:57 -07:00
|
|
|
void
|
|
|
|
mjit::Compiler::jsop_arginc(JSOp op, uint32 slot, bool popped)
|
|
|
|
{
|
|
|
|
int amt = (js_CodeSpec[op].format & JOF_INC) ? 1 : -1;
|
|
|
|
bool post = !!(js_CodeSpec[op].format & JOF_POST);
|
|
|
|
uint32 depth = frame.stackDepth();
|
|
|
|
|
|
|
|
jsop_getarg(slot);
|
|
|
|
if (post && !popped)
|
|
|
|
frame.dup();
|
|
|
|
|
|
|
|
FrameEntry *fe = frame.peek(-1);
|
|
|
|
Jump notInt = frame.testInt32(Assembler::NotEqual, fe);
|
|
|
|
stubcc.linkExit(notInt);
|
|
|
|
|
|
|
|
RegisterID reg = frame.ownRegForData(fe);
|
|
|
|
frame.pop();
|
|
|
|
|
|
|
|
Jump ovf;
|
|
|
|
if (amt > 0)
|
|
|
|
ovf = masm.branchAdd32(Assembler::Overflow, Imm32(1), reg);
|
|
|
|
else
|
|
|
|
ovf = masm.branchSub32(Assembler::Overflow, Imm32(1), reg);
|
|
|
|
stubcc.linkExit(ovf);
|
|
|
|
|
|
|
|
Address argv(Assembler::FpReg, offsetof(JSStackFrame, argv));
|
|
|
|
|
|
|
|
stubcc.leave();
|
|
|
|
stubcc.masm.loadPtr(argv, Registers::ArgReg1);
|
|
|
|
stubcc.masm.addPtr(Imm32(sizeof(Value) * slot), Registers::ArgReg1, Registers::ArgReg1);
|
|
|
|
stubcc.vpInc(op, depth);
|
|
|
|
|
|
|
|
frame.pushTypedPayload(JSVAL_MASK32_INT32, reg);
|
|
|
|
fe = frame.peek(-1);
|
|
|
|
|
|
|
|
reg = frame.allocReg();
|
|
|
|
masm.loadPtr(argv, reg);
|
|
|
|
Address address = Address(reg, slot * sizeof(Value));
|
|
|
|
frame.storeTo(fe, address, popped);
|
|
|
|
frame.freeReg(reg);
|
|
|
|
|
|
|
|
if (post || popped)
|
|
|
|
frame.pop();
|
|
|
|
else
|
|
|
|
frame.forgetType(fe);
|
|
|
|
|
|
|
|
stubcc.rejoin(1);
|
|
|
|
}
|
|
|
|
|