X87: [builtins] Introduce proper Float64Cos and Float64Sin.
port c781e83194
(r37072)
original commit message:
Import base::ieee754::cos() and base::ieee754::sin() from fdlibm and
introduce Float64Cos and Float64Sin TurboFan operator based on that,
similar to what we do for Float64Log. Rewrite Math.cos() and Math.sin()
as TurboFan builtins and use those operators to also inline Math.cos()
and Math.sin() into optimized TurboFan functions.
BUG=
Review-Url: https://codereview.chromium.org/2105613002
Cr-Commit-Position: refs/heads/master@{#37304}
This commit is contained in:
parent
9480ea4496
commit
3bc1a84227
@ -754,6 +754,19 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
|
||||
case kIeee754Float64Atan2:
|
||||
ASSEMBLE_IEEE754_BINOP(atan2);
|
||||
break;
|
||||
case kIeee754Float64Cbrt:
|
||||
ASSEMBLE_IEEE754_UNOP(cbrt);
|
||||
break;
|
||||
case kIeee754Float64Cos:
|
||||
__ X87SetFPUCW(0x027F);
|
||||
ASSEMBLE_IEEE754_UNOP(cos);
|
||||
__ X87SetFPUCW(0x037F);
|
||||
break;
|
||||
case kIeee754Float64Expm1:
|
||||
__ X87SetFPUCW(0x027F);
|
||||
ASSEMBLE_IEEE754_UNOP(expm1);
|
||||
__ X87SetFPUCW(0x037F);
|
||||
break;
|
||||
case kIeee754Float64Exp:
|
||||
ASSEMBLE_IEEE754_UNOP(exp);
|
||||
break;
|
||||
@ -772,11 +785,10 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
|
||||
case kIeee754Float64Log10:
|
||||
ASSEMBLE_IEEE754_UNOP(log10);
|
||||
break;
|
||||
case kIeee754Float64Cbrt:
|
||||
ASSEMBLE_IEEE754_UNOP(cbrt);
|
||||
break;
|
||||
case kIeee754Float64Expm1:
|
||||
ASSEMBLE_IEEE754_UNOP(expm1);
|
||||
case kIeee754Float64Sin:
|
||||
__ X87SetFPUCW(0x027F);
|
||||
ASSEMBLE_IEEE754_UNOP(sin);
|
||||
__ X87SetFPUCW(0x037F);
|
||||
break;
|
||||
case kX87Add:
|
||||
if (HasImmediateInput(instr, 1)) {
|
||||
|
@ -3697,6 +3697,33 @@ void LCodeGen::DoMathClz32(LMathClz32* instr) {
|
||||
__ Lzcnt(result, input);
|
||||
}
|
||||
|
||||
void LCodeGen::DoMathCos(LMathCos* instr) {
|
||||
X87Register result = ToX87Register(instr->result());
|
||||
X87Register input_reg = ToX87Register(instr->value());
|
||||
__ fld(x87_stack_.st(input_reg));
|
||||
|
||||
// Pass one double as argument on the stack.
|
||||
__ PrepareCallCFunction(2, eax);
|
||||
__ fstp_d(MemOperand(esp, 0));
|
||||
X87PrepareToWrite(result);
|
||||
__ CallCFunction(ExternalReference::ieee754_cos_function(isolate()), 2);
|
||||
// Return value is in st(0) on ia32.
|
||||
X87CommitWrite(result);
|
||||
}
|
||||
|
||||
void LCodeGen::DoMathSin(LMathSin* instr) {
|
||||
X87Register result = ToX87Register(instr->result());
|
||||
X87Register input_reg = ToX87Register(instr->value());
|
||||
__ fld(x87_stack_.st(input_reg));
|
||||
|
||||
// Pass one double as argument on the stack.
|
||||
__ PrepareCallCFunction(2, eax);
|
||||
__ fstp_d(MemOperand(esp, 0));
|
||||
X87PrepareToWrite(result);
|
||||
__ CallCFunction(ExternalReference::ieee754_sin_function(isolate()), 2);
|
||||
// Return value is in st(0) on ia32.
|
||||
X87CommitWrite(result);
|
||||
}
|
||||
|
||||
void LCodeGen::DoMathExp(LMathExp* instr) {
|
||||
X87Register result = ToX87Register(instr->result());
|
||||
|
@ -1110,15 +1110,28 @@ LInstruction* LChunkBuilder::DoInvokeFunction(HInvokeFunction* instr) {
|
||||
|
||||
LInstruction* LChunkBuilder::DoUnaryMathOperation(HUnaryMathOperation* instr) {
|
||||
switch (instr->op()) {
|
||||
case kMathFloor: return DoMathFloor(instr);
|
||||
case kMathRound: return DoMathRound(instr);
|
||||
case kMathFround: return DoMathFround(instr);
|
||||
case kMathAbs: return DoMathAbs(instr);
|
||||
case kMathLog: return DoMathLog(instr);
|
||||
case kMathExp: return DoMathExp(instr);
|
||||
case kMathSqrt: return DoMathSqrt(instr);
|
||||
case kMathPowHalf: return DoMathPowHalf(instr);
|
||||
case kMathClz32: return DoMathClz32(instr);
|
||||
case kMathCos:
|
||||
return DoMathCos(instr);
|
||||
case kMathFloor:
|
||||
return DoMathFloor(instr);
|
||||
case kMathRound:
|
||||
return DoMathRound(instr);
|
||||
case kMathFround:
|
||||
return DoMathFround(instr);
|
||||
case kMathAbs:
|
||||
return DoMathAbs(instr);
|
||||
case kMathLog:
|
||||
return DoMathLog(instr);
|
||||
case kMathExp:
|
||||
return DoMathExp(instr);
|
||||
case kMathSqrt:
|
||||
return DoMathSqrt(instr);
|
||||
case kMathPowHalf:
|
||||
return DoMathPowHalf(instr);
|
||||
case kMathClz32:
|
||||
return DoMathClz32(instr);
|
||||
case kMathSin:
|
||||
return DoMathSin(instr);
|
||||
default:
|
||||
UNREACHABLE();
|
||||
return NULL;
|
||||
@ -1173,6 +1186,19 @@ LInstruction* LChunkBuilder::DoMathClz32(HUnaryMathOperation* instr) {
|
||||
return DefineAsRegister(result);
|
||||
}
|
||||
|
||||
LInstruction* LChunkBuilder::DoMathCos(HUnaryMathOperation* instr) {
|
||||
DCHECK(instr->representation().IsDouble());
|
||||
DCHECK(instr->value()->representation().IsDouble());
|
||||
LOperand* input = UseRegisterAtStart(instr->value());
|
||||
return MarkAsCall(DefineSameAsFirst(new (zone()) LMathCos(input)), instr);
|
||||
}
|
||||
|
||||
LInstruction* LChunkBuilder::DoMathSin(HUnaryMathOperation* instr) {
|
||||
DCHECK(instr->representation().IsDouble());
|
||||
DCHECK(instr->value()->representation().IsDouble());
|
||||
LOperand* input = UseRegisterAtStart(instr->value());
|
||||
return MarkAsCall(DefineSameAsFirst(new (zone()) LMathSin(input)), instr);
|
||||
}
|
||||
|
||||
LInstruction* LChunkBuilder::DoMathExp(HUnaryMathOperation* instr) {
|
||||
DCHECK(instr->representation().IsDouble());
|
||||
|
@ -103,6 +103,7 @@ class LCodeGen;
|
||||
V(LoadRoot) \
|
||||
V(MathAbs) \
|
||||
V(MathClz32) \
|
||||
V(MathCos) \
|
||||
V(MathExp) \
|
||||
V(MathFloor) \
|
||||
V(MathFround) \
|
||||
@ -112,6 +113,7 @@ class LCodeGen;
|
||||
V(MathRound) \
|
||||
V(MathSqrt) \
|
||||
V(MaybeGrowElements) \
|
||||
V(MathSin) \
|
||||
V(ModByConstI) \
|
||||
V(ModByPowerOf2I) \
|
||||
V(ModI) \
|
||||
@ -904,6 +906,24 @@ class LMathClz32 final : public LTemplateInstruction<1, 1, 0> {
|
||||
DECLARE_CONCRETE_INSTRUCTION(MathClz32, "math-clz32")
|
||||
};
|
||||
|
||||
class LMathCos final : 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 LMathSin final : 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 LMathExp final : public LTemplateInstruction<1, 1, 0> {
|
||||
public:
|
||||
explicit LMathExp(LOperand* value) { inputs_[0] = value; }
|
||||
@ -2534,6 +2554,8 @@ class LChunkBuilder final : public LChunkBuilderBase {
|
||||
LInstruction* DoMathFround(HUnaryMathOperation* instr);
|
||||
LInstruction* DoMathAbs(HUnaryMathOperation* instr);
|
||||
LInstruction* DoMathLog(HUnaryMathOperation* instr);
|
||||
LInstruction* DoMathCos(HUnaryMathOperation* instr);
|
||||
LInstruction* DoMathSin(HUnaryMathOperation* instr);
|
||||
LInstruction* DoMathExp(HUnaryMathOperation* instr);
|
||||
LInstruction* DoMathSqrt(HUnaryMathOperation* instr);
|
||||
LInstruction* DoMathPowHalf(HUnaryMathOperation* instr);
|
||||
|
Loading…
Reference in New Issue
Block a user