Separate Math Lithium operations.

This makes the logic in the Hydrogen->Lithium translation much clearer, avoids a
hand-written dispatch and even opened up opportunities for simpler register
constraints for some operations/platforms.

Doing the same for the Hydrogen level might be done in a follow-up CL.

Review URL: https://codereview.chromium.org/13841003

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14233 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
svenpanne@chromium.org 2013-04-11 13:27:06 +00:00
parent 5fd24b0afa
commit 12e74509d4
16 changed files with 900 additions and 507 deletions

View File

@ -302,17 +302,6 @@ void LCallConstantFunction::PrintDataTo(StringStream* stream) {
} }
void LUnaryMathOperation::PrintDataTo(StringStream* stream) {
stream->Add("/%s ", hydrogen()->OpName());
value()->PrintTo(stream);
}
void LMathExp::PrintDataTo(StringStream* stream) {
value()->PrintTo(stream);
}
void LLoadContextSlot::PrintDataTo(StringStream* stream) { void LLoadContextSlot::PrintDataTo(StringStream* stream) {
context()->PrintTo(stream); context()->PrintTo(stream);
stream->Add("[%d]", slot_index()); stream->Add("[%d]", slot_index());
@ -1124,12 +1113,75 @@ LInstruction* LChunkBuilder::DoInvokeFunction(HInvokeFunction* instr) {
LInstruction* LChunkBuilder::DoUnaryMathOperation(HUnaryMathOperation* instr) { LInstruction* LChunkBuilder::DoUnaryMathOperation(HUnaryMathOperation* instr) {
BuiltinFunctionId op = instr->op(); switch (instr->op()) {
if (op == kMathLog || op == kMathSin || op == kMathCos || op == kMathTan) { case kMathFloor: return DoMathFloor(instr);
case kMathRound: return DoMathRound(instr);
case kMathAbs: return DoMathAbs(instr);
case kMathLog: return DoMathLog(instr);
case kMathSin: return DoMathSin(instr);
case kMathCos: return DoMathCos(instr);
case kMathTan: return DoMathTan(instr);
case kMathExp: return DoMathExp(instr);
case kMathSqrt: return DoMathSqrt(instr);
case kMathPowHalf: return DoMathPowHalf(instr);
default:
UNREACHABLE();
return NULL;
}
}
LInstruction* LChunkBuilder::DoMathFloor(HUnaryMathOperation* instr) {
LOperand* input = UseRegister(instr->value());
LMathFloor* result = new(zone()) LMathFloor(input);
return AssignEnvironment(AssignPointerMap(DefineAsRegister(result)));
}
LInstruction* LChunkBuilder::DoMathRound(HUnaryMathOperation* instr) {
LOperand* input = UseRegister(instr->value());
LOperand* temp = FixedTemp(d3);
LMathRound* result = new(zone()) LMathRound(input, temp);
return AssignEnvironment(DefineAsRegister(result));
}
LInstruction* LChunkBuilder::DoMathAbs(HUnaryMathOperation* instr) {
LOperand* input = UseRegister(instr->value());
LMathAbs* result = new(zone()) LMathAbs(input);
return AssignEnvironment(AssignPointerMap(DefineAsRegister(result)));
}
LInstruction* LChunkBuilder::DoMathLog(HUnaryMathOperation* instr) {
LOperand* input = UseFixedDouble(instr->value(), d2); LOperand* input = UseFixedDouble(instr->value(), d2);
LUnaryMathOperation* result = new(zone()) LUnaryMathOperation(input, NULL); LMathLog* result = new(zone()) LMathLog(input);
return MarkAsCall(DefineFixedDouble(result, d2), instr); return MarkAsCall(DefineFixedDouble(result, d2), instr);
} else if (op == kMathExp) { }
LInstruction* LChunkBuilder::DoMathSin(HUnaryMathOperation* instr) {
LOperand* input = UseFixedDouble(instr->value(), d2);
LMathSin* result = new(zone()) LMathSin(input);
return MarkAsCall(DefineFixedDouble(result, d2), instr);
}
LInstruction* LChunkBuilder::DoMathCos(HUnaryMathOperation* instr) {
LOperand* input = UseFixedDouble(instr->value(), d2);
LMathCos* result = new(zone()) LMathCos(input);
return MarkAsCall(DefineFixedDouble(result, d2), instr);
}
LInstruction* LChunkBuilder::DoMathTan(HUnaryMathOperation* instr) {
LOperand* input = UseFixedDouble(instr->value(), d2);
LMathTan* result = new(zone()) LMathTan(input);
return MarkAsCall(DefineFixedDouble(result, d2), instr);
}
LInstruction* LChunkBuilder::DoMathExp(HUnaryMathOperation* instr) {
ASSERT(instr->representation().IsDouble()); ASSERT(instr->representation().IsDouble());
ASSERT(instr->value()->representation().IsDouble()); ASSERT(instr->value()->representation().IsDouble());
LOperand* input = UseTempRegister(instr->value()); LOperand* input = UseTempRegister(instr->value());
@ -1138,30 +1190,21 @@ LInstruction* LChunkBuilder::DoUnaryMathOperation(HUnaryMathOperation* instr) {
LOperand* double_temp = FixedTemp(d3); // Chosen by fair dice roll. LOperand* double_temp = FixedTemp(d3); // Chosen by fair dice roll.
LMathExp* result = new(zone()) LMathExp(input, double_temp, temp1, temp2); LMathExp* result = new(zone()) LMathExp(input, double_temp, temp1, temp2);
return DefineAsRegister(result); return DefineAsRegister(result);
} else if (op == kMathPowHalf) { }
LInstruction* LChunkBuilder::DoMathSqrt(HUnaryMathOperation* instr) {
LOperand* input = UseRegister(instr->value());
LMathSqrt* result = new(zone()) LMathSqrt(input);
return DefineAsRegister(result);
}
LInstruction* LChunkBuilder::DoMathPowHalf(HUnaryMathOperation* instr) {
LOperand* input = UseFixedDouble(instr->value(), d2); LOperand* input = UseFixedDouble(instr->value(), d2);
LOperand* temp = FixedTemp(d3); LOperand* temp = FixedTemp(d3);
LUnaryMathOperation* result = new(zone()) LUnaryMathOperation(input, temp); LMathPowHalf* result = new(zone()) LMathPowHalf(input, temp);
return DefineFixedDouble(result, d2); return DefineFixedDouble(result, d2);
} else {
LOperand* input = UseRegister(instr->value());
LOperand* temp = (op == kMathRound) ? FixedTemp(d3) : NULL;
LUnaryMathOperation* result = new(zone()) LUnaryMathOperation(input, temp);
switch (op) {
case kMathAbs:
return AssignEnvironment(AssignPointerMap(DefineAsRegister(result)));
case kMathFloor:
return AssignEnvironment(AssignPointerMap(DefineAsRegister(result)));
case kMathSqrt:
return DefineAsRegister(result);
case kMathRound:
return AssignEnvironment(DefineAsRegister(result));
default:
UNREACHABLE();
return NULL;
}
}
} }

View File

@ -133,9 +133,18 @@ class LCodeGen;
V(LoadNamedFieldPolymorphic) \ V(LoadNamedFieldPolymorphic) \
V(LoadNamedGeneric) \ V(LoadNamedGeneric) \
V(MapEnumLength) \ V(MapEnumLength) \
V(MathAbs) \
V(MathCos) \
V(MathExp) \ V(MathExp) \
V(MathFloor) \
V(MathFloorOfDiv) \ V(MathFloorOfDiv) \
V(MathLog) \
V(MathMinMax) \ V(MathMinMax) \
V(MathPowHalf) \
V(MathRound) \
V(MathSin) \
V(MathSqrt) \
V(MathTan) \
V(ModI) \ V(ModI) \
V(MulI) \ V(MulI) \
V(MultiplyAddD) \ V(MultiplyAddD) \
@ -180,7 +189,6 @@ class LCodeGen;
V(TrapAllocationMemento) \ V(TrapAllocationMemento) \
V(Typeof) \ V(Typeof) \
V(TypeofIsAndBranch) \ V(TypeofIsAndBranch) \
V(UnaryMathOperation) \
V(UnknownOSRValue) \ V(UnknownOSRValue) \
V(ValueOf) \ V(ValueOf) \
V(ForInPrepareMap) \ V(ForInPrepareMap) \
@ -702,9 +710,22 @@ class LCmpIDAndBranch: public LControlInstruction<2, 0> {
}; };
class LUnaryMathOperation: public LTemplateInstruction<1, 1, 1> { class LMathFloor: public LTemplateInstruction<1, 1, 0> {
public: public:
LUnaryMathOperation(LOperand* value, LOperand* temp) { explicit LMathFloor(LOperand* value) {
inputs_[0] = value;
}
LOperand* value() { return inputs_[0]; }
DECLARE_CONCRETE_INSTRUCTION(MathFloor, "math-floor")
DECLARE_HYDROGEN_ACCESSOR(UnaryMathOperation)
};
class LMathRound: public LTemplateInstruction<1, 1, 1> {
public:
LMathRound(LOperand* value, LOperand* temp) {
inputs_[0] = value; inputs_[0] = value;
temps_[0] = temp; temps_[0] = temp;
} }
@ -712,11 +733,69 @@ class LUnaryMathOperation: public LTemplateInstruction<1, 1, 1> {
LOperand* value() { return inputs_[0]; } LOperand* value() { return inputs_[0]; }
LOperand* temp() { return temps_[0]; } LOperand* temp() { return temps_[0]; }
DECLARE_CONCRETE_INSTRUCTION(UnaryMathOperation, "unary-math-operation") DECLARE_CONCRETE_INSTRUCTION(MathRound, "math-round")
DECLARE_HYDROGEN_ACCESSOR(UnaryMathOperation) DECLARE_HYDROGEN_ACCESSOR(UnaryMathOperation)
};
virtual void PrintDataTo(StringStream* stream);
BuiltinFunctionId op() const { return hydrogen()->op(); } class LMathAbs: public LTemplateInstruction<1, 1, 0> {
public:
explicit LMathAbs(LOperand* value) {
inputs_[0] = value;
}
LOperand* value() { return inputs_[0]; }
DECLARE_CONCRETE_INSTRUCTION(MathAbs, "math-abs")
DECLARE_HYDROGEN_ACCESSOR(UnaryMathOperation)
};
class LMathLog: public LTemplateInstruction<1, 1, 0> {
public:
explicit LMathLog(LOperand* value) {
inputs_[0] = value;
}
LOperand* value() { return inputs_[0]; }
DECLARE_CONCRETE_INSTRUCTION(MathLog, "math-log")
};
class LMathSin: public LTemplateInstruction<1, 1, 0> {
public:
explicit LMathSin(LOperand* value) {
inputs_[0] = value;
}
LOperand* value() { return inputs_[0]; }
DECLARE_CONCRETE_INSTRUCTION(MathSin, "math-sin")
};
class LMathCos: public LTemplateInstruction<1, 1, 0> {
public:
explicit LMathCos(LOperand* value) {
inputs_[0] = value;
}
LOperand* value() { return inputs_[0]; }
DECLARE_CONCRETE_INSTRUCTION(MathCos, "math-cos")
};
class LMathTan: public LTemplateInstruction<1, 1, 0> {
public:
explicit LMathTan(LOperand* value) {
inputs_[0] = value;
}
LOperand* value() { return inputs_[0]; }
DECLARE_CONCRETE_INSTRUCTION(MathTan, "math-tan")
}; };
@ -739,8 +818,32 @@ class LMathExp: public LTemplateInstruction<1, 1, 3> {
LOperand* double_temp() { return temps_[2]; } LOperand* double_temp() { return temps_[2]; }
DECLARE_CONCRETE_INSTRUCTION(MathExp, "math-exp") DECLARE_CONCRETE_INSTRUCTION(MathExp, "math-exp")
};
virtual void PrintDataTo(StringStream* stream);
class LMathSqrt: public LTemplateInstruction<1, 1, 0> {
public:
explicit LMathSqrt(LOperand* value) {
inputs_[0] = value;
}
LOperand* value() { return inputs_[0]; }
DECLARE_CONCRETE_INSTRUCTION(MathSqrt, "math-sqrt")
};
class LMathPowHalf: public LTemplateInstruction<1, 1, 1> {
public:
LMathPowHalf(LOperand* value, LOperand* temp) {
inputs_[0] = value;
temps_[0] = temp;
}
LOperand* value() { return inputs_[0]; }
LOperand* temp() { return temps_[0]; }
DECLARE_CONCRETE_INSTRUCTION(MathPowHalf, "math-pow-half")
}; };
@ -1309,7 +1412,7 @@ class LMathMinMax: public LTemplateInstruction<1, 2, 0> {
LOperand* left() { return inputs_[0]; } LOperand* left() { return inputs_[0]; }
LOperand* right() { return inputs_[1]; } LOperand* right() { return inputs_[1]; }
DECLARE_CONCRETE_INSTRUCTION(MathMinMax, "min-max") DECLARE_CONCRETE_INSTRUCTION(MathMinMax, "math-min-max")
DECLARE_HYDROGEN_ACCESSOR(MathMinMax) DECLARE_HYDROGEN_ACCESSOR(MathMinMax)
}; };
@ -2603,6 +2706,17 @@ class LChunkBuilder BASE_EMBEDDED {
static HValue* SimplifiedDividendForMathFloorOfDiv(HValue* val); static HValue* SimplifiedDividendForMathFloorOfDiv(HValue* val);
static HValue* SimplifiedDivisorForMathFloorOfDiv(HValue* val); static HValue* SimplifiedDivisorForMathFloorOfDiv(HValue* val);
LInstruction* DoMathFloor(HUnaryMathOperation* instr);
LInstruction* DoMathRound(HUnaryMathOperation* instr);
LInstruction* DoMathAbs(HUnaryMathOperation* instr);
LInstruction* DoMathLog(HUnaryMathOperation* instr);
LInstruction* DoMathSin(HUnaryMathOperation* instr);
LInstruction* DoMathCos(HUnaryMathOperation* instr);
LInstruction* DoMathTan(HUnaryMathOperation* instr);
LInstruction* DoMathExp(HUnaryMathOperation* instr);
LInstruction* DoMathSqrt(HUnaryMathOperation* instr);
LInstruction* DoMathPowHalf(HUnaryMathOperation* instr);
private: private:
enum Status { enum Status {
UNUSED, UNUSED,

View File

@ -3754,7 +3754,7 @@ void LCodeGen::DoCallConstantFunction(LCallConstantFunction* instr) {
} }
void LCodeGen::DoDeferredMathAbsTaggedHeapNumber(LUnaryMathOperation* instr) { void LCodeGen::DoDeferredMathAbsTaggedHeapNumber(LMathAbs* instr) {
Register input = ToRegister(instr->value()); Register input = ToRegister(instr->value());
Register result = ToRegister(instr->result()); Register result = ToRegister(instr->result());
Register scratch = scratch0(); Register scratch = scratch0();
@ -3820,7 +3820,7 @@ void LCodeGen::DoDeferredMathAbsTaggedHeapNumber(LUnaryMathOperation* instr) {
} }
void LCodeGen::EmitIntegerMathAbs(LUnaryMathOperation* instr) { void LCodeGen::EmitIntegerMathAbs(LMathAbs* instr) {
Register input = ToRegister(instr->value()); Register input = ToRegister(instr->value());
Register result = ToRegister(instr->result()); Register result = ToRegister(instr->result());
__ cmp(input, Operand::Zero()); __ cmp(input, Operand::Zero());
@ -3834,19 +3834,18 @@ void LCodeGen::EmitIntegerMathAbs(LUnaryMathOperation* instr) {
} }
void LCodeGen::DoMathAbs(LUnaryMathOperation* instr) { void LCodeGen::DoMathAbs(LMathAbs* instr) {
// Class for deferred case. // Class for deferred case.
class DeferredMathAbsTaggedHeapNumber: public LDeferredCode { class DeferredMathAbsTaggedHeapNumber: public LDeferredCode {
public: public:
DeferredMathAbsTaggedHeapNumber(LCodeGen* codegen, DeferredMathAbsTaggedHeapNumber(LCodeGen* codegen, LMathAbs* instr)
LUnaryMathOperation* instr)
: LDeferredCode(codegen), instr_(instr) { } : LDeferredCode(codegen), instr_(instr) { }
virtual void Generate() { virtual void Generate() {
codegen()->DoDeferredMathAbsTaggedHeapNumber(instr_); codegen()->DoDeferredMathAbsTaggedHeapNumber(instr_);
} }
virtual LInstruction* instr() { return instr_; } virtual LInstruction* instr() { return instr_; }
private: private:
LUnaryMathOperation* instr_; LMathAbs* instr_;
}; };
Representation r = instr->hydrogen()->value()->representation(); Representation r = instr->hydrogen()->value()->representation();
@ -3870,7 +3869,7 @@ void LCodeGen::DoMathAbs(LUnaryMathOperation* instr) {
} }
void LCodeGen::DoMathFloor(LUnaryMathOperation* instr) { void LCodeGen::DoMathFloor(LMathFloor* instr) {
DwVfpRegister input = ToDoubleRegister(instr->value()); DwVfpRegister input = ToDoubleRegister(instr->value());
Register result = ToRegister(instr->result()); Register result = ToRegister(instr->result());
Register input_high = scratch0(); Register input_high = scratch0();
@ -3892,7 +3891,7 @@ void LCodeGen::DoMathFloor(LUnaryMathOperation* instr) {
} }
void LCodeGen::DoMathRound(LUnaryMathOperation* instr) { void LCodeGen::DoMathRound(LMathRound* instr) {
DwVfpRegister input = ToDoubleRegister(instr->value()); DwVfpRegister input = ToDoubleRegister(instr->value());
Register result = ToRegister(instr->result()); Register result = ToRegister(instr->result());
DwVfpRegister double_scratch1 = ToDoubleRegister(instr->temp()); DwVfpRegister double_scratch1 = ToDoubleRegister(instr->temp());
@ -3931,14 +3930,14 @@ void LCodeGen::DoMathRound(LUnaryMathOperation* instr) {
} }
void LCodeGen::DoMathSqrt(LUnaryMathOperation* instr) { void LCodeGen::DoMathSqrt(LMathSqrt* instr) {
DwVfpRegister input = ToDoubleRegister(instr->value()); DwVfpRegister input = ToDoubleRegister(instr->value());
DwVfpRegister result = ToDoubleRegister(instr->result()); DwVfpRegister result = ToDoubleRegister(instr->result());
__ vsqrt(result, input); __ vsqrt(result, input);
} }
void LCodeGen::DoMathPowHalf(LUnaryMathOperation* instr) { void LCodeGen::DoMathPowHalf(LMathPowHalf* instr) {
DwVfpRegister input = ToDoubleRegister(instr->value()); DwVfpRegister input = ToDoubleRegister(instr->value());
DwVfpRegister result = ToDoubleRegister(instr->result()); DwVfpRegister result = ToDoubleRegister(instr->result());
DwVfpRegister temp = ToDoubleRegister(instr->temp()); DwVfpRegister temp = ToDoubleRegister(instr->temp());
@ -4083,7 +4082,7 @@ void LCodeGen::DoMathExp(LMathExp* instr) {
} }
void LCodeGen::DoMathLog(LUnaryMathOperation* instr) { void LCodeGen::DoMathLog(LMathLog* instr) {
ASSERT(ToDoubleRegister(instr->result()).is(d2)); ASSERT(ToDoubleRegister(instr->result()).is(d2));
TranscendentalCacheStub stub(TranscendentalCache::LOG, TranscendentalCacheStub stub(TranscendentalCache::LOG,
TranscendentalCacheStub::UNTAGGED); TranscendentalCacheStub::UNTAGGED);
@ -4091,7 +4090,7 @@ void LCodeGen::DoMathLog(LUnaryMathOperation* instr) {
} }
void LCodeGen::DoMathTan(LUnaryMathOperation* instr) { void LCodeGen::DoMathTan(LMathTan* instr) {
ASSERT(ToDoubleRegister(instr->result()).is(d2)); ASSERT(ToDoubleRegister(instr->result()).is(d2));
TranscendentalCacheStub stub(TranscendentalCache::TAN, TranscendentalCacheStub stub(TranscendentalCache::TAN,
TranscendentalCacheStub::UNTAGGED); TranscendentalCacheStub::UNTAGGED);
@ -4099,7 +4098,7 @@ void LCodeGen::DoMathTan(LUnaryMathOperation* instr) {
} }
void LCodeGen::DoMathCos(LUnaryMathOperation* instr) { void LCodeGen::DoMathCos(LMathCos* instr) {
ASSERT(ToDoubleRegister(instr->result()).is(d2)); ASSERT(ToDoubleRegister(instr->result()).is(d2));
TranscendentalCacheStub stub(TranscendentalCache::COS, TranscendentalCacheStub stub(TranscendentalCache::COS,
TranscendentalCacheStub::UNTAGGED); TranscendentalCacheStub::UNTAGGED);
@ -4107,7 +4106,7 @@ void LCodeGen::DoMathCos(LUnaryMathOperation* instr) {
} }
void LCodeGen::DoMathSin(LUnaryMathOperation* instr) { void LCodeGen::DoMathSin(LMathSin* instr) {
ASSERT(ToDoubleRegister(instr->result()).is(d2)); ASSERT(ToDoubleRegister(instr->result()).is(d2));
TranscendentalCacheStub stub(TranscendentalCache::SIN, TranscendentalCacheStub stub(TranscendentalCache::SIN,
TranscendentalCacheStub::UNTAGGED); TranscendentalCacheStub::UNTAGGED);
@ -4115,42 +4114,6 @@ void LCodeGen::DoMathSin(LUnaryMathOperation* instr) {
} }
void LCodeGen::DoUnaryMathOperation(LUnaryMathOperation* instr) {
switch (instr->op()) {
case kMathAbs:
DoMathAbs(instr);
break;
case kMathFloor:
DoMathFloor(instr);
break;
case kMathRound:
DoMathRound(instr);
break;
case kMathSqrt:
DoMathSqrt(instr);
break;
case kMathPowHalf:
DoMathPowHalf(instr);
break;
case kMathCos:
DoMathCos(instr);
break;
case kMathSin:
DoMathSin(instr);
break;
case kMathTan:
DoMathTan(instr);
break;
case kMathLog:
DoMathLog(instr);
break;
default:
Abort("Unimplemented type of LUnaryMathOperation.");
UNREACHABLE();
}
}
void LCodeGen::DoInvokeFunction(LInvokeFunction* instr) { void LCodeGen::DoInvokeFunction(LInvokeFunction* instr) {
ASSERT(ToRegister(instr->function()).is(r1)); ASSERT(ToRegister(instr->function()).is(r1));
ASSERT(instr->HasPointerMap()); ASSERT(instr->HasPointerMap());

View File

@ -137,7 +137,7 @@ class LCodeGen BASE_EMBEDDED {
IntegerSignedness signedness); IntegerSignedness signedness);
void DoDeferredTaggedToI(LTaggedToI* instr); void DoDeferredTaggedToI(LTaggedToI* instr);
void DoDeferredMathAbsTaggedHeapNumber(LUnaryMathOperation* instr); void DoDeferredMathAbsTaggedHeapNumber(LMathAbs* instr);
void DoDeferredStackCheck(LStackCheck* instr); void DoDeferredStackCheck(LStackCheck* instr);
void DoDeferredRandom(LRandom* instr); void DoDeferredRandom(LRandom* instr);
void DoDeferredStringCharCodeAt(LStringCharCodeAt* instr); void DoDeferredStringCharCodeAt(LStringCharCodeAt* instr);
@ -294,17 +294,7 @@ class LCodeGen BASE_EMBEDDED {
Register ToRegister(int index) const; Register ToRegister(int index) const;
DwVfpRegister ToDoubleRegister(int index) const; DwVfpRegister ToDoubleRegister(int index) const;
// Specific math operations - used from DoUnaryMathOperation. void EmitIntegerMathAbs(LMathAbs* instr);
void EmitIntegerMathAbs(LUnaryMathOperation* instr);
void DoMathAbs(LUnaryMathOperation* instr);
void DoMathFloor(LUnaryMathOperation* instr);
void DoMathRound(LUnaryMathOperation* instr);
void DoMathSqrt(LUnaryMathOperation* instr);
void DoMathPowHalf(LUnaryMathOperation* instr);
void DoMathLog(LUnaryMathOperation* instr);
void DoMathTan(LUnaryMathOperation* instr);
void DoMathCos(LUnaryMathOperation* instr);
void DoMathSin(LUnaryMathOperation* instr);
// Support for recording safepoint and position information. // Support for recording safepoint and position information.
void RecordSafepoint(LPointerMap* pointers, void RecordSafepoint(LPointerMap* pointers,

View File

@ -3645,7 +3645,7 @@ void LCodeGen::DoCallConstantFunction(LCallConstantFunction* instr) {
} }
void LCodeGen::DoDeferredMathAbsTaggedHeapNumber(LUnaryMathOperation* instr) { void LCodeGen::DoDeferredMathAbsTaggedHeapNumber(LMathAbs* instr) {
Register input_reg = ToRegister(instr->value()); Register input_reg = ToRegister(instr->value());
__ cmp(FieldOperand(input_reg, HeapObject::kMapOffset), __ cmp(FieldOperand(input_reg, HeapObject::kMapOffset),
factory()->heap_number_map()); factory()->heap_number_map());
@ -3698,7 +3698,7 @@ void LCodeGen::DoDeferredMathAbsTaggedHeapNumber(LUnaryMathOperation* instr) {
} }
void LCodeGen::EmitIntegerMathAbs(LUnaryMathOperation* instr) { void LCodeGen::EmitIntegerMathAbs(LMathAbs* instr) {
Register input_reg = ToRegister(instr->value()); Register input_reg = ToRegister(instr->value());
__ test(input_reg, Operand(input_reg)); __ test(input_reg, Operand(input_reg));
Label is_positive; Label is_positive;
@ -3710,19 +3710,18 @@ void LCodeGen::EmitIntegerMathAbs(LUnaryMathOperation* instr) {
} }
void LCodeGen::DoMathAbs(LUnaryMathOperation* instr) { void LCodeGen::DoMathAbs(LMathAbs* instr) {
// Class for deferred case. // Class for deferred case.
class DeferredMathAbsTaggedHeapNumber: public LDeferredCode { class DeferredMathAbsTaggedHeapNumber: public LDeferredCode {
public: public:
DeferredMathAbsTaggedHeapNumber(LCodeGen* codegen, DeferredMathAbsTaggedHeapNumber(LCodeGen* codegen, LMathAbs* instr)
LUnaryMathOperation* instr)
: LDeferredCode(codegen), instr_(instr) { } : LDeferredCode(codegen), instr_(instr) { }
virtual void Generate() { virtual void Generate() {
codegen()->DoDeferredMathAbsTaggedHeapNumber(instr_); codegen()->DoDeferredMathAbsTaggedHeapNumber(instr_);
} }
virtual LInstruction* instr() { return instr_; } virtual LInstruction* instr() { return instr_; }
private: private:
LUnaryMathOperation* instr_; LMathAbs* instr_;
}; };
ASSERT(instr->value()->Equals(instr->result())); ASSERT(instr->value()->Equals(instr->result()));
@ -3749,7 +3748,7 @@ void LCodeGen::DoMathAbs(LUnaryMathOperation* instr) {
} }
void LCodeGen::DoMathFloor(LUnaryMathOperation* instr) { void LCodeGen::DoMathFloor(LMathFloor* instr) {
CpuFeatureScope scope(masm(), SSE2); CpuFeatureScope scope(masm(), SSE2);
XMMRegister xmm_scratch = xmm0; XMMRegister xmm_scratch = xmm0;
Register output_reg = ToRegister(instr->result()); Register output_reg = ToRegister(instr->result());
@ -3875,7 +3874,7 @@ void LCodeGen::DoMathRound(LMathRound* instr) {
} }
void LCodeGen::DoMathSqrt(LUnaryMathOperation* instr) { void LCodeGen::DoMathSqrt(LMathSqrt* instr) {
CpuFeatureScope scope(masm(), SSE2); CpuFeatureScope scope(masm(), SSE2);
XMMRegister input_reg = ToDoubleRegister(instr->value()); XMMRegister input_reg = ToDoubleRegister(instr->value());
ASSERT(ToDoubleRegister(instr->result()).is(input_reg)); ASSERT(ToDoubleRegister(instr->result()).is(input_reg));
@ -4028,7 +4027,7 @@ void LCodeGen::DoDeferredRandom(LRandom* instr) {
} }
void LCodeGen::DoMathLog(LUnaryMathOperation* instr) { void LCodeGen::DoMathLog(LMathLog* instr) {
CpuFeatureScope scope(masm(), SSE2); CpuFeatureScope scope(masm(), SSE2);
ASSERT(instr->value()->Equals(instr->result())); ASSERT(instr->value()->Equals(instr->result()));
XMMRegister input_reg = ToDoubleRegister(instr->value()); XMMRegister input_reg = ToDoubleRegister(instr->value());
@ -4071,7 +4070,7 @@ void LCodeGen::DoMathExp(LMathExp* instr) {
} }
void LCodeGen::DoMathTan(LUnaryMathOperation* instr) { void LCodeGen::DoMathTan(LMathTan* instr) {
ASSERT(ToDoubleRegister(instr->result()).is(xmm1)); ASSERT(ToDoubleRegister(instr->result()).is(xmm1));
TranscendentalCacheStub stub(TranscendentalCache::TAN, TranscendentalCacheStub stub(TranscendentalCache::TAN,
TranscendentalCacheStub::UNTAGGED); TranscendentalCacheStub::UNTAGGED);
@ -4079,7 +4078,7 @@ void LCodeGen::DoMathTan(LUnaryMathOperation* instr) {
} }
void LCodeGen::DoMathCos(LUnaryMathOperation* instr) { void LCodeGen::DoMathCos(LMathCos* instr) {
ASSERT(ToDoubleRegister(instr->result()).is(xmm1)); ASSERT(ToDoubleRegister(instr->result()).is(xmm1));
TranscendentalCacheStub stub(TranscendentalCache::COS, TranscendentalCacheStub stub(TranscendentalCache::COS,
TranscendentalCacheStub::UNTAGGED); TranscendentalCacheStub::UNTAGGED);
@ -4087,7 +4086,7 @@ void LCodeGen::DoMathCos(LUnaryMathOperation* instr) {
} }
void LCodeGen::DoMathSin(LUnaryMathOperation* instr) { void LCodeGen::DoMathSin(LMathSin* instr) {
ASSERT(ToDoubleRegister(instr->result()).is(xmm1)); ASSERT(ToDoubleRegister(instr->result()).is(xmm1));
TranscendentalCacheStub stub(TranscendentalCache::SIN, TranscendentalCacheStub stub(TranscendentalCache::SIN,
TranscendentalCacheStub::UNTAGGED); TranscendentalCacheStub::UNTAGGED);
@ -4095,36 +4094,6 @@ void LCodeGen::DoMathSin(LUnaryMathOperation* instr) {
} }
void LCodeGen::DoUnaryMathOperation(LUnaryMathOperation* instr) {
switch (instr->op()) {
case kMathAbs:
DoMathAbs(instr);
break;
case kMathFloor:
DoMathFloor(instr);
break;
case kMathSqrt:
DoMathSqrt(instr);
break;
case kMathCos:
DoMathCos(instr);
break;
case kMathSin:
DoMathSin(instr);
break;
case kMathTan:
DoMathTan(instr);
break;
case kMathLog:
DoMathLog(instr);
break;
default:
UNREACHABLE();
}
}
void LCodeGen::DoInvokeFunction(LInvokeFunction* instr) { void LCodeGen::DoInvokeFunction(LInvokeFunction* instr) {
ASSERT(ToRegister(instr->context()).is(esi)); ASSERT(ToRegister(instr->context()).is(esi));
ASSERT(ToRegister(instr->function()).is(edi)); ASSERT(ToRegister(instr->function()).is(edi));

View File

@ -138,7 +138,7 @@ class LCodeGen BASE_EMBEDDED {
void DoDeferredTaggedToI(LTaggedToI* instr); void DoDeferredTaggedToI(LTaggedToI* instr);
void DoDeferredTaggedToINoSSE2(LTaggedToINoSSE2* instr); void DoDeferredTaggedToINoSSE2(LTaggedToINoSSE2* instr);
void DoDeferredMathAbsTaggedHeapNumber(LUnaryMathOperation* instr); void DoDeferredMathAbsTaggedHeapNumber(LMathAbs* instr);
void DoDeferredStackCheck(LStackCheck* instr); void DoDeferredStackCheck(LStackCheck* instr);
void DoDeferredRandom(LRandom* instr); void DoDeferredRandom(LRandom* instr);
void DoDeferredStringCharCodeAt(LStringCharCodeAt* instr); void DoDeferredStringCharCodeAt(LStringCharCodeAt* instr);
@ -290,15 +290,7 @@ class LCodeGen BASE_EMBEDDED {
uint32_t offset, uint32_t offset,
uint32_t additional_index = 0); uint32_t additional_index = 0);
// Specific math operations - used from DoUnaryMathOperation. void EmitIntegerMathAbs(LMathAbs* instr);
void EmitIntegerMathAbs(LUnaryMathOperation* instr);
void DoMathAbs(LUnaryMathOperation* instr);
void DoMathFloor(LUnaryMathOperation* instr);
void DoMathSqrt(LUnaryMathOperation* instr);
void DoMathLog(LUnaryMathOperation* instr);
void DoMathTan(LUnaryMathOperation* instr);
void DoMathCos(LUnaryMathOperation* instr);
void DoMathSin(LUnaryMathOperation* instr);
// Support for recording safepoint and position information. // Support for recording safepoint and position information.
void RecordSafepoint(LPointerMap* pointers, void RecordSafepoint(LPointerMap* pointers,

View File

@ -320,29 +320,6 @@ void LCallConstantFunction::PrintDataTo(StringStream* stream) {
} }
void LUnaryMathOperation::PrintDataTo(StringStream* stream) {
stream->Add("/%s ", hydrogen()->OpName());
value()->PrintTo(stream);
}
void LMathExp::PrintDataTo(StringStream* stream) {
value()->PrintTo(stream);
}
void LMathPowHalf::PrintDataTo(StringStream* stream) {
stream->Add("/pow_half ");
value()->PrintTo(stream);
}
void LMathRound::PrintDataTo(StringStream* stream) {
stream->Add("/round ");
value()->PrintTo(stream);
}
void LLoadContextSlot::PrintDataTo(StringStream* stream) { void LLoadContextSlot::PrintDataTo(StringStream* stream) {
context()->PrintTo(stream); context()->PrintTo(stream);
stream->Add("[%d]", slot_index()); stream->Add("[%d]", slot_index());
@ -1208,16 +1185,79 @@ LInstruction* LChunkBuilder::DoInvokeFunction(HInvokeFunction* instr) {
LInstruction* LChunkBuilder::DoUnaryMathOperation(HUnaryMathOperation* instr) { LInstruction* LChunkBuilder::DoUnaryMathOperation(HUnaryMathOperation* instr) {
BuiltinFunctionId op = instr->op(); switch (instr->op()) {
if (op == kMathLog) { case kMathFloor: return DoMathFloor(instr);
case kMathRound: return DoMathRound(instr);
case kMathAbs: return DoMathAbs(instr);
case kMathLog: return DoMathLog(instr);
case kMathSin: return DoMathSin(instr);
case kMathCos: return DoMathCos(instr);
case kMathTan: return DoMathTan(instr);
case kMathExp: return DoMathExp(instr);
case kMathSqrt: return DoMathSqrt(instr);
case kMathPowHalf: return DoMathPowHalf(instr);
default:
UNREACHABLE();
return NULL;
}
}
LInstruction* LChunkBuilder::DoMathFloor(HUnaryMathOperation* instr) {
LOperand* input = UseRegisterAtStart(instr->value());
LMathFloor* result = new(zone()) LMathFloor(input);
return AssignEnvironment(DefineAsRegister(result));
}
LInstruction* LChunkBuilder::DoMathRound(HUnaryMathOperation* instr) {
LOperand* context = UseAny(instr->context());
LOperand* input = UseRegister(instr->value());
LOperand* temp = FixedTemp(xmm4);
LMathRound* result = new(zone()) LMathRound(context, input, temp);
return AssignEnvironment(DefineAsRegister(result));
}
LInstruction* LChunkBuilder::DoMathAbs(HUnaryMathOperation* instr) {
LOperand* context = UseAny(instr->context()); // Deferred use.
LOperand* input = UseRegisterAtStart(instr->value());
LMathAbs* result = new(zone()) LMathAbs(context, input);
return AssignEnvironment(AssignPointerMap(DefineSameAsFirst(result)));
}
LInstruction* LChunkBuilder::DoMathLog(HUnaryMathOperation* instr) {
ASSERT(instr->representation().IsDouble()); ASSERT(instr->representation().IsDouble());
ASSERT(instr->value()->representation().IsDouble()); ASSERT(instr->value()->representation().IsDouble());
LOperand* context = UseAny(instr->context()); // Not actually used.
LOperand* input = UseRegisterAtStart(instr->value()); LOperand* input = UseRegisterAtStart(instr->value());
LUnaryMathOperation* result = new(zone()) LUnaryMathOperation(context, LMathLog* result = new(zone()) LMathLog(input);
input);
return DefineSameAsFirst(result); return DefineSameAsFirst(result);
} else if (op == kMathExp) { }
LInstruction* LChunkBuilder::DoMathSin(HUnaryMathOperation* instr) {
LOperand* input = UseFixedDouble(instr->value(), xmm1);
LMathSin* result = new(zone()) LMathSin(input);
return MarkAsCall(DefineFixedDouble(result, xmm1), instr);
}
LInstruction* LChunkBuilder::DoMathCos(HUnaryMathOperation* instr) {
LOperand* input = UseFixedDouble(instr->value(), xmm1);
LMathCos* result = new(zone()) LMathCos(input);
return MarkAsCall(DefineFixedDouble(result, xmm1), instr);
}
LInstruction* LChunkBuilder::DoMathTan(HUnaryMathOperation* instr) {
LOperand* input = UseFixedDouble(instr->value(), xmm1);
LMathTan* result = new(zone()) LMathTan(input);
return MarkAsCall(DefineFixedDouble(result, xmm1), instr);
}
LInstruction* LChunkBuilder::DoMathExp(HUnaryMathOperation* instr) {
ASSERT(instr->representation().IsDouble()); ASSERT(instr->representation().IsDouble());
ASSERT(instr->value()->representation().IsDouble()); ASSERT(instr->value()->representation().IsDouble());
LOperand* value = UseTempRegister(instr->value()); LOperand* value = UseTempRegister(instr->value());
@ -1225,42 +1265,22 @@ LInstruction* LChunkBuilder::DoUnaryMathOperation(HUnaryMathOperation* instr) {
LOperand* temp2 = TempRegister(); LOperand* temp2 = TempRegister();
LMathExp* result = new(zone()) LMathExp(value, temp1, temp2); LMathExp* result = new(zone()) LMathExp(value, temp1, temp2);
return DefineAsRegister(result); return DefineAsRegister(result);
} else if (op == kMathSin || op == kMathCos || op == kMathTan) { }
LOperand* context = UseFixed(instr->context(), esi);
LOperand* input = UseFixedDouble(instr->value(), xmm1);
LUnaryMathOperation* result = new(zone()) LUnaryMathOperation(context, LInstruction* LChunkBuilder::DoMathSqrt(HUnaryMathOperation* instr) {
input); LOperand* input = UseRegisterAtStart(instr->value());
return MarkAsCall(DefineFixedDouble(result, xmm1), instr); LMathSqrt* result = new(zone()) LMathSqrt(input);
} else { return DefineSameAsFirst(result);
LOperand* context = UseAny(instr->context()); // Deferred use by MathAbs. }
LOperand* input = NULL;
if (op == kMathPowHalf) {
input = UseRegisterAtStart(instr->value()); LInstruction* LChunkBuilder::DoMathPowHalf(HUnaryMathOperation* instr) {
LOperand* context = UseAny(instr->context());
LOperand* input = UseRegisterAtStart(instr->value());
LOperand* temp = TempRegister(); LOperand* temp = TempRegister();
LMathPowHalf* result = new(zone()) LMathPowHalf(context, input, temp); LMathPowHalf* result = new(zone()) LMathPowHalf(context, input, temp);
return DefineSameAsFirst(result); return DefineSameAsFirst(result);
} else if (op == kMathRound) {
input = UseRegister(instr->value());
LOperand* temp = FixedTemp(xmm4);
LMathRound* result = new(zone()) LMathRound(context, input, temp);
return AssignEnvironment(DefineAsRegister(result));
} else {
input = UseRegisterAtStart(instr->value());
}
LUnaryMathOperation* result = new(zone()) LUnaryMathOperation(context,
input);
switch (op) {
case kMathAbs:
return AssignEnvironment(AssignPointerMap(DefineSameAsFirst(result)));
case kMathFloor:
return AssignEnvironment(DefineAsRegister(result));
case kMathSqrt:
return DefineSameAsFirst(result);
default:
UNREACHABLE();
return NULL;
}
}
} }

View File

@ -128,11 +128,18 @@ class LCodeGen;
V(LoadNamedFieldPolymorphic) \ V(LoadNamedFieldPolymorphic) \
V(LoadNamedGeneric) \ V(LoadNamedGeneric) \
V(MapEnumLength) \ V(MapEnumLength) \
V(MathAbs) \
V(MathCos) \
V(MathExp) \ V(MathExp) \
V(MathFloor) \
V(MathFloorOfDiv) \ V(MathFloorOfDiv) \
V(MathLog) \
V(MathMinMax) \ V(MathMinMax) \
V(MathPowHalf) \ V(MathPowHalf) \
V(MathRound) \ V(MathRound) \
V(MathSin) \
V(MathSqrt) \
V(MathTan) \
V(ModI) \ V(ModI) \
V(MulI) \ V(MulI) \
V(NumberTagD) \ V(NumberTagD) \
@ -175,7 +182,6 @@ class LCodeGen;
V(TrapAllocationMemento) \ V(TrapAllocationMemento) \
V(Typeof) \ V(Typeof) \
V(TypeofIsAndBranch) \ V(TypeofIsAndBranch) \
V(UnaryMathOperation) \
V(UnknownOSRValue) \ V(UnknownOSRValue) \
V(ValueOf) \ V(ValueOf) \
V(ForInPrepareMap) \ V(ForInPrepareMap) \
@ -649,9 +655,39 @@ class LCmpIDAndBranch: public LControlInstruction<2, 0> {
}; };
class LUnaryMathOperation: public LTemplateInstruction<1, 2, 0> { class LMathFloor: public LTemplateInstruction<1, 1, 0> {
public: public:
LUnaryMathOperation(LOperand* context, LOperand* value) { explicit LMathFloor(LOperand* value) {
inputs_[0] = value;
}
LOperand* value() { return inputs_[0]; }
DECLARE_CONCRETE_INSTRUCTION(MathFloor, "math-floor")
DECLARE_HYDROGEN_ACCESSOR(UnaryMathOperation)
};
class LMathRound: public LTemplateInstruction<1, 2, 1> {
public:
LMathRound(LOperand* context, LOperand* value, LOperand* temp) {
inputs_[1] = context;
inputs_[0] = value;
temps_[0] = temp;
}
LOperand* context() { return inputs_[1]; }
LOperand* value() { return inputs_[0]; }
LOperand* temp() { return temps_[0]; }
DECLARE_CONCRETE_INSTRUCTION(MathRound, "math-round")
DECLARE_HYDROGEN_ACCESSOR(UnaryMathOperation)
};
class LMathAbs: public LTemplateInstruction<1, 2, 0> {
public:
LMathAbs(LOperand* context, LOperand* value) {
inputs_[1] = context; inputs_[1] = context;
inputs_[0] = value; inputs_[0] = value;
} }
@ -659,11 +695,56 @@ class LUnaryMathOperation: public LTemplateInstruction<1, 2, 0> {
LOperand* context() { return inputs_[1]; } LOperand* context() { return inputs_[1]; }
LOperand* value() { return inputs_[0]; } LOperand* value() { return inputs_[0]; }
DECLARE_CONCRETE_INSTRUCTION(UnaryMathOperation, "unary-math-operation") DECLARE_CONCRETE_INSTRUCTION(MathAbs, "math-abs")
DECLARE_HYDROGEN_ACCESSOR(UnaryMathOperation) DECLARE_HYDROGEN_ACCESSOR(UnaryMathOperation)
};
virtual void PrintDataTo(StringStream* stream);
BuiltinFunctionId op() const { return hydrogen()->op(); } class LMathLog: public LTemplateInstruction<1, 1, 0> {
public:
explicit LMathLog(LOperand* value) {
inputs_[0] = value;
}
LOperand* value() { return inputs_[0]; }
DECLARE_CONCRETE_INSTRUCTION(MathLog, "math-log")
};
class LMathSin: public LTemplateInstruction<1, 1, 0> {
public:
explicit LMathSin(LOperand* value) {
inputs_[0] = value;
}
LOperand* value() { return inputs_[0]; }
DECLARE_CONCRETE_INSTRUCTION(MathSin, "math-sin")
};
class LMathCos: public LTemplateInstruction<1, 1, 0> {
public:
explicit LMathCos(LOperand* value) {
inputs_[0] = value;
}
LOperand* value() { return inputs_[0]; }
DECLARE_CONCRETE_INSTRUCTION(MathCos, "math-cos")
};
class LMathTan: public LTemplateInstruction<1, 1, 0> {
public:
explicit LMathTan(LOperand* value) {
inputs_[0] = value;
}
LOperand* value() { return inputs_[0]; }
DECLARE_CONCRETE_INSTRUCTION(MathTan, "math-tan")
}; };
@ -683,8 +764,18 @@ class LMathExp: public LTemplateInstruction<1, 1, 2> {
LOperand* temp2() { return temps_[1]; } LOperand* temp2() { return temps_[1]; }
DECLARE_CONCRETE_INSTRUCTION(MathExp, "math-exp") DECLARE_CONCRETE_INSTRUCTION(MathExp, "math-exp")
};
virtual void PrintDataTo(StringStream* stream);
class LMathSqrt: public LTemplateInstruction<1, 1, 0> {
public:
explicit LMathSqrt(LOperand* value) {
inputs_[0] = value;
}
LOperand* value() { return inputs_[0]; }
DECLARE_CONCRETE_INSTRUCTION(MathSqrt, "math-sqrt")
}; };
@ -701,27 +792,6 @@ class LMathPowHalf: public LTemplateInstruction<1, 2, 1> {
LOperand* temp() { return temps_[0]; } LOperand* temp() { return temps_[0]; }
DECLARE_CONCRETE_INSTRUCTION(MathPowHalf, "math-pow-half") DECLARE_CONCRETE_INSTRUCTION(MathPowHalf, "math-pow-half")
virtual void PrintDataTo(StringStream* stream);
};
class LMathRound: public LTemplateInstruction<1, 2, 1> {
public:
LMathRound(LOperand* context, LOperand* value, LOperand* temp) {
inputs_[1] = context;
inputs_[0] = value;
temps_[0] = temp;
}
LOperand* context() { return inputs_[1]; }
LOperand* value() { return inputs_[0]; }
LOperand* temp() { return temps_[0]; }
DECLARE_CONCRETE_INSTRUCTION(MathRound, "math-round")
DECLARE_HYDROGEN_ACCESSOR(UnaryMathOperation)
virtual void PrintDataTo(StringStream* stream);
}; };
@ -1304,7 +1374,7 @@ class LMathMinMax: public LTemplateInstruction<1, 2, 0> {
LOperand* left() { return inputs_[0]; } LOperand* left() { return inputs_[0]; }
LOperand* right() { return inputs_[1]; } LOperand* right() { return inputs_[1]; }
DECLARE_CONCRETE_INSTRUCTION(MathMinMax, "min-max") DECLARE_CONCRETE_INSTRUCTION(MathMinMax, "math-min-max")
DECLARE_HYDROGEN_ACCESSOR(MathMinMax) DECLARE_HYDROGEN_ACCESSOR(MathMinMax)
}; };
@ -2760,6 +2830,17 @@ class LChunkBuilder BASE_EMBEDDED {
static HValue* SimplifiedDividendForMathFloorOfDiv(HValue* val); static HValue* SimplifiedDividendForMathFloorOfDiv(HValue* val);
static HValue* SimplifiedDivisorForMathFloorOfDiv(HValue* val); static HValue* SimplifiedDivisorForMathFloorOfDiv(HValue* val);
LInstruction* DoMathFloor(HUnaryMathOperation* instr);
LInstruction* DoMathRound(HUnaryMathOperation* instr);
LInstruction* DoMathAbs(HUnaryMathOperation* instr);
LInstruction* DoMathLog(HUnaryMathOperation* instr);
LInstruction* DoMathSin(HUnaryMathOperation* instr);
LInstruction* DoMathCos(HUnaryMathOperation* instr);
LInstruction* DoMathTan(HUnaryMathOperation* instr);
LInstruction* DoMathExp(HUnaryMathOperation* instr);
LInstruction* DoMathSqrt(HUnaryMathOperation* instr);
LInstruction* DoMathPowHalf(HUnaryMathOperation* instr);
private: private:
enum Status { enum Status {
UNUSED, UNUSED,

View File

@ -3447,7 +3447,7 @@ void LCodeGen::DoCallConstantFunction(LCallConstantFunction* instr) {
} }
void LCodeGen::DoDeferredMathAbsTaggedHeapNumber(LUnaryMathOperation* instr) { void LCodeGen::DoDeferredMathAbsTaggedHeapNumber(LMathAbs* instr) {
Register input = ToRegister(instr->value()); Register input = ToRegister(instr->value());
Register result = ToRegister(instr->result()); Register result = ToRegister(instr->result());
Register scratch = scratch0(); Register scratch = scratch0();
@ -3512,7 +3512,7 @@ void LCodeGen::DoDeferredMathAbsTaggedHeapNumber(LUnaryMathOperation* instr) {
} }
void LCodeGen::EmitIntegerMathAbs(LUnaryMathOperation* instr) { void LCodeGen::EmitIntegerMathAbs(LMathAbs* instr) {
Register input = ToRegister(instr->value()); Register input = ToRegister(instr->value());
Register result = ToRegister(instr->result()); Register result = ToRegister(instr->result());
Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm_); Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm_);
@ -3525,20 +3525,19 @@ void LCodeGen::EmitIntegerMathAbs(LUnaryMathOperation* instr) {
} }
void LCodeGen::DoMathAbs(LUnaryMathOperation* instr) { void LCodeGen::DoMathAbs(LMathAbs* instr) {
CpuFeatureScope scope(masm(), FPU); CpuFeatureScope scope(masm(), FPU);
// Class for deferred case. // Class for deferred case.
class DeferredMathAbsTaggedHeapNumber: public LDeferredCode { class DeferredMathAbsTaggedHeapNumber: public LDeferredCode {
public: public:
DeferredMathAbsTaggedHeapNumber(LCodeGen* codegen, DeferredMathAbsTaggedHeapNumber(LCodeGen* codegen, LMathAbs* instr)
LUnaryMathOperation* instr)
: LDeferredCode(codegen), instr_(instr) { } : LDeferredCode(codegen), instr_(instr) { }
virtual void Generate() { virtual void Generate() {
codegen()->DoDeferredMathAbsTaggedHeapNumber(instr_); codegen()->DoDeferredMathAbsTaggedHeapNumber(instr_);
} }
virtual LInstruction* instr() { return instr_; } virtual LInstruction* instr() { return instr_; }
private: private:
LUnaryMathOperation* instr_; LMathAbs* instr_;
}; };
Representation r = instr->hydrogen()->value()->representation(); Representation r = instr->hydrogen()->value()->representation();
@ -3562,7 +3561,7 @@ void LCodeGen::DoMathAbs(LUnaryMathOperation* instr) {
} }
void LCodeGen::DoMathFloor(LUnaryMathOperation* instr) { void LCodeGen::DoMathFloor(LMathFloor* instr) {
CpuFeatureScope scope(masm(), FPU); CpuFeatureScope scope(masm(), FPU);
DoubleRegister input = ToDoubleRegister(instr->value()); DoubleRegister input = ToDoubleRegister(instr->value());
Register result = ToRegister(instr->result()); Register result = ToRegister(instr->result());
@ -3591,7 +3590,7 @@ void LCodeGen::DoMathFloor(LUnaryMathOperation* instr) {
} }
void LCodeGen::DoMathRound(LUnaryMathOperation* instr) { void LCodeGen::DoMathRound(LMathRound* instr) {
CpuFeatureScope scope(masm(), FPU); CpuFeatureScope scope(masm(), FPU);
DoubleRegister input = ToDoubleRegister(instr->value()); DoubleRegister input = ToDoubleRegister(instr->value());
Register result = ToRegister(instr->result()); Register result = ToRegister(instr->result());
@ -3668,7 +3667,7 @@ void LCodeGen::DoMathRound(LUnaryMathOperation* instr) {
} }
void LCodeGen::DoMathSqrt(LUnaryMathOperation* instr) { void LCodeGen::DoMathSqrt(LMathSqrt* instr) {
CpuFeatureScope scope(masm(), FPU); CpuFeatureScope scope(masm(), FPU);
DoubleRegister input = ToDoubleRegister(instr->value()); DoubleRegister input = ToDoubleRegister(instr->value());
DoubleRegister result = ToDoubleRegister(instr->result()); DoubleRegister result = ToDoubleRegister(instr->result());
@ -3676,7 +3675,7 @@ void LCodeGen::DoMathSqrt(LUnaryMathOperation* instr) {
} }
void LCodeGen::DoMathPowHalf(LUnaryMathOperation* instr) { void LCodeGen::DoMathPowHalf(LMathPowHalf* instr) {
CpuFeatureScope scope(masm(), FPU); CpuFeatureScope scope(masm(), FPU);
DoubleRegister input = ToDoubleRegister(instr->value()); DoubleRegister input = ToDoubleRegister(instr->value());
DoubleRegister result = ToDoubleRegister(instr->result()); DoubleRegister result = ToDoubleRegister(instr->result());
@ -3824,7 +3823,7 @@ void LCodeGen::DoMathExp(LMathExp* instr) {
} }
void LCodeGen::DoMathLog(LUnaryMathOperation* instr) { void LCodeGen::DoMathLog(LMathLog* instr) {
ASSERT(ToDoubleRegister(instr->result()).is(f4)); ASSERT(ToDoubleRegister(instr->result()).is(f4));
TranscendentalCacheStub stub(TranscendentalCache::LOG, TranscendentalCacheStub stub(TranscendentalCache::LOG,
TranscendentalCacheStub::UNTAGGED); TranscendentalCacheStub::UNTAGGED);
@ -3832,7 +3831,7 @@ void LCodeGen::DoMathLog(LUnaryMathOperation* instr) {
} }
void LCodeGen::DoMathTan(LUnaryMathOperation* instr) { void LCodeGen::DoMathTan(LMathTan* instr) {
ASSERT(ToDoubleRegister(instr->result()).is(f4)); ASSERT(ToDoubleRegister(instr->result()).is(f4));
TranscendentalCacheStub stub(TranscendentalCache::TAN, TranscendentalCacheStub stub(TranscendentalCache::TAN,
TranscendentalCacheStub::UNTAGGED); TranscendentalCacheStub::UNTAGGED);
@ -3840,7 +3839,7 @@ void LCodeGen::DoMathTan(LUnaryMathOperation* instr) {
} }
void LCodeGen::DoMathCos(LUnaryMathOperation* instr) { void LCodeGen::DoMathCos(LMathCos* instr) {
ASSERT(ToDoubleRegister(instr->result()).is(f4)); ASSERT(ToDoubleRegister(instr->result()).is(f4));
TranscendentalCacheStub stub(TranscendentalCache::COS, TranscendentalCacheStub stub(TranscendentalCache::COS,
TranscendentalCacheStub::UNTAGGED); TranscendentalCacheStub::UNTAGGED);
@ -3848,7 +3847,7 @@ void LCodeGen::DoMathCos(LUnaryMathOperation* instr) {
} }
void LCodeGen::DoMathSin(LUnaryMathOperation* instr) { void LCodeGen::DoMathSin(LMathSin* instr) {
ASSERT(ToDoubleRegister(instr->result()).is(f4)); ASSERT(ToDoubleRegister(instr->result()).is(f4));
TranscendentalCacheStub stub(TranscendentalCache::SIN, TranscendentalCacheStub stub(TranscendentalCache::SIN,
TranscendentalCacheStub::UNTAGGED); TranscendentalCacheStub::UNTAGGED);
@ -3856,42 +3855,6 @@ void LCodeGen::DoMathSin(LUnaryMathOperation* instr) {
} }
void LCodeGen::DoUnaryMathOperation(LUnaryMathOperation* instr) {
switch (instr->op()) {
case kMathAbs:
DoMathAbs(instr);
break;
case kMathFloor:
DoMathFloor(instr);
break;
case kMathRound:
DoMathRound(instr);
break;
case kMathSqrt:
DoMathSqrt(instr);
break;
case kMathPowHalf:
DoMathPowHalf(instr);
break;
case kMathCos:
DoMathCos(instr);
break;
case kMathSin:
DoMathSin(instr);
break;
case kMathTan:
DoMathTan(instr);
break;
case kMathLog:
DoMathLog(instr);
break;
default:
Abort("Unimplemented type of LUnaryMathOperation.");
UNREACHABLE();
}
}
void LCodeGen::DoInvokeFunction(LInvokeFunction* instr) { void LCodeGen::DoInvokeFunction(LInvokeFunction* instr) {
ASSERT(ToRegister(instr->function()).is(a1)); ASSERT(ToRegister(instr->function()).is(a1));
ASSERT(instr->HasPointerMap()); ASSERT(instr->HasPointerMap());

View File

@ -132,7 +132,7 @@ class LCodeGen BASE_EMBEDDED {
IntegerSignedness signedness); IntegerSignedness signedness);
void DoDeferredTaggedToI(LTaggedToI* instr); void DoDeferredTaggedToI(LTaggedToI* instr);
void DoDeferredMathAbsTaggedHeapNumber(LUnaryMathOperation* instr); void DoDeferredMathAbsTaggedHeapNumber(LMathAbs* instr);
void DoDeferredStackCheck(LStackCheck* instr); void DoDeferredStackCheck(LStackCheck* instr);
void DoDeferredRandom(LRandom* instr); void DoDeferredRandom(LRandom* instr);
void DoDeferredStringCharCodeAt(LStringCharCodeAt* instr); void DoDeferredStringCharCodeAt(LStringCharCodeAt* instr);
@ -289,17 +289,7 @@ class LCodeGen BASE_EMBEDDED {
Register ToRegister(int index) const; Register ToRegister(int index) const;
DoubleRegister ToDoubleRegister(int index) const; DoubleRegister ToDoubleRegister(int index) const;
// Specific math operations - used from DoUnaryMathOperation. void EmitIntegerMathAbs(LMathAbs* instr);
void EmitIntegerMathAbs(LUnaryMathOperation* instr);
void DoMathAbs(LUnaryMathOperation* instr);
void DoMathFloor(LUnaryMathOperation* instr);
void DoMathRound(LUnaryMathOperation* instr);
void DoMathSqrt(LUnaryMathOperation* instr);
void DoMathPowHalf(LUnaryMathOperation* instr);
void DoMathLog(LUnaryMathOperation* instr);
void DoMathTan(LUnaryMathOperation* instr);
void DoMathCos(LUnaryMathOperation* instr);
void DoMathSin(LUnaryMathOperation* instr);
// Support for recording safepoint and position information. // Support for recording safepoint and position information.
void RecordSafepoint(LPointerMap* pointers, void RecordSafepoint(LPointerMap* pointers,

View File

@ -302,17 +302,6 @@ void LCallConstantFunction::PrintDataTo(StringStream* stream) {
} }
void LUnaryMathOperation::PrintDataTo(StringStream* stream) {
stream->Add("/%s ", hydrogen()->OpName());
value()->PrintTo(stream);
}
void LMathExp::PrintDataTo(StringStream* stream) {
value()->PrintTo(stream);
}
void LLoadContextSlot::PrintDataTo(StringStream* stream) { void LLoadContextSlot::PrintDataTo(StringStream* stream) {
context()->PrintTo(stream); context()->PrintTo(stream);
stream->Add("[%d]", slot_index()); stream->Add("[%d]", slot_index());
@ -1123,12 +1112,53 @@ LInstruction* LChunkBuilder::DoInvokeFunction(HInvokeFunction* instr) {
LInstruction* LChunkBuilder::DoUnaryMathOperation(HUnaryMathOperation* instr) { LInstruction* LChunkBuilder::DoUnaryMathOperation(HUnaryMathOperation* instr) {
BuiltinFunctionId op = instr->op(); switch (instr->op()) {
if (op == kMathLog || op == kMathSin || op == kMathCos || op == kMathTan) { case kMathFloor: return DoMathFloor(instr);
case kMathRound: return DoMathRound(instr);
case kMathAbs: return DoMathAbs(instr);
case kMathLog: return DoMathLog(instr);
case kMathSin: return DoMathSin(instr);
case kMathCos: return DoMathCos(instr);
case kMathTan: return DoMathTan(instr);
case kMathExp: return DoMathExp(instr);
case kMathSqrt: return DoMathSqrt(instr);
case kMathPowHalf: return DoMathPowHalf(instr);
default:
UNREACHABLE();
return NULL;
}
}
LInstruction* LChunkBuilder::DoMathLog(HUnaryMathOperation* instr) {
LOperand* input = UseFixedDouble(instr->value(), f4); LOperand* input = UseFixedDouble(instr->value(), f4);
LUnaryMathOperation* result = new(zone()) LUnaryMathOperation(input, NULL); LMathLog* result = new(zone()) LMathLog(input);
return MarkAsCall(DefineFixedDouble(result, f4), instr); return MarkAsCall(DefineFixedDouble(result, f4), instr);
} else if (op == kMathExp) { }
LInstruction* LChunkBuilder::DoMathSin(HUnaryMathOperation* instr) {
LOperand* input = UseFixedDouble(instr->value(), f4);
LMathSin* result = new(zone()) LMathSin(input);
return MarkAsCall(DefineFixedDouble(result, f4), instr);
}
LInstruction* LChunkBuilder::DoMathCos(HUnaryMathOperation* instr) {
LOperand* input = UseFixedDouble(instr->value(), f4);
LMathCos* result = new(zone()) LMathCos(input);
return MarkAsCall(DefineFixedDouble(result, f4), instr);
}
LInstruction* LChunkBuilder::DoMathTan(HUnaryMathOperation* instr) {
LOperand* input = UseFixedDouble(instr->value(), f4);
LMathTan* result = new(zone()) LMathTan(input);
return MarkAsCall(DefineFixedDouble(result, f4), instr);
}
LInstruction* LChunkBuilder::DoMathExp(HUnaryMathOperation* instr) {
ASSERT(instr->representation().IsDouble()); ASSERT(instr->representation().IsDouble());
ASSERT(instr->value()->representation().IsDouble()); ASSERT(instr->value()->representation().IsDouble());
LOperand* input = UseTempRegister(instr->value()); LOperand* input = UseTempRegister(instr->value());
@ -1137,33 +1167,45 @@ LInstruction* LChunkBuilder::DoUnaryMathOperation(HUnaryMathOperation* instr) {
LOperand* double_temp = FixedTemp(f6); // Chosen by fair dice roll. LOperand* double_temp = FixedTemp(f6); // Chosen by fair dice roll.
LMathExp* result = new(zone()) LMathExp(input, double_temp, temp1, temp2); LMathExp* result = new(zone()) LMathExp(input, double_temp, temp1, temp2);
return DefineAsRegister(result); return DefineAsRegister(result);
} else if (op == kMathPowHalf) { }
// Input cannot be the same as the result.
// See lithium-codegen-mips.cc::DoMathPowHalf.
LInstruction* LChunkBuilder::DoMathPowHalf(HUnaryMathOperation* instr) {
// Input cannot be the same as the result, see LCodeGen::DoMathPowHalf.
LOperand* input = UseFixedDouble(instr->value(), f8); LOperand* input = UseFixedDouble(instr->value(), f8);
LOperand* temp = FixedTemp(f6); LOperand* temp = FixedTemp(f6);
LUnaryMathOperation* result = new(zone()) LUnaryMathOperation(input, temp); LMathPowHalf* result = new(zone()) LMathPowHalf(input, temp);
return DefineFixedDouble(result, f4); return DefineFixedDouble(result, f4);
} else { }
LOperand* input = UseRegister(instr->value());
LOperand* temp = (op == kMathRound) ? FixedTemp(f6) :
(op == kMathFloor) ? TempRegister() : NULL; LInstruction* LChunkBuilder::DoMathAbs(HUnaryMathOperation* instr) {
LUnaryMathOperation* result = new(zone()) LUnaryMathOperation(input, temp); LOperand* input = UseRegister(instr->value());
switch (op) { LMathAbs* result = new(zone()) LMathAbs(input);
case kMathAbs:
return AssignEnvironment(AssignPointerMap(DefineAsRegister(result))); return AssignEnvironment(AssignPointerMap(DefineAsRegister(result)));
case kMathFloor: }
LInstruction* LChunkBuilder::DoMathFloor(HUnaryMathOperation* instr) {
LOperand* input = UseRegister(instr->value());
LOperand* temp = TempRegister();
LMathFloor* result = new(zone()) LMathFloor(input, temp);
return AssignEnvironment(AssignPointerMap(DefineAsRegister(result))); return AssignEnvironment(AssignPointerMap(DefineAsRegister(result)));
case kMathSqrt: }
LInstruction* LChunkBuilder::DoMathSqrt(HUnaryMathOperation* instr) {
LOperand* input = UseRegister(instr->value());
LMathSqrt* result = new(zone()) LMathSqrt(input);
return DefineAsRegister(result); return DefineAsRegister(result);
case kMathRound: }
LInstruction* LChunkBuilder::DoMathRound(HUnaryMathOperation* instr) {
LOperand* input = UseRegister(instr->value());
LOperand* temp = FixedTemp(f6);
LMathRound* result = new(zone()) LMathRound(input, temp);
return AssignEnvironment(DefineAsRegister(result)); return AssignEnvironment(DefineAsRegister(result));
default:
UNREACHABLE();
return NULL;
}
}
} }

View File

@ -133,8 +133,17 @@ class LCodeGen;
V(LoadNamedFieldPolymorphic) \ V(LoadNamedFieldPolymorphic) \
V(LoadNamedGeneric) \ V(LoadNamedGeneric) \
V(MapEnumLength) \ V(MapEnumLength) \
V(MathAbs) \
V(MathCos) \
V(MathExp) \ V(MathExp) \
V(MathFloor) \
V(MathLog) \
V(MathMinMax) \ V(MathMinMax) \
V(MathPowHalf) \
V(MathRound) \
V(MathSin) \
V(MathSqrt) \
V(MathTan) \
V(ModI) \ V(ModI) \
V(MulI) \ V(MulI) \
V(MultiplyAddD) \ V(MultiplyAddD) \
@ -177,7 +186,6 @@ class LCodeGen;
V(TrapAllocationMemento) \ V(TrapAllocationMemento) \
V(Typeof) \ V(Typeof) \
V(TypeofIsAndBranch) \ V(TypeofIsAndBranch) \
V(UnaryMathOperation) \
V(UnknownOSRValue) \ V(UnknownOSRValue) \
V(ValueOf) \ V(ValueOf) \
V(ForInPrepareMap) \ V(ForInPrepareMap) \
@ -662,9 +670,9 @@ class LCmpIDAndBranch: public LControlInstruction<2, 0> {
}; };
class LUnaryMathOperation: public LTemplateInstruction<1, 1, 1> { class LMathFloor: public LTemplateInstruction<1, 1, 1> {
public: public:
LUnaryMathOperation(LOperand* value, LOperand* temp) { LMathFloor(LOperand* value, LOperand* temp) {
inputs_[0] = value; inputs_[0] = value;
temps_[0] = temp; temps_[0] = temp;
} }
@ -672,11 +680,84 @@ class LUnaryMathOperation: public LTemplateInstruction<1, 1, 1> {
LOperand* value() { return inputs_[0]; } LOperand* value() { return inputs_[0]; }
LOperand* temp() { return temps_[0]; } LOperand* temp() { return temps_[0]; }
DECLARE_CONCRETE_INSTRUCTION(UnaryMathOperation, "unary-math-operation") DECLARE_CONCRETE_INSTRUCTION(MathFloor, "math-floor")
DECLARE_HYDROGEN_ACCESSOR(UnaryMathOperation) DECLARE_HYDROGEN_ACCESSOR(UnaryMathOperation)
};
virtual void PrintDataTo(StringStream* stream);
BuiltinFunctionId op() const { return hydrogen()->op(); } class LMathRound: public LTemplateInstruction<1, 1, 1> {
public:
LMathRound(LOperand* value, LOperand* temp) {
inputs_[0] = value;
temps_[0] = temp;
}
LOperand* value() { return inputs_[0]; }
LOperand* temp() { return temps_[0]; }
DECLARE_CONCRETE_INSTRUCTION(MathRound, "math-round")
DECLARE_HYDROGEN_ACCESSOR(UnaryMathOperation)
};
class LMathAbs: public LTemplateInstruction<1, 1, 0> {
public:
explicit LMathAbs(LOperand* value) {
inputs_[0] = value;
}
LOperand* value() { return inputs_[0]; }
DECLARE_CONCRETE_INSTRUCTION(MathAbs, "math-abs")
DECLARE_HYDROGEN_ACCESSOR(UnaryMathOperation)
};
class LMathLog: public LTemplateInstruction<1, 1, 0> {
public:
explicit LMathLog(LOperand* value) {
inputs_[0] = value;
}
LOperand* value() { return inputs_[0]; }
DECLARE_CONCRETE_INSTRUCTION(MathLog, "math-log")
};
class LMathSin: public LTemplateInstruction<1, 1, 0> {
public:
explicit LMathSin(LOperand* value) {
inputs_[0] = value;
}
LOperand* value() { return inputs_[0]; }
DECLARE_CONCRETE_INSTRUCTION(MathSin, "math-sin")
};
class LMathCos: public LTemplateInstruction<1, 1, 0> {
public:
explicit LMathCos(LOperand* value) {
inputs_[0] = value;
}
LOperand* value() { return inputs_[0]; }
DECLARE_CONCRETE_INSTRUCTION(MathCos, "math-cos")
};
class LMathTan: public LTemplateInstruction<1, 1, 0> {
public:
explicit LMathTan(LOperand* value) {
inputs_[0] = value;
}
LOperand* value() { return inputs_[0]; }
DECLARE_CONCRETE_INSTRUCTION(MathTan, "math-tan")
}; };
@ -699,8 +780,32 @@ class LMathExp: public LTemplateInstruction<1, 1, 3> {
LOperand* double_temp() { return temps_[2]; } LOperand* double_temp() { return temps_[2]; }
DECLARE_CONCRETE_INSTRUCTION(MathExp, "math-exp") DECLARE_CONCRETE_INSTRUCTION(MathExp, "math-exp")
};
virtual void PrintDataTo(StringStream* stream);
class LMathSqrt: public LTemplateInstruction<1, 1, 0> {
public:
explicit LMathSqrt(LOperand* value) {
inputs_[0] = value;
}
LOperand* value() { return inputs_[0]; }
DECLARE_CONCRETE_INSTRUCTION(MathSqrt, "math-sqrt")
};
class LMathPowHalf: public LTemplateInstruction<1, 1, 1> {
public:
LMathPowHalf(LOperand* value, LOperand* temp) {
inputs_[0] = value;
temps_[0] = temp;
}
LOperand* value() { return inputs_[0]; }
LOperand* temp() { return temps_[0]; }
DECLARE_CONCRETE_INSTRUCTION(MathPowHalf, "math-pow-half")
}; };
@ -1254,7 +1359,7 @@ class LMathMinMax: public LTemplateInstruction<1, 2, 0> {
LOperand* left() { return inputs_[0]; } LOperand* left() { return inputs_[0]; }
LOperand* right() { return inputs_[1]; } LOperand* right() { return inputs_[1]; }
DECLARE_CONCRETE_INSTRUCTION(MathMinMax, "min-max") DECLARE_CONCRETE_INSTRUCTION(MathMinMax, "math-min-max")
DECLARE_HYDROGEN_ACCESSOR(MathMinMax) DECLARE_HYDROGEN_ACCESSOR(MathMinMax)
}; };
@ -2542,6 +2647,17 @@ class LChunkBuilder BASE_EMBEDDED {
LInstruction* DoMultiplyAdd(HMul* mul, HValue* addend); LInstruction* DoMultiplyAdd(HMul* mul, HValue* addend);
LInstruction* DoMathFloor(HUnaryMathOperation* instr);
LInstruction* DoMathRound(HUnaryMathOperation* instr);
LInstruction* DoMathAbs(HUnaryMathOperation* instr);
LInstruction* DoMathLog(HUnaryMathOperation* instr);
LInstruction* DoMathSin(HUnaryMathOperation* instr);
LInstruction* DoMathCos(HUnaryMathOperation* instr);
LInstruction* DoMathTan(HUnaryMathOperation* instr);
LInstruction* DoMathExp(HUnaryMathOperation* instr);
LInstruction* DoMathSqrt(HUnaryMathOperation* instr);
LInstruction* DoMathPowHalf(HUnaryMathOperation* instr);
private: private:
enum Status { enum Status {
UNUSED, UNUSED,

View File

@ -3368,7 +3368,7 @@ void LCodeGen::DoCallConstantFunction(LCallConstantFunction* instr) {
} }
void LCodeGen::DoDeferredMathAbsTaggedHeapNumber(LUnaryMathOperation* instr) { void LCodeGen::DoDeferredMathAbsTaggedHeapNumber(LMathAbs* instr) {
Register input_reg = ToRegister(instr->value()); Register input_reg = ToRegister(instr->value());
__ CompareRoot(FieldOperand(input_reg, HeapObject::kMapOffset), __ CompareRoot(FieldOperand(input_reg, HeapObject::kMapOffset),
Heap::kHeapNumberMapRootIndex); Heap::kHeapNumberMapRootIndex);
@ -3420,7 +3420,7 @@ void LCodeGen::DoDeferredMathAbsTaggedHeapNumber(LUnaryMathOperation* instr) {
} }
void LCodeGen::EmitIntegerMathAbs(LUnaryMathOperation* instr) { void LCodeGen::EmitIntegerMathAbs(LMathAbs* instr) {
Register input_reg = ToRegister(instr->value()); Register input_reg = ToRegister(instr->value());
__ testl(input_reg, input_reg); __ testl(input_reg, input_reg);
Label is_positive; Label is_positive;
@ -3431,19 +3431,18 @@ void LCodeGen::EmitIntegerMathAbs(LUnaryMathOperation* instr) {
} }
void LCodeGen::DoMathAbs(LUnaryMathOperation* instr) { void LCodeGen::DoMathAbs(LMathAbs* instr) {
// Class for deferred case. // Class for deferred case.
class DeferredMathAbsTaggedHeapNumber: public LDeferredCode { class DeferredMathAbsTaggedHeapNumber: public LDeferredCode {
public: public:
DeferredMathAbsTaggedHeapNumber(LCodeGen* codegen, DeferredMathAbsTaggedHeapNumber(LCodeGen* codegen, LMathAbs* instr)
LUnaryMathOperation* instr)
: LDeferredCode(codegen), instr_(instr) { } : LDeferredCode(codegen), instr_(instr) { }
virtual void Generate() { virtual void Generate() {
codegen()->DoDeferredMathAbsTaggedHeapNumber(instr_); codegen()->DoDeferredMathAbsTaggedHeapNumber(instr_);
} }
virtual LInstruction* instr() { return instr_; } virtual LInstruction* instr() { return instr_; }
private: private:
LUnaryMathOperation* instr_; LMathAbs* instr_;
}; };
ASSERT(instr->value()->Equals(instr->result())); ASSERT(instr->value()->Equals(instr->result()));
@ -3471,7 +3470,7 @@ void LCodeGen::DoMathAbs(LUnaryMathOperation* instr) {
} }
void LCodeGen::DoMathFloor(LUnaryMathOperation* instr) { void LCodeGen::DoMathFloor(LMathFloor* instr) {
XMMRegister xmm_scratch = xmm0; XMMRegister xmm_scratch = xmm0;
Register output_reg = ToRegister(instr->result()); Register output_reg = ToRegister(instr->result());
XMMRegister input_reg = ToDoubleRegister(instr->value()); XMMRegister input_reg = ToDoubleRegister(instr->value());
@ -3530,7 +3529,7 @@ void LCodeGen::DoMathFloor(LUnaryMathOperation* instr) {
} }
void LCodeGen::DoMathRound(LUnaryMathOperation* instr) { void LCodeGen::DoMathRound(LMathRound* instr) {
const XMMRegister xmm_scratch = xmm0; const XMMRegister xmm_scratch = xmm0;
Register output_reg = ToRegister(instr->result()); Register output_reg = ToRegister(instr->result());
XMMRegister input_reg = ToDoubleRegister(instr->value()); XMMRegister input_reg = ToDoubleRegister(instr->value());
@ -3591,14 +3590,14 @@ void LCodeGen::DoMathRound(LUnaryMathOperation* instr) {
} }
void LCodeGen::DoMathSqrt(LUnaryMathOperation* instr) { void LCodeGen::DoMathSqrt(LMathSqrt* instr) {
XMMRegister input_reg = ToDoubleRegister(instr->value()); XMMRegister input_reg = ToDoubleRegister(instr->value());
ASSERT(ToDoubleRegister(instr->result()).is(input_reg)); ASSERT(ToDoubleRegister(instr->result()).is(input_reg));
__ sqrtsd(input_reg, input_reg); __ sqrtsd(input_reg, input_reg);
} }
void LCodeGen::DoMathPowHalf(LUnaryMathOperation* instr) { void LCodeGen::DoMathPowHalf(LMathPowHalf* instr) {
XMMRegister xmm_scratch = xmm0; XMMRegister xmm_scratch = xmm0;
XMMRegister input_reg = ToDoubleRegister(instr->value()); XMMRegister input_reg = ToDoubleRegister(instr->value());
ASSERT(ToDoubleRegister(instr->result()).is(input_reg)); ASSERT(ToDoubleRegister(instr->result()).is(input_reg));
@ -3765,7 +3764,7 @@ void LCodeGen::DoMathExp(LMathExp* instr) {
} }
void LCodeGen::DoMathLog(LUnaryMathOperation* instr) { void LCodeGen::DoMathLog(LMathLog* instr) {
ASSERT(ToDoubleRegister(instr->result()).is(xmm1)); ASSERT(ToDoubleRegister(instr->result()).is(xmm1));
TranscendentalCacheStub stub(TranscendentalCache::LOG, TranscendentalCacheStub stub(TranscendentalCache::LOG,
TranscendentalCacheStub::UNTAGGED); TranscendentalCacheStub::UNTAGGED);
@ -3773,7 +3772,7 @@ void LCodeGen::DoMathLog(LUnaryMathOperation* instr) {
} }
void LCodeGen::DoMathTan(LUnaryMathOperation* instr) { void LCodeGen::DoMathTan(LMathTan* instr) {
ASSERT(ToDoubleRegister(instr->result()).is(xmm1)); ASSERT(ToDoubleRegister(instr->result()).is(xmm1));
TranscendentalCacheStub stub(TranscendentalCache::TAN, TranscendentalCacheStub stub(TranscendentalCache::TAN,
TranscendentalCacheStub::UNTAGGED); TranscendentalCacheStub::UNTAGGED);
@ -3781,7 +3780,7 @@ void LCodeGen::DoMathTan(LUnaryMathOperation* instr) {
} }
void LCodeGen::DoMathCos(LUnaryMathOperation* instr) { void LCodeGen::DoMathCos(LMathCos* instr) {
ASSERT(ToDoubleRegister(instr->result()).is(xmm1)); ASSERT(ToDoubleRegister(instr->result()).is(xmm1));
TranscendentalCacheStub stub(TranscendentalCache::COS, TranscendentalCacheStub stub(TranscendentalCache::COS,
TranscendentalCacheStub::UNTAGGED); TranscendentalCacheStub::UNTAGGED);
@ -3789,7 +3788,7 @@ void LCodeGen::DoMathCos(LUnaryMathOperation* instr) {
} }
void LCodeGen::DoMathSin(LUnaryMathOperation* instr) { void LCodeGen::DoMathSin(LMathSin* instr) {
ASSERT(ToDoubleRegister(instr->result()).is(xmm1)); ASSERT(ToDoubleRegister(instr->result()).is(xmm1));
TranscendentalCacheStub stub(TranscendentalCache::SIN, TranscendentalCacheStub stub(TranscendentalCache::SIN,
TranscendentalCacheStub::UNTAGGED); TranscendentalCacheStub::UNTAGGED);
@ -3797,42 +3796,6 @@ void LCodeGen::DoMathSin(LUnaryMathOperation* instr) {
} }
void LCodeGen::DoUnaryMathOperation(LUnaryMathOperation* instr) {
switch (instr->op()) {
case kMathAbs:
DoMathAbs(instr);
break;
case kMathFloor:
DoMathFloor(instr);
break;
case kMathRound:
DoMathRound(instr);
break;
case kMathSqrt:
DoMathSqrt(instr);
break;
case kMathPowHalf:
DoMathPowHalf(instr);
break;
case kMathCos:
DoMathCos(instr);
break;
case kMathSin:
DoMathSin(instr);
break;
case kMathTan:
DoMathTan(instr);
break;
case kMathLog:
DoMathLog(instr);
break;
default:
UNREACHABLE();
}
}
void LCodeGen::DoInvokeFunction(LInvokeFunction* instr) { void LCodeGen::DoInvokeFunction(LInvokeFunction* instr) {
ASSERT(ToRegister(instr->function()).is(rdi)); ASSERT(ToRegister(instr->function()).is(rdi));
ASSERT(instr->HasPointerMap()); ASSERT(instr->HasPointerMap());

View File

@ -111,7 +111,7 @@ class LCodeGen BASE_EMBEDDED {
void DoDeferredNumberTagD(LNumberTagD* instr); void DoDeferredNumberTagD(LNumberTagD* instr);
void DoDeferredNumberTagU(LNumberTagU* instr); void DoDeferredNumberTagU(LNumberTagU* instr);
void DoDeferredTaggedToI(LTaggedToI* instr); void DoDeferredTaggedToI(LTaggedToI* instr);
void DoDeferredMathAbsTaggedHeapNumber(LUnaryMathOperation* instr); void DoDeferredMathAbsTaggedHeapNumber(LMathAbs* instr);
void DoDeferredStackCheck(LStackCheck* instr); void DoDeferredStackCheck(LStackCheck* instr);
void DoDeferredRandom(LRandom* instr); void DoDeferredRandom(LRandom* instr);
void DoDeferredStringCharCodeAt(LStringCharCodeAt* instr); void DoDeferredStringCharCodeAt(LStringCharCodeAt* instr);
@ -258,17 +258,7 @@ class LCodeGen BASE_EMBEDDED {
uint32_t offset, uint32_t offset,
uint32_t additional_index = 0); uint32_t additional_index = 0);
// Specific math operations - used from DoUnaryMathOperation. void EmitIntegerMathAbs(LMathAbs* instr);
void EmitIntegerMathAbs(LUnaryMathOperation* instr);
void DoMathAbs(LUnaryMathOperation* instr);
void DoMathFloor(LUnaryMathOperation* instr);
void DoMathRound(LUnaryMathOperation* instr);
void DoMathSqrt(LUnaryMathOperation* instr);
void DoMathPowHalf(LUnaryMathOperation* instr);
void DoMathLog(LUnaryMathOperation* instr);
void DoMathTan(LUnaryMathOperation* instr);
void DoMathCos(LUnaryMathOperation* instr);
void DoMathSin(LUnaryMathOperation* instr);
// Support for recording safepoint and position information. // Support for recording safepoint and position information.
void RecordSafepoint(LPointerMap* pointers, void RecordSafepoint(LPointerMap* pointers,

View File

@ -304,17 +304,6 @@ void LCallConstantFunction::PrintDataTo(StringStream* stream) {
} }
void LUnaryMathOperation::PrintDataTo(StringStream* stream) {
stream->Add("/%s ", hydrogen()->OpName());
value()->PrintTo(stream);
}
void LMathExp::PrintDataTo(StringStream* stream) {
value()->PrintTo(stream);
}
void LLoadContextSlot::PrintDataTo(StringStream* stream) { void LLoadContextSlot::PrintDataTo(StringStream* stream) {
context()->PrintTo(stream); context()->PrintTo(stream);
stream->Add("[%d]", slot_index()); stream->Add("[%d]", slot_index());
@ -1130,12 +1119,73 @@ LInstruction* LChunkBuilder::DoInvokeFunction(HInvokeFunction* instr) {
LInstruction* LChunkBuilder::DoUnaryMathOperation(HUnaryMathOperation* instr) { LInstruction* LChunkBuilder::DoUnaryMathOperation(HUnaryMathOperation* instr) {
BuiltinFunctionId op = instr->op(); switch (instr->op()) {
if (op == kMathLog || op == kMathSin || op == kMathCos || op == kMathTan) { case kMathFloor: return DoMathFloor(instr);
case kMathRound: return DoMathRound(instr);
case kMathAbs: return DoMathAbs(instr);
case kMathLog: return DoMathLog(instr);
case kMathSin: return DoMathSin(instr);
case kMathCos: return DoMathCos(instr);
case kMathTan: return DoMathTan(instr);
case kMathExp: return DoMathExp(instr);
case kMathSqrt: return DoMathSqrt(instr);
case kMathPowHalf: return DoMathPowHalf(instr);
default:
UNREACHABLE();
return NULL;
}
}
LInstruction* LChunkBuilder::DoMathFloor(HUnaryMathOperation* instr) {
LOperand* input = UseRegisterAtStart(instr->value());
LMathFloor* result = new(zone()) LMathFloor(input);
return AssignEnvironment(DefineAsRegister(result));
}
LInstruction* LChunkBuilder::DoMathRound(HUnaryMathOperation* instr) {
LOperand* input = UseRegisterAtStart(instr->value());
LMathRound* result = new(zone()) LMathRound(input);
return AssignEnvironment(DefineAsRegister(result));
}
LInstruction* LChunkBuilder::DoMathAbs(HUnaryMathOperation* instr) {
LOperand* input = UseRegisterAtStart(instr->value());
LMathAbs* result = new(zone()) LMathAbs(input);
return AssignEnvironment(AssignPointerMap(DefineSameAsFirst(result)));
}
LInstruction* LChunkBuilder::DoMathLog(HUnaryMathOperation* instr) {
LOperand* input = UseFixedDouble(instr->value(), xmm1); LOperand* input = UseFixedDouble(instr->value(), xmm1);
LUnaryMathOperation* result = new(zone()) LUnaryMathOperation(input); LMathLog* result = new(zone()) LMathLog(input);
return MarkAsCall(DefineFixedDouble(result, xmm1), instr); return MarkAsCall(DefineFixedDouble(result, xmm1), instr);
} else if (op == kMathExp) { }
LInstruction* LChunkBuilder::DoMathSin(HUnaryMathOperation* instr) {
LOperand* input = UseFixedDouble(instr->value(), xmm1);
LMathSin* result = new(zone()) LMathSin(input);
return MarkAsCall(DefineFixedDouble(result, xmm1), instr);
}
LInstruction* LChunkBuilder::DoMathCos(HUnaryMathOperation* instr) {
LOperand* input = UseFixedDouble(instr->value(), xmm1);
LMathCos* result = new(zone()) LMathCos(input);
return MarkAsCall(DefineFixedDouble(result, xmm1), instr);
}
LInstruction* LChunkBuilder::DoMathTan(HUnaryMathOperation* instr) {
LOperand* input = UseFixedDouble(instr->value(), xmm1);
LMathTan* result = new(zone()) LMathTan(input);
return MarkAsCall(DefineFixedDouble(result, xmm1), instr);
}
LInstruction* LChunkBuilder::DoMathExp(HUnaryMathOperation* instr) {
ASSERT(instr->representation().IsDouble()); ASSERT(instr->representation().IsDouble());
ASSERT(instr->value()->representation().IsDouble()); ASSERT(instr->value()->representation().IsDouble());
LOperand* value = UseTempRegister(instr->value()); LOperand* value = UseTempRegister(instr->value());
@ -1143,25 +1193,20 @@ LInstruction* LChunkBuilder::DoUnaryMathOperation(HUnaryMathOperation* instr) {
LOperand* temp2 = TempRegister(); LOperand* temp2 = TempRegister();
LMathExp* result = new(zone()) LMathExp(value, temp1, temp2); LMathExp* result = new(zone()) LMathExp(value, temp1, temp2);
return DefineAsRegister(result); return DefineAsRegister(result);
} else { }
LInstruction* LChunkBuilder::DoMathSqrt(HUnaryMathOperation* instr) {
LOperand* input = UseRegisterAtStart(instr->value()); LOperand* input = UseRegisterAtStart(instr->value());
LUnaryMathOperation* result = new(zone()) LUnaryMathOperation(input); LMathSqrt* result = new(zone()) LMathSqrt(input);
switch (op) {
case kMathAbs:
return AssignEnvironment(AssignPointerMap(DefineSameAsFirst(result)));
case kMathFloor:
return AssignEnvironment(DefineAsRegister(result));
case kMathRound:
return AssignEnvironment(DefineAsRegister(result));
case kMathSqrt:
return DefineSameAsFirst(result); return DefineSameAsFirst(result);
case kMathPowHalf: }
LInstruction* LChunkBuilder::DoMathPowHalf(HUnaryMathOperation* instr) {
LOperand* input = UseRegisterAtStart(instr->value());
LMathPowHalf* result = new(zone()) LMathPowHalf(input);
return DefineSameAsFirst(result); return DefineSameAsFirst(result);
default:
UNREACHABLE();
return NULL;
}
}
} }

View File

@ -133,9 +133,18 @@ class LCodeGen;
V(LoadNamedField) \ V(LoadNamedField) \
V(LoadNamedFieldPolymorphic) \ V(LoadNamedFieldPolymorphic) \
V(LoadNamedGeneric) \ V(LoadNamedGeneric) \
V(MathAbs) \
V(MathCos) \
V(MathExp) \ V(MathExp) \
V(MathFloor) \
V(MathFloorOfDiv) \ V(MathFloorOfDiv) \
V(MathLog) \
V(MathMinMax) \ V(MathMinMax) \
V(MathPowHalf) \
V(MathRound) \
V(MathSin) \
V(MathSqrt) \
V(MathTan) \
V(ModI) \ V(ModI) \
V(MulI) \ V(MulI) \
V(NumberTagD) \ V(NumberTagD) \
@ -177,7 +186,6 @@ class LCodeGen;
V(TrapAllocationMemento) \ V(TrapAllocationMemento) \
V(Typeof) \ V(Typeof) \
V(TypeofIsAndBranch) \ V(TypeofIsAndBranch) \
V(UnaryMathOperation) \
V(UnknownOSRValue) \ V(UnknownOSRValue) \
V(ValueOf) \ V(ValueOf) \
V(ForInPrepareMap) \ V(ForInPrepareMap) \
@ -649,19 +657,90 @@ class LCmpIDAndBranch: public LControlInstruction<2, 0> {
}; };
class LUnaryMathOperation: public LTemplateInstruction<1, 1, 0> { class LMathFloor: public LTemplateInstruction<1, 1, 0> {
public: public:
explicit LUnaryMathOperation(LOperand* value) { explicit LMathFloor(LOperand* value) {
inputs_[0] = value; inputs_[0] = value;
} }
LOperand* value() { return inputs_[0]; } LOperand* value() { return inputs_[0]; }
DECLARE_CONCRETE_INSTRUCTION(UnaryMathOperation, "unary-math-operation") DECLARE_CONCRETE_INSTRUCTION(MathFloor, "math-floor")
DECLARE_HYDROGEN_ACCESSOR(UnaryMathOperation) DECLARE_HYDROGEN_ACCESSOR(UnaryMathOperation)
};
virtual void PrintDataTo(StringStream* stream);
BuiltinFunctionId op() const { return hydrogen()->op(); } class LMathRound: public LTemplateInstruction<1, 1, 0> {
public:
explicit LMathRound(LOperand* value) {
inputs_[0] = value;
}
LOperand* value() { return inputs_[0]; }
DECLARE_CONCRETE_INSTRUCTION(MathRound, "math-round")
DECLARE_HYDROGEN_ACCESSOR(UnaryMathOperation)
};
class LMathAbs: public LTemplateInstruction<1, 1, 0> {
public:
explicit LMathAbs(LOperand* value) {
inputs_[0] = value;
}
LOperand* value() { return inputs_[0]; }
DECLARE_CONCRETE_INSTRUCTION(MathAbs, "math-abs")
DECLARE_HYDROGEN_ACCESSOR(UnaryMathOperation)
};
class LMathLog: public LTemplateInstruction<1, 1, 0> {
public:
explicit LMathLog(LOperand* value) {
inputs_[0] = value;
}
LOperand* value() { return inputs_[0]; }
DECLARE_CONCRETE_INSTRUCTION(MathLog, "math-log")
};
class LMathSin: public LTemplateInstruction<1, 1, 0> {
public:
explicit LMathSin(LOperand* value) {
inputs_[0] = value;
}
LOperand* value() { return inputs_[0]; }
DECLARE_CONCRETE_INSTRUCTION(MathSin, "math-sin")
};
class LMathCos: public LTemplateInstruction<1, 1, 0> {
public:
explicit LMathCos(LOperand* value) {
inputs_[0] = value;
}
LOperand* value() { return inputs_[0]; }
DECLARE_CONCRETE_INSTRUCTION(MathCos, "math-cos")
};
class LMathTan: public LTemplateInstruction<1, 1, 0> {
public:
explicit LMathTan(LOperand* value) {
inputs_[0] = value;
}
LOperand* value() { return inputs_[0]; }
DECLARE_CONCRETE_INSTRUCTION(MathTan, "math-tan")
}; };
@ -679,8 +758,30 @@ class LMathExp: public LTemplateInstruction<1, 1, 2> {
LOperand* temp2() { return temps_[1]; } LOperand* temp2() { return temps_[1]; }
DECLARE_CONCRETE_INSTRUCTION(MathExp, "math-exp") DECLARE_CONCRETE_INSTRUCTION(MathExp, "math-exp")
};
virtual void PrintDataTo(StringStream* stream);
class LMathSqrt: public LTemplateInstruction<1, 1, 0> {
public:
explicit LMathSqrt(LOperand* value) {
inputs_[0] = value;
}
LOperand* value() { return inputs_[0]; }
DECLARE_CONCRETE_INSTRUCTION(MathSqrt, "math-sqrt")
};
class LMathPowHalf: public LTemplateInstruction<1, 1, 0> {
public:
explicit LMathPowHalf(LOperand* value) {
inputs_[0] = value;
}
LOperand* value() { return inputs_[0]; }
DECLARE_CONCRETE_INSTRUCTION(MathPowHalf, "math-pow-half")
}; };
@ -1249,7 +1350,7 @@ class LMathMinMax: public LTemplateInstruction<1, 2, 0> {
LOperand* left() { return inputs_[0]; } LOperand* left() { return inputs_[0]; }
LOperand* right() { return inputs_[1]; } LOperand* right() { return inputs_[1]; }
DECLARE_CONCRETE_INSTRUCTION(MathMinMax, "min-max") DECLARE_CONCRETE_INSTRUCTION(MathMinMax, "math-min-max")
DECLARE_HYDROGEN_ACCESSOR(MathMinMax) DECLARE_HYDROGEN_ACCESSOR(MathMinMax)
}; };
@ -2497,6 +2598,17 @@ class LChunkBuilder BASE_EMBEDDED {
static HValue* SimplifiedDividendForMathFloorOfDiv(HValue* val); static HValue* SimplifiedDividendForMathFloorOfDiv(HValue* val);
static HValue* SimplifiedDivisorForMathFloorOfDiv(HValue* val); static HValue* SimplifiedDivisorForMathFloorOfDiv(HValue* val);
LInstruction* DoMathFloor(HUnaryMathOperation* instr);
LInstruction* DoMathRound(HUnaryMathOperation* instr);
LInstruction* DoMathAbs(HUnaryMathOperation* instr);
LInstruction* DoMathLog(HUnaryMathOperation* instr);
LInstruction* DoMathSin(HUnaryMathOperation* instr);
LInstruction* DoMathCos(HUnaryMathOperation* instr);
LInstruction* DoMathTan(HUnaryMathOperation* instr);
LInstruction* DoMathExp(HUnaryMathOperation* instr);
LInstruction* DoMathSqrt(HUnaryMathOperation* instr);
LInstruction* DoMathPowHalf(HUnaryMathOperation* instr);
private: private:
enum Status { enum Status {
UNUSED, UNUSED,