Bug 1438727: [Part 11] Implement JSOP_DIV in CacheIR r=jandem

--HG--
extra : rebase_source : 4926515b6dd4061a8287d05e88061d8929cb3906
This commit is contained in:
Matthew Gaudet 2018-05-01 13:56:32 -04:00
Родитель 0fba2182f3
Коммит 9df2c19321
7 изменённых файлов: 57 добавлений и 3 удалений

Просмотреть файл

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

Просмотреть файл

@ -5159,7 +5159,8 @@ BinaryArithIRGenerator::tryAttachInt32()
{
if (op_ != JSOP_ADD && op_ != JSOP_SUB &&
op_ != JSOP_BITOR && op_ != JSOP_BITAND &&
op_ != JSOP_BITXOR && op_ != JSOP_MUL)
op_ != JSOP_BITXOR && op_ != JSOP_MUL &&
op_ != JSOP_DIV)
{
return false;
}
@ -5186,6 +5187,10 @@ BinaryArithIRGenerator::tryAttachInt32()
writer.int32MulResult(lhsIntId, rhsIntId);
trackAttached("BinaryArith.Int32.Mul");
break;
case JSOP_DIV:
writer.int32DivResult(lhsIntId, rhsIntId);
trackAttached("BinaryArith.Int32.Div");
break;
case JSOP_BITOR:
writer.int32BitOrResult(lhsIntId, rhsIntId);
trackAttached("BinaryArith.Int32.BitOr");
@ -5211,7 +5216,7 @@ BinaryArithIRGenerator::tryAttachBooleanWithInt32()
{
if (op_ != JSOP_ADD && op_ != JSOP_SUB &&
op_ != JSOP_BITOR && op_ != JSOP_BITAND &&
op_ != JSOP_BITXOR && op_!= JSOP_MUL)
op_ != JSOP_BITXOR && op_ != JSOP_MUL && op_ != JSOP_DIV)
return false;
if (!(lhs_.isBoolean() && (rhs_.isBoolean() || rhs_.isInt32())) &&
@ -5240,6 +5245,10 @@ BinaryArithIRGenerator::tryAttachBooleanWithInt32()
writer.int32MulResult(lhsIntId, rhsIntId);
trackAttached("BinaryArith.BooleanInt32.Mul");
break;
case JSOP_DIV:
writer.int32DivResult(lhsIntId, rhsIntId);
trackAttached("BinaryArith.BooleanInt32.Div");
break;
case JSOP_BITOR:
writer.int32BitOrResult(lhsIntId, rhsIntId);
trackAttached("BinaryArith.BooleanInt32.BitOr");

Просмотреть файл

@ -298,6 +298,7 @@ extern const char* CacheKindNames[];
_(Int32AddResult) \
_(Int32SubResult) \
_(Int32MulResult) \
_(Int32DivResult) \
_(Int32BitOrResult) \
_(Int32BitXorResult) \
_(Int32BitAndResult) \
@ -1030,6 +1031,10 @@ class MOZ_RAII CacheIRWriter : public JS::CustomAutoRooter
writeOpWithOperandId(CacheOp::Int32MulResult, lhs);
writeOperandId(rhs);
}
void int32DivResult(Int32OperandId lhs, Int32OperandId rhs) {
writeOpWithOperandId(CacheOp::Int32DivResult, lhs);
writeOperandId(rhs);
}
void int32BitOrResult(Int32OperandId lhs, Int32OperandId rhs) {
writeOpWithOperandId(CacheOp::Int32BitOrResult, lhs);
writeOperandId(rhs);

Просмотреть файл

@ -2058,6 +2058,39 @@ CacheIRCompiler::emitInt32MulResult()
EmitStoreResult(masm, lhs, JSVAL_TYPE_INT32, output);
return true;
}
bool
CacheIRCompiler::emitInt32DivResult()
{
AutoOutputRegister output(*this);
Register lhs = allocator.useRegister(masm, reader.int32OperandId());
Register rhs = allocator.useRegister(masm, reader.int32OperandId());
AutoScratchRegister rem(allocator, masm);
FailurePath* failure;
if (!addFailurePath(&failure))
return false;
// Prevent division by 0.
masm.branchTest32(Assembler::Zero, rhs, rhs, failure->label());
// Prevent negative 0 and -2147483648 / -1.
masm.branch32(Assembler::Equal, lhs, Imm32(INT32_MIN), failure->label());
Label notZero;
masm.branch32(Assembler::NotEqual, lhs, Imm32(0), &notZero);
masm.branchTest32(Assembler::Signed, rhs, rhs, failure->label());
masm.bind(&notZero);
LiveRegisterSet volatileRegs(GeneralRegisterSet::Volatile(), liveVolatileFloatRegs());
masm.flexibleDivMod32(rhs, lhs, rem, false, volatileRegs);
// A remainder implies a double result.
masm.branchTest32(Assembler::NonZero, rem, rem, failure->label());
EmitStoreResult(masm, lhs, JSVAL_TYPE_INT32, output);
return true;
}
bool
CacheIRCompiler::emitInt32BitOrResult()
{

Просмотреть файл

@ -58,6 +58,7 @@ namespace jit {
_(Int32AddResult) \
_(Int32SubResult) \
_(Int32MulResult) \
_(Int32DivResult) \
_(Int32BitOrResult) \
_(Int32BitXorResult) \
_(Int32BitAndResult) \

Просмотреть файл

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

Просмотреть файл

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