Bug 1438727: [Part 8] Implement JSOP_MUL in CacheIR r=tcampbell

--HG--
extra : rebase_source : e17f138c9e1c5061332a10971f0f880e681f091c
This commit is contained in:
Matthew Gaudet 2018-03-26 09:58:19 -04:00
parent 380ca375d8
commit 2c49bae399
7 changed files with 76 additions and 4 deletions

View File

@ -4956,6 +4956,7 @@ DoCacheIRBinaryArithFallback(JSContext* cx, BaselineFrame* frame, ICBinaryArith_
case JSOP_BITOR:
case JSOP_BITXOR:
case JSOP_BITAND:
case JSOP_MUL:
break;
default:
return false; // Fallback to shared IC.

View File

@ -5118,7 +5118,8 @@ BinaryArithIRGenerator::tryAttachStub()
bool
BinaryArithIRGenerator::tryAttachDouble()
{
if (op_ != JSOP_ADD && op_ != JSOP_SUB)
if (op_ != JSOP_ADD && op_ != JSOP_SUB &&
op_ != JSOP_MUL)
return false;
if (!lhs_.isDouble() || !rhs_.isDouble() || !res_.isDouble())
@ -5142,6 +5143,10 @@ BinaryArithIRGenerator::tryAttachDouble()
writer.doubleSubResult(lhsId, rhsId);
trackAttached("BinaryArith.Double.Sub");
break;
case JSOP_MUL:
writer.doubleMulResult(lhsId, rhsId);
trackAttached("BinaryArith.Double.Mul");
break;
default:
MOZ_CRASH("Unhandled Op");
}
@ -5154,7 +5159,7 @@ BinaryArithIRGenerator::tryAttachInt32()
{
if (op_ != JSOP_ADD && op_ != JSOP_SUB &&
op_ != JSOP_BITOR && op_ != JSOP_BITAND &&
op_ != JSOP_BITXOR)
op_ != JSOP_BITXOR && op_ != JSOP_MUL)
{
return false;
}
@ -5177,6 +5182,10 @@ BinaryArithIRGenerator::tryAttachInt32()
writer.int32SubResult(lhsIntId, rhsIntId);
trackAttached("BinaryArith.Int32.Sub");
break;
case JSOP_MUL:
writer.int32MulResult(lhsIntId, rhsIntId);
trackAttached("BinaryArith.Int32.Mul");
break;
case JSOP_BITOR:
writer.int32BitOrResult(lhsIntId, rhsIntId);
trackAttached("BinaryArith.Int32.BitOr");
@ -5202,7 +5211,7 @@ BinaryArithIRGenerator::tryAttachBooleanWithInt32()
{
if (op_ != JSOP_ADD && op_ != JSOP_SUB &&
op_ != JSOP_BITOR && op_ != JSOP_BITAND &&
op_ != JSOP_BITXOR)
op_ != JSOP_BITXOR && op_!= JSOP_MUL)
return false;
if (!(lhs_.isBoolean() && (rhs_.isBoolean() || rhs_.isInt32())) &&
@ -5227,6 +5236,10 @@ BinaryArithIRGenerator::tryAttachBooleanWithInt32()
writer.int32SubResult(lhsIntId, rhsIntId);
trackAttached("BinaryArith.BooleanInt32.Sub");
break;
case JSOP_MUL:
writer.int32MulResult(lhsIntId, rhsIntId);
trackAttached("BinaryArith.BooleanInt32.Mul");
break;
case JSOP_BITOR:
writer.int32BitOrResult(lhsIntId, rhsIntId);
trackAttached("BinaryArith.BooleanInt32.BitOr");

View File

@ -294,8 +294,10 @@ extern const char* CacheKindNames[];
_(LoadTypeOfObjectResult) \
_(DoubleAddResult) \
_(DoubleSubResult) \
_(DoubleMulResult) \
_(Int32AddResult) \
_(Int32SubResult) \
_(Int32MulResult) \
_(Int32BitOrResult) \
_(Int32BitXorResult) \
_(Int32BitAndResult) \
@ -1012,6 +1014,10 @@ class MOZ_RAII CacheIRWriter : public JS::CustomAutoRooter
writeOpWithOperandId(CacheOp::DoubleSubResult, lhsId);
writeOperandId(rhsId);
}
void doubleMulResult(ValOperandId lhsId, ValOperandId rhsId) {
writeOpWithOperandId(CacheOp::DoubleMulResult, lhsId);
writeOperandId(rhsId);
}
void int32AddResult(Int32OperandId lhs, Int32OperandId rhs) {
writeOpWithOperandId(CacheOp::Int32AddResult, lhs);
writeOperandId(rhs);
@ -1020,6 +1026,10 @@ class MOZ_RAII CacheIRWriter : public JS::CustomAutoRooter
writeOpWithOperandId(CacheOp::Int32SubResult, lhs);
writeOperandId(rhs);
}
void int32MulResult(Int32OperandId lhs, Int32OperandId rhs) {
writeOpWithOperandId(CacheOp::Int32MulResult, lhs);
writeOperandId(rhs);
}
void int32BitOrResult(Int32OperandId lhs, Int32OperandId rhs) {
writeOpWithOperandId(CacheOp::Int32BitOrResult, lhs);
writeOperandId(rhs);

View File

@ -1954,6 +1954,7 @@ CacheIRCompiler::emitLoadInt32ArrayLengthResult()
EmitStoreResult(masm, scratch, JSVAL_TYPE_INT32, output);
return true;
}
bool
CacheIRCompiler::emitDoubleAddResult()
{
@ -1983,6 +1984,19 @@ CacheIRCompiler::emitDoubleSubResult()
return true;
}
bool
CacheIRCompiler::emitDoubleMulResult()
{
AutoOutputRegister output(*this);
allocator.loadDouble(masm, reader.valOperandId(), FloatReg0);
allocator.loadDouble(masm, reader.valOperandId(), FloatReg1);
masm.mulDouble(FloatReg1, FloatReg0);
masm.boxDouble(FloatReg0, output.valueReg(), FloatReg0);
return true;
}
bool
CacheIRCompiler::emitInt32AddResult()
@ -2016,6 +2030,34 @@ CacheIRCompiler::emitInt32SubResult()
return true;
}
bool
CacheIRCompiler::emitInt32MulResult()
{
AutoOutputRegister output(*this);
Register lhs = allocator.useRegister(masm, reader.int32OperandId());
Register rhs = allocator.useRegister(masm, reader.int32OperandId());
AutoScratchRegisterMaybeOutput scratch(allocator, masm, output);
FailurePath* failure;
if (!addFailurePath(&failure))
return false;
Label maybeNegZero, done;
masm.mov(lhs, scratch);
masm.branchMul32(Assembler::Overflow, rhs, lhs, failure->label());
masm.branchTest32(Assembler::Zero, lhs, lhs, &maybeNegZero);
masm.jump(&done);
masm.bind(&maybeNegZero);
// Result is -0 if exactly one of lhs or rhs is negative.
masm.or32(rhs, scratch);
masm.branchTest32(Assembler::Signed, scratch, scratch, failure->label());
masm.bind(&done);
EmitStoreResult(masm, lhs, JSVAL_TYPE_INT32, output);
return true;
}
bool
CacheIRCompiler::emitInt32BitOrResult()
{

View File

@ -54,8 +54,10 @@ namespace jit {
_(LoadInt32ArrayLengthResult) \
_(DoubleAddResult) \
_(DoubleSubResult) \
_(DoubleMulResult) \
_(Int32AddResult) \
_(Int32SubResult) \
_(Int32MulResult) \
_(Int32BitOrResult) \
_(Int32BitXorResult) \
_(Int32BitAndResult) \

View File

@ -3571,13 +3571,13 @@ IonBuilder::arithTrySharedStub(bool* emitted, JSOp op,
break;
case JSOP_ADD:
case JSOP_SUB:
case JSOP_MUL:
// If not disabled, prefer the cache IR stub.
if (!JitOptions.disableCacheIRBinaryArith) {
stub = MBinaryCache::New(alloc(), left, right);
break;
}
MOZ_FALLTHROUGH;
case JSOP_MUL:
case JSOP_DIV:
case JSOP_MOD:
case JSOP_POW:

View File

@ -575,6 +575,10 @@ IonBinaryArithIC::update(JSContext* cx, HandleScript outerScript, IonBinaryArith
if (!SubValues(cx, &lhsCopy, &rhsCopy, ret))
return false;
break;
case JSOP_MUL:
if (!MulValues(cx, &lhsCopy, &rhsCopy, ret))
return false;
break;
case JSOP_BITOR: {
int32_t result;
if (!BitOr(cx, lhs, rhs, &result))