Bug 1638586 - Support double and int32 Math.abs in CacheIR. r=iain

Differential Revision: https://phabricator.services.mozilla.com/D75691
This commit is contained in:
Tom Schuster 2020-05-17 19:02:49 +00:00
Родитель 8335c6217b
Коммит eb3f650269
4 изменённых файлов: 92 добавлений и 0 удалений

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

@ -5076,6 +5076,44 @@ AttachDecision CallIRGenerator::tryAttachStringChar(HandleFunction callee,
return AttachDecision::Attach;
}
AttachDecision CallIRGenerator::tryAttachMathAbs(HandleFunction callee) {
// Need one argument.
if (argc_ != 1) {
return AttachDecision::NoAction;
}
if (!args_[0].isNumber()) {
return AttachDecision::NoAction;
}
// Initialize the input operand.
Int32OperandId argcId(writer.setInputOperandId(0));
// Guard callee is the 'abs' native function.
emitNativeCalleeGuard(callee);
ValOperandId argumentId =
writer.loadArgumentFixedSlot(ArgumentKind::Arg0, argc_);
// abs(INT_MIN) is a double.
if (args_[0].isInt32() && args_[0].toInt32() != INT_MIN) {
Int32OperandId int32Id = writer.guardToInt32(argumentId);
writer.mathAbsInt32Result(int32Id);
} else {
NumberOperandId numberId = writer.guardIsNumber(argumentId);
writer.mathAbsNumberResult(numberId);
}
// The INT_MIN case and implementation details of the C++ abs
// make this a bit tricky. We probably can just remove monitoring
// in the future completely, so do the easy thing right now.
writer.typeMonitorResult();
cacheIRStubKind_ = BaselineCacheIRStubKind::Monitored;
trackAttached("MathAbs");
return AttachDecision::Attach;
}
AttachDecision CallIRGenerator::tryAttachStringCharCodeAt(
HandleFunction callee) {
return tryAttachStringChar(callee, StringChar::CodeAt);
@ -5242,6 +5280,8 @@ AttachDecision CallIRGenerator::tryAttachSpecialCaseCallNative(
return tryAttachStringCharCodeAt(callee);
case InlinableNative::StringCharAt:
return tryAttachStringCharAt(callee);
case InlinableNative::MathAbs:
return tryAttachMathAbs(callee);
default:
return AttachDecision::NoAction;
}

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

@ -1505,6 +1505,8 @@ class MOZ_RAII CallIRGenerator : public IRGenerator {
AttachDecision tryAttachStringChar(HandleFunction callee, StringChar kind);
AttachDecision tryAttachStringCharCodeAt(HandleFunction callee);
AttachDecision tryAttachStringCharAt(HandleFunction callee);
AttachDecision tryAttachMathAbs(HandleFunction callee);
AttachDecision tryAttachFunCall(HandleFunction calleeFunc);
AttachDecision tryAttachFunApply(HandleFunction calleeFunc);
AttachDecision tryAttachCallScripted(HandleFunction calleeFunc);

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

@ -3688,6 +3688,44 @@ bool CacheIRCompiler::emitArrayJoinResult(ObjOperandId objId) {
return true;
}
bool CacheIRCompiler::emitMathAbsInt32Result(Int32OperandId inputId) {
JitSpew(JitSpew_Codegen, "%s", __FUNCTION__);
AutoOutputRegister output(*this);
AutoScratchRegisterMaybeOutput scratch(allocator, masm, output);
Register input = allocator.useRegister(masm, inputId);
FailurePath* failure;
if (!addFailurePath(&failure)) {
return false;
}
masm.mov(input, scratch);
// Don't negate already positive values.
Label positive;
masm.branchTest32(Assembler::NotSigned, scratch, scratch, &positive);
// neg32 might overflow for INT_MIN.
masm.branchNeg32(Assembler::Overflow, scratch, failure->label());
masm.bind(&positive);
EmitStoreResult(masm, scratch, JSVAL_TYPE_INT32, output);
return true;
}
bool CacheIRCompiler::emitMathAbsNumberResult(NumberOperandId inputId) {
JitSpew(JitSpew_Codegen, "%s", __FUNCTION__);
AutoOutputRegister output(*this);
AutoScratchFloatRegister scratch(this);
allocator.ensureDoubleRegister(masm, inputId, FloatReg0);
masm.absDouble(FloatReg0, scratch);
masm.boxDouble(scratch, output.valueReg(), scratch);
return true;
}
bool CacheIRCompiler::emitStoreTypedElement(ObjOperandId objId,
TypedThingLayout layout,
Scalar::Type elementType,

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

@ -656,6 +656,18 @@
args:
obj: ObjId
- name: MathAbsInt32Result
shared: true
transpile: false
args:
input: Int32Id
- name: MathAbsNumberResult
shared: true
transpile: false
args:
input: NumberId
- name: StoreTypedArrayElement
shared: true
transpile: true