Commit 9714c98f authored by zhengxing.li's avatar zhengxing.li Committed by Commit bot

X87: [builtins] Introduce proper Float64Exp operator.

  port d5f2ac5e (r37047)

  original commit message:
  Import base::ieee754::exp() from FreeBSD msun and introduce a Float64Exp
  TurboFan operator based on that, similar to what we do for Float64Log.
  Rewrite Math.exp() as TurboFan builtin and use that operator to also
  inline Math.exp() into optimized TurboFan functions.

BUG=

Review-Url: https://codereview.chromium.org/2096283002
Cr-Commit-Position: refs/heads/master@{#37269}
parent 513240bf
......@@ -754,6 +754,9 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
case kIeee754Float64Atan2:
ASSEMBLE_IEEE754_BINOP(atan2);
break;
case kIeee754Float64Exp:
ASSEMBLE_IEEE754_UNOP(exp);
break;
case kIeee754Float64Log:
ASSEMBLE_IEEE754_UNOP(log);
break;
......
......@@ -3702,65 +3702,17 @@ void LCodeGen::DoMathClz32(LMathClz32* instr) {
void LCodeGen::DoMathExp(LMathExp* instr) {
X87Register input = ToX87Register(instr->value());
X87Register result_reg = ToX87Register(instr->result());
Register temp_result = ToRegister(instr->temp1());
Register temp = ToRegister(instr->temp2());
Label slow, done, smi, finish;
DCHECK(result_reg.is(input));
// Store input into Heap number and call runtime function kMathExpRT.
if (FLAG_inline_new) {
__ AllocateHeapNumber(temp_result, temp, no_reg, &slow);
__ jmp(&done, Label::kNear);
}
// Slow case: Call the runtime system to do the number allocation.
__ bind(&slow);
{
// TODO(3095996): Put a valid pointer value in the stack slot where the
// result register is stored, as this register is in the pointer map, but
// contains an integer value.
__ Move(temp_result, Immediate(0));
// Preserve the value of all registers.
PushSafepointRegistersScope scope(this);
__ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset));
__ CallRuntimeSaveDoubles(Runtime::kAllocateHeapNumber);
RecordSafepointWithRegisters(instr->pointer_map(), 0,
Safepoint::kNoLazyDeopt);
__ StoreToSafepointRegisterSlot(temp_result, eax);
}
__ bind(&done);
X87LoadForUsage(input);
__ fstp_d(FieldOperand(temp_result, HeapNumber::kValueOffset));
{
// Preserve the value of all registers.
PushSafepointRegistersScope scope(this);
X87Register result = ToX87Register(instr->result());
X87Register input_reg = ToX87Register(instr->value());
__ fld(x87_stack_.st(input_reg));
__ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset));
__ push(temp_result);
__ CallRuntimeSaveDoubles(Runtime::kMathExpRT);
RecordSafepointWithRegisters(instr->pointer_map(), 1,
Safepoint::kNoLazyDeopt);
__ StoreToSafepointRegisterSlot(temp_result, eax);
}
X87PrepareToWrite(result_reg);
// return value of MathExpRT is Smi or Heap Number.
__ JumpIfSmi(temp_result, &smi);
// Heap number(double)
__ fld_d(FieldOperand(temp_result, HeapNumber::kValueOffset));
__ jmp(&finish);
// SMI
__ bind(&smi);
__ SmiUntag(temp_result);
__ push(temp_result);
__ fild_s(MemOperand(esp, 0));
__ pop(temp_result);
__ bind(&finish);
X87CommitWrite(result_reg);
// Pass one double as argument on the stack.
__ PrepareCallCFunction(2, eax);
__ fstp_d(MemOperand(esp, 0));
X87PrepareToWrite(result);
__ CallCFunction(ExternalReference::ieee754_exp_function(isolate()), 2);
// Return value is in st(0) on ia32.
X87CommitWrite(result);
}
void LCodeGen::PrepareForTailCall(const ParameterCount& actual,
......
......@@ -1177,11 +1177,8 @@ LInstruction* LChunkBuilder::DoMathClz32(HUnaryMathOperation* instr) {
LInstruction* LChunkBuilder::DoMathExp(HUnaryMathOperation* instr) {
DCHECK(instr->representation().IsDouble());
DCHECK(instr->value()->representation().IsDouble());
LOperand* value = UseRegisterAtStart(instr->value());
LOperand* temp1 = FixedTemp(ecx);
LOperand* temp2 = FixedTemp(edx);
LMathExp* result = new(zone()) LMathExp(value, temp1, temp2);
return MarkAsCall(DefineSameAsFirst(result), instr);
LOperand* input = UseRegisterAtStart(instr->value());
return MarkAsCall(DefineSameAsFirst(new (zone()) LMathExp(input)), instr);
}
......
......@@ -904,21 +904,11 @@ class LMathClz32 final : public LTemplateInstruction<1, 1, 0> {
DECLARE_CONCRETE_INSTRUCTION(MathClz32, "math-clz32")
};
class LMathExp final : public LTemplateInstruction<1, 1, 2> {
class LMathExp final : public LTemplateInstruction<1, 1, 0> {
public:
LMathExp(LOperand* value,
LOperand* temp1,
LOperand* temp2) {
inputs_[0] = value;
temps_[0] = temp1;
temps_[1] = temp2;
ExternalReference::InitializeMathExpData();
}
explicit LMathExp(LOperand* value) { inputs_[0] = value; }
LOperand* value() { return inputs_[0]; }
LOperand* temp1() { return temps_[0]; }
LOperand* temp2() { return temps_[1]; }
DECLARE_CONCRETE_INSTRUCTION(MathExp, "math-exp")
};
......
......@@ -33,10 +33,6 @@ void StubRuntimeCallHelper::AfterCall(MacroAssembler* masm) const {
#define __ masm.
UnaryMathFunctionWithIsolate CreateExpFunction(Isolate* isolate) {
return nullptr;
}
UnaryMathFunctionWithIsolate CreateSqrtFunction(Isolate* isolate) {
size_t actual_size;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment