Commit 4d4eb611 authored by mvstanton's avatar mvstanton Committed by Commit bot

[builtins] Unify Atanh, Cbrt and Expm1 as exports from flibm.

BUG=v8:5103

Review-Url: https://codereview.chromium.org/2068743002
Cr-Commit-Position: refs/heads/master@{#37058}
parent 5c5f5c08
......@@ -1568,6 +1568,11 @@ ExternalReference ExternalReference::ieee754_atan2_function(Isolate* isolate) {
isolate, FUNCTION_ADDR(base::ieee754::atan2), BUILTIN_FP_FP_CALL));
}
ExternalReference ExternalReference::ieee754_atanh_function(Isolate* isolate) {
return ExternalReference(Redirect(
isolate, FUNCTION_ADDR(base::ieee754::atanh), BUILTIN_FP_FP_CALL));
}
ExternalReference ExternalReference::ieee754_exp_function(Isolate* isolate) {
return ExternalReference(
Redirect(isolate, FUNCTION_ADDR(base::ieee754::exp), BUILTIN_FP_CALL));
......@@ -1593,6 +1598,16 @@ ExternalReference ExternalReference::ieee754_log10_function(Isolate* isolate) {
Redirect(isolate, FUNCTION_ADDR(base::ieee754::log10), BUILTIN_FP_CALL));
}
ExternalReference ExternalReference::ieee754_cbrt_function(Isolate* isolate) {
return ExternalReference(Redirect(isolate, FUNCTION_ADDR(base::ieee754::cbrt),
BUILTIN_FP_FP_CALL));
}
ExternalReference ExternalReference::ieee754_expm1_function(Isolate* isolate) {
return ExternalReference(Redirect(
isolate, FUNCTION_ADDR(base::ieee754::expm1), BUILTIN_FP_FP_CALL));
}
ExternalReference ExternalReference::page_flags(Page* page) {
return ExternalReference(reinterpret_cast<Address>(page) +
MemoryChunk::kFlagsOffset);
......
......@@ -1047,6 +1047,12 @@ class ExternalReference BASE_EMBEDDED {
static ExternalReference ieee754_log1p_function(Isolate* isolate);
static ExternalReference ieee754_log2_function(Isolate* isolate);
static ExternalReference ieee754_log10_function(Isolate* isolate);
static ExternalReference ieee754_atanh_function(Isolate* isolate);
static ExternalReference ieee754_cbrt_function(Isolate* isolate);
static ExternalReference ieee754_expm1_function(Isolate* isolate);
static ExternalReference math_exp_constants(int constant_index);
static ExternalReference math_exp_log_table();
static ExternalReference page_flags(Page* page);
......
This diff is collapsed.
......@@ -20,6 +20,8 @@ double atan2(double y, double x);
// Returns the base-e exponential of |x|.
double exp(double x);
double atanh(double x);
// Returns the natural logarithm of |x|.
double log(double x);
......@@ -33,6 +35,12 @@ double log2(double x);
// Return the base 10 logarithm of |x|.
double log10(double x);
// Return cube root of |x|.
double cbrt(double x);
// Returns exp(x)-1, the exponential of |x| minus 1.
double expm1(double x);
} // namespace ieee754
} // namespace base
} // namespace v8
......
......@@ -1674,7 +1674,10 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
SimpleInstallFunction(math, "asin", Builtins::kMathAsin, 1, true);
SimpleInstallFunction(math, "atan", Builtins::kMathAtan, 1, true);
SimpleInstallFunction(math, "atan2", Builtins::kMathAtan2, 2, true);
SimpleInstallFunction(math, "atanh", Builtins::kMathAtanh, 1, true);
SimpleInstallFunction(math, "ceil", Builtins::kMathCeil, 1, true);
SimpleInstallFunction(math, "cbrt", Builtins::kMathCbrt, 1, true);
SimpleInstallFunction(math, "expm1", Builtins::kMathExpm1, 1, true);
SimpleInstallFunction(math, "clz32", Builtins::kMathClz32, 1, true);
Handle<JSFunction> math_exp =
SimpleInstallFunction(math, "exp", Builtins::kMathExp, 1, true);
......@@ -2584,6 +2587,13 @@ void Bootstrapper::ExportFromRuntime(Isolate* isolate,
script_map->AppendDescriptor(&d);
}
{
// TODO(mvstanton): Remove this when MathSinh, MathCosh and MathTanh are
// no longer implemented in fdlibm.js.
SimpleInstallFunction(container, "MathExpm1", Builtins::kMathExpm1, 1,
true);
}
{
PrototypeIterator iter(native_context->sloppy_async_function_map());
Handle<JSObject> async_function_prototype(iter.GetCurrent<JSObject>());
......
......@@ -2316,6 +2316,18 @@ void Builtins::Generate_MathAtan2(CodeStubAssembler* assembler) {
assembler->Return(result);
}
// ES6 section 20.2.2.7 Math.atanh ( x )
void Builtins::Generate_MathAtanh(CodeStubAssembler* assembler) {
using compiler::Node;
Node* x = assembler->Parameter(1);
Node* context = assembler->Parameter(4);
Node* x_value = assembler->TruncateTaggedToFloat64(context, x);
Node* value = assembler->Float64Atanh(x_value);
Node* result = assembler->ChangeFloat64ToTagged(value);
assembler->Return(result);
}
namespace {
void Generate_MathRoundingOperation(
......@@ -2384,6 +2396,18 @@ void Builtins::Generate_MathCeil(CodeStubAssembler* assembler) {
Generate_MathRoundingOperation(assembler, &CodeStubAssembler::Float64Ceil);
}
// ES6 section 20.2.2.9 Math.cbrt ( x )
void Builtins::Generate_MathCbrt(CodeStubAssembler* assembler) {
using compiler::Node;
Node* x = assembler->Parameter(1);
Node* context = assembler->Parameter(4);
Node* x_value = assembler->TruncateTaggedToFloat64(context, x);
Node* value = assembler->Float64Cbrt(x_value);
Node* result = assembler->ChangeFloat64ToTagged(value);
assembler->Return(result);
}
// ES6 section 20.2.2.11 Math.clz32 ( x )
void Builtins::Generate_MathClz32(CodeStubAssembler* assembler) {
typedef CodeStubAssembler::Label Label;
......@@ -2539,6 +2563,18 @@ void Builtins::Generate_MathLog10(CodeStubAssembler* assembler) {
assembler->Return(result);
}
// ES6 section 20.2.2.15 Math.expm1 ( x )
void Builtins::Generate_MathExpm1(CodeStubAssembler* assembler) {
using compiler::Node;
Node* x = assembler->Parameter(1);
Node* context = assembler->Parameter(4);
Node* x_value = assembler->TruncateTaggedToFloat64(context, x);
Node* value = assembler->Float64Expm1(x_value);
Node* result = assembler->ChangeFloat64ToTagged(value);
assembler->Return(result);
}
// ES6 section 20.2.2.28 Math.round ( x )
void Builtins::Generate_MathRound(CodeStubAssembler* assembler) {
Generate_MathRoundingOperation(assembler, &CodeStubAssembler::Float64Round);
......
......@@ -318,7 +318,10 @@ inline bool operator&(BuiltinExtraArguments lhs, BuiltinExtraArguments rhs) {
V(GeneratorPrototypeThrow, 2) \
V(MathAtan, 2) \
V(MathAtan2, 3) \
V(MathAtanh, 2) \
V(MathCeil, 2) \
V(MathCbrt, 2) \
V(MathExpm1, 2) \
V(MathClz32, 2) \
V(MathExp, 2) \
V(MathFloor, 2) \
......@@ -631,8 +634,14 @@ class Builtins {
static void Generate_MathAtan(CodeStubAssembler* assembler);
// ES6 section 20.2.2.8 Math.atan2 ( y, x )
static void Generate_MathAtan2(CodeStubAssembler* assembler);
// ES6 section 20.2.2.7 Math.atanh ( x )
static void Generate_MathAtanh(CodeStubAssembler* assembler);
// ES6 section 20.2.2.10 Math.ceil ( x )
static void Generate_MathCeil(CodeStubAssembler* assembler);
// ES6 section 20.2.2.9 Math.ceil ( x )
static void Generate_MathCbrt(CodeStubAssembler* assembler);
// ES6 section 20.2.2.15 Math.expm1 ( x )
static void Generate_MathExpm1(CodeStubAssembler* assembler);
// ES6 section 20.2.2.11 Math.clz32 ( x )
static void Generate_MathClz32(CodeStubAssembler* assembler);
// ES6 section 20.2.2.14 Math.exp ( x )
......
......@@ -712,6 +712,9 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
case kIeee754Float64Exp:
ASSEMBLE_IEEE754_UNOP(exp);
break;
case kIeee754Float64Atanh:
ASSEMBLE_IEEE754_UNOP(atanh);
break;
case kIeee754Float64Log:
ASSEMBLE_IEEE754_UNOP(log);
break;
......@@ -724,6 +727,12 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
case kIeee754Float64Log10:
ASSEMBLE_IEEE754_UNOP(log10);
break;
case kIeee754Float64Cbrt:
ASSEMBLE_IEEE754_UNOP(cbrt);
break;
case kIeee754Float64Expm1:
ASSEMBLE_IEEE754_UNOP(expm1);
break;
case kArmAdd:
__ add(i.OutputRegister(), i.InputRegister(0), i.InputOperand2(1),
i.OutputSBit());
......
......@@ -816,6 +816,9 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
case kIeee754Float64Exp:
ASSEMBLE_IEEE754_UNOP(exp);
break;
case kIeee754Float64Atanh:
ASSEMBLE_IEEE754_UNOP(atanh);
break;
case kIeee754Float64Log:
ASSEMBLE_IEEE754_UNOP(log);
break;
......@@ -828,6 +831,12 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
case kIeee754Float64Log10:
ASSEMBLE_IEEE754_UNOP(log10);
break;
case kIeee754Float64Cbrt:
ASSEMBLE_IEEE754_UNOP(cbrt);
break;
case kIeee754Float64Expm1:
ASSEMBLE_IEEE754_UNOP(expm1);
break;
case kArm64Float32RoundDown:
__ Frintm(i.OutputFloat32Register(), i.InputFloat32Register(0));
break;
......
......@@ -108,11 +108,14 @@ class Schedule;
#define CODE_ASSEMBLER_UNARY_OP_LIST(V) \
V(Float64Atan) \
V(Float64Atanh) \
V(Float64Exp) \
V(Float64Expm1) \
V(Float64Log) \
V(Float64Log1p) \
V(Float64Log2) \
V(Float64Log10) \
V(Float64Cbrt) \
V(Float64Neg) \
V(Float64Sqrt) \
V(Float64ExtractLowWord32) \
......
......@@ -658,6 +658,9 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
case kIeee754Float64Exp:
ASSEMBLE_IEEE754_UNOP(exp);
break;
case kIeee754Float64Atanh:
ASSEMBLE_IEEE754_UNOP(atanh);
break;
case kIeee754Float64Log:
ASSEMBLE_IEEE754_UNOP(log);
break;
......@@ -670,6 +673,12 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
case kIeee754Float64Log10:
ASSEMBLE_IEEE754_UNOP(log10);
break;
case kIeee754Float64Cbrt:
ASSEMBLE_IEEE754_UNOP(cbrt);
break;
case kIeee754Float64Expm1:
ASSEMBLE_IEEE754_UNOP(expm1);
break;
case kIA32Add:
if (HasImmediateInput(instr, 1)) {
__ add(i.InputOperand(0), i.InputImmediate(1));
......
......@@ -91,11 +91,14 @@ enum class RecordWriteMode { kValueIsMap, kValueIsPointer, kValueIsAny };
V(AtomicStoreWord32) \
V(Ieee754Float64Atan) \
V(Ieee754Float64Atan2) \
V(Ieee754Float64Atanh) \
V(Ieee754Float64Exp) \
V(Ieee754Float64Expm1) \
V(Ieee754Float64Log) \
V(Ieee754Float64Log1p) \
V(Ieee754Float64Log2) \
V(Ieee754Float64Log10)
V(Ieee754Float64Log10) \
V(Ieee754Float64Cbrt)
#define ARCH_OPCODE_LIST(V) \
COMMON_ARCH_OPCODE_LIST(V) \
......
......@@ -226,11 +226,14 @@ int InstructionScheduler::GetInstructionFlags(const Instruction* instr) const {
case kArchComment:
case kIeee754Float64Atan:
case kIeee754Float64Atan2:
case kIeee754Float64Atanh:
case kIeee754Float64Exp:
case kIeee754Float64Expm1:
case kIeee754Float64Log:
case kIeee754Float64Log1p:
case kIeee754Float64Log2:
case kIeee754Float64Log10:
case kIeee754Float64Cbrt:
return kNoOpcodeFlags;
case kArchStackPointer:
......
......@@ -1138,8 +1138,12 @@ void InstructionSelector::VisitNode(Node* node) {
return MarkAsFloat64(node), VisitFloat64Atan(node);
case IrOpcode::kFloat64Atan2:
return MarkAsFloat64(node), VisitFloat64Atan2(node);
case IrOpcode::kFloat64Atanh:
return MarkAsFloat64(node), VisitFloat64Atanh(node);
case IrOpcode::kFloat64Exp:
return MarkAsFloat64(node), VisitFloat64Exp(node);
case IrOpcode::kFloat64Expm1:
return MarkAsFloat64(node), VisitFloat64Expm1(node);
case IrOpcode::kFloat64Log:
return MarkAsFloat64(node), VisitFloat64Log(node);
case IrOpcode::kFloat64Log1p:
......@@ -1148,6 +1152,8 @@ void InstructionSelector::VisitNode(Node* node) {
return MarkAsFloat64(node), VisitFloat64Log2(node);
case IrOpcode::kFloat64Log10:
return MarkAsFloat64(node), VisitFloat64Log10(node);
case IrOpcode::kFloat64Cbrt:
return MarkAsFloat64(node), VisitFloat64Cbrt(node);
case IrOpcode::kFloat64Sqrt:
return MarkAsFloat64(node), VisitFloat64Sqrt(node);
case IrOpcode::kFloat64Equal:
......@@ -1261,10 +1267,18 @@ void InstructionSelector::VisitFloat64Atan2(Node* node) {
VisitFloat64Ieee754Binop(node, kIeee754Float64Atan2);
}
void InstructionSelector::VisitFloat64Atanh(Node* node) {
VisitFloat64Ieee754Unop(node, kIeee754Float64Atanh);
}
void InstructionSelector::VisitFloat64Exp(Node* node) {
VisitFloat64Ieee754Unop(node, kIeee754Float64Exp);
}
void InstructionSelector::VisitFloat64Expm1(Node* node) {
VisitFloat64Ieee754Unop(node, kIeee754Float64Expm1);
}
void InstructionSelector::VisitFloat64Log(Node* node) {
VisitFloat64Ieee754Unop(node, kIeee754Float64Log);
}
......@@ -1281,6 +1295,10 @@ void InstructionSelector::VisitFloat64Log10(Node* node) {
VisitFloat64Ieee754Unop(node, kIeee754Float64Log10);
}
void InstructionSelector::VisitFloat64Cbrt(Node* node) {
VisitFloat64Ieee754Unop(node, kIeee754Float64Cbrt);
}
void InstructionSelector::EmitTableSwitch(const SwitchInfo& sw,
InstructionOperand& index_operand) {
OperandGenerator g(this);
......
......@@ -118,6 +118,17 @@ Reduction JSBuiltinReducer::ReduceMathAtan2(Node* node) {
return NoChange();
}
// ES6 section 20.2.2.7 Math.atanh ( x )
Reduction JSBuiltinReducer::ReduceMathAtanh(Node* node) {
JSCallReduction r(node);
if (r.InputsMatchOne(Type::Number())) {
// Math.atanh(a:number) -> NumberAtanh(a)
Node* value = graph()->NewNode(simplified()->NumberAtanh(), r.left());
return Replace(value);
}
return NoChange();
}
// ES6 section 20.2.2.10 Math.ceil ( x )
Reduction JSBuiltinReducer::ReduceMathCeil(Node* node) {
JSCallReduction r(node);
......@@ -154,6 +165,17 @@ Reduction JSBuiltinReducer::ReduceMathExp(Node* node) {
return NoChange();
}
// ES6 section 20.2.2.15 Math.expm1 ( x )
Reduction JSBuiltinReducer::ReduceMathExpm1(Node* node) {
JSCallReduction r(node);
if (r.InputsMatchOne(Type::Number())) {
// Math.expm1(a:number) -> NumberExpm1(a)
Node* value = graph()->NewNode(simplified()->NumberExpm1(), r.left());
return Replace(value);
}
return NoChange();
}
// ES6 section 20.2.2.16 Math.floor ( x )
Reduction JSBuiltinReducer::ReduceMathFloor(Node* node) {
JSCallReduction r(node);
......@@ -293,6 +315,17 @@ Reduction JSBuiltinReducer::ReduceMathLog10(Node* node) {
return NoChange();
}
// ES6 section 20.2.2.9 Math.cbrt ( x )
Reduction JSBuiltinReducer::ReduceMathCbrt(Node* node) {
JSCallReduction r(node);
if (r.InputsMatchOne(Type::Number())) {
// Math.cbrt(a:number) -> NumberCbrt(a)
Node* value = graph()->NewNode(simplified()->NumberCbrt(), r.left());
return Replace(value);
}
return NoChange();
}
// ES6 section 20.2.2.28 Math.round ( x )
Reduction JSBuiltinReducer::ReduceMathRound(Node* node) {
JSCallReduction r(node);
......@@ -354,6 +387,9 @@ Reduction JSBuiltinReducer::Reduce(Node* node) {
case kMathAtan2:
reduction = ReduceMathAtan2(node);
break;
case kMathAtanh:
reduction = ReduceMathAtanh(node);
break;
case kMathClz32:
reduction = ReduceMathClz32(node);
break;
......@@ -363,6 +399,9 @@ Reduction JSBuiltinReducer::Reduce(Node* node) {
case kMathExp:
reduction = ReduceMathExp(node);
break;
case kMathExpm1:
reduction = ReduceMathExpm1(node);
break;
case kMathFloor:
reduction = ReduceMathFloor(node);
break;
......@@ -390,6 +429,9 @@ Reduction JSBuiltinReducer::Reduce(Node* node) {
case kMathMin:
reduction = ReduceMathMin(node);
break;
case kMathCbrt:
reduction = ReduceMathCbrt(node);
break;
case kMathRound:
reduction = ReduceMathRound(node);
break;
......
......@@ -31,6 +31,7 @@ class JSBuiltinReducer final : public AdvancedReducer {
private:
Reduction ReduceMathAtan(Node* node);
Reduction ReduceMathAtan2(Node* node);
Reduction ReduceMathAtanh(Node* node);
Reduction ReduceMathCeil(Node* node);
Reduction ReduceMathClz32(Node* node);
Reduction ReduceMathExp(Node* node);
......@@ -43,6 +44,8 @@ class JSBuiltinReducer final : public AdvancedReducer {
Reduction ReduceMathLog10(Node* node);
Reduction ReduceMathMax(Node* node);
Reduction ReduceMathMin(Node* node);
Reduction ReduceMathCbrt(Node* node);
Reduction ReduceMathExpm1(Node* node);
Reduction ReduceMathRound(Node* node);
Reduction ReduceMathSqrt(Node* node);
Reduction ReduceMathTrunc(Node* node);
......
......@@ -396,11 +396,21 @@ Reduction MachineOperatorReducer::Reduce(Node* node) {
}
break;
}
case IrOpcode::kFloat64Atanh: {
Float64Matcher m(node->InputAt(0));
if (m.HasValue()) return ReplaceFloat64(base::ieee754::atanh(m.Value()));
break;
}
case IrOpcode::kFloat64Exp: {
Float64Matcher m(node->InputAt(0));
if (m.HasValue()) return ReplaceFloat64(base::ieee754::exp(m.Value()));
break;
}
case IrOpcode::kFloat64Expm1: {
Float64Matcher m(node->InputAt(0));
if (m.HasValue()) return ReplaceFloat64(base::ieee754::expm1(m.Value()));
break;
}
case IrOpcode::kFloat64Log: {
Float64Matcher m(node->InputAt(0));
if (m.HasValue()) return ReplaceFloat64(base::ieee754::log(m.Value()));
......@@ -421,6 +431,11 @@ Reduction MachineOperatorReducer::Reduce(Node* node) {
if (m.HasValue()) return ReplaceFloat64(base::ieee754::log10(m.Value()));
break;
}
case IrOpcode::kFloat64Cbrt: {
Float64Matcher m(node->InputAt(0));
if (m.HasValue()) return ReplaceFloat64(base::ieee754::cbrt(m.Value()));
break;
}
case IrOpcode::kChangeFloat32ToFloat64: {
Float32Matcher m(node->InputAt(0));
if (m.HasValue()) return ReplaceFloat64(m.Value());
......
......@@ -157,11 +157,14 @@ MachineRepresentation AtomicStoreRepresentationOf(Operator const* op) {
V(Float64Abs, Operator::kNoProperties, 1, 0, 1) \
V(Float64Atan, Operator::kNoProperties, 1, 0, 1) \
V(Float64Atan2, Operator::kNoProperties, 2, 0, 1) \
V(Float64Atanh, Operator::kNoProperties, 1, 0, 1) \
V(Float64Exp, Operator::kNoProperties, 1, 0, 1) \
V(Float64Expm1, Operator::kNoProperties, 1, 0, 1) \
V(Float64Log, Operator::kNoProperties, 1, 0, 1) \
V(Float64Log1p, Operator::kNoProperties, 1, 0, 1) \
V(Float64Log2, Operator::kNoProperties, 1, 0, 1) \
V(Float64Log10, Operator::kNoProperties, 1, 0, 1) \
V(Float64Cbrt, Operator::kNoProperties, 1, 0, 1) \
V(Float64Add, Operator::kCommutative, 2, 0, 1) \
V(Float64Sub, Operator::kNoProperties, 2, 0, 1) \
V(Float64SubPreserveNan, Operator::kNoProperties, 2, 0, 1) \
......
......@@ -371,6 +371,7 @@ class MachineOperatorBuilder final : public ZoneObject {
// Floating point trigonometric functions (double-precision).
const Operator* Float64Atan();
const Operator* Float64Atan2();
const Operator* Float64Atanh();
// Floating point exponential functions.
const Operator* Float64Exp();
......@@ -381,6 +382,9 @@ class MachineOperatorBuilder final : public ZoneObject {
const Operator* Float64Log2();
const Operator* Float64Log10();
const Operator* Float64Cbrt();
const Operator* Float64Expm1();
// Floating point bit representation.
const Operator* Float64ExtractLowWord32();
const Operator* Float64ExtractHighWord32();
......
......@@ -750,9 +750,18 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
case kIeee754Float64Exp:
ASSEMBLE_IEEE754_UNOP(exp);
break;
case kIeee754Float64Atanh:
ASSEMBLE_IEEE754_UNOP(atanh);
break;
case kIeee754Float64Log:
ASSEMBLE_IEEE754_UNOP(log);
break;
case kIeee754Float64Cbrt:
ASSEMBLE_IEEE754_UNOP(cbrt);
break;
case kIeee754Float64Expm1:
ASSEMBLE_IEEE754_UNOP(expm1);
break;
case kIeee754Float64Log1p:
ASSEMBLE_IEEE754_UNOP(log1p);
break;
......
......@@ -756,9 +756,15 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
case kIeee754Float64Atan2:
ASSEMBLE_IEEE754_BINOP(atan2);
break;
case kIeee754Float64Atanh:
ASSEMBLE_IEEE754_UNOP(atanh);
break;
case kIeee754Float64Exp:
ASSEMBLE_IEEE754_UNOP(exp);
break;
case kIeee754Float64Expm1:
ASSEMBLE_IEEE754_UNOP(expm1);
break;
case kIeee754Float64Log:
ASSEMBLE_IEEE754_UNOP(log);
break;
......@@ -771,6 +777,9 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
case kIeee754Float64Log10:
ASSEMBLE_IEEE754_UNOP(log10);
break;
case kIeee754Float64Cbrt:
ASSEMBLE_IEEE754_UNOP(cbrt);
break;
case kMips64Add:
__ Addu(i.OutputRegister(), i.InputRegister(0), i.InputOperand(1));
break;
......
......@@ -203,11 +203,14 @@
V(NumberFround) \
V(NumberAtan) \
V(NumberAtan2) \
V(NumberAtanh) \
V(NumberExp) \
V(NumberExpm1) \
V(NumberLog) \
V(NumberLog1p) \
V(NumberLog2) \
V(NumberLog10) \
V(NumberCbrt) \
V(NumberRound) \
V(NumberSqrt) \
V(NumberTrunc) \
......@@ -372,11 +375,14 @@
V(Float64Abs) \
V(Float64Atan) \
V(Float64Atan2) \
V(Float64Atanh) \
V(Float64Exp) \
V(Float64Expm1) \
V(Float64Log) \
V(Float64Log1p) \
V(Float64Log2) \
V(Float64Log10) \
V(Float64Cbrt) \
V(Float64Sqrt) \
V(Float64RoundDown) \
V(Float32RoundUp) \
......
......@@ -464,11 +464,14 @@ class RawMachineAssembler {
Node* Float64Atan2(Node* a, Node* b) {
return AddNode(machine()->Float64Atan2(), a, b);
}
Node* Float64Atanh(Node* a) { return AddNode(machine()->Float64Atanh(), a); }
Node* Float64Exp(Node* a) { return AddNode(machine()->Float64Exp(), a); }
Node* Float64Expm1(Node* a) { return AddNode(machine()->Float64Expm1(), a); }
Node* Float64Log(Node* a) { return AddNode(machine()->Float64Log(), a); }
Node* Float64Log1p(Node* a) { return AddNode(machine()->Float64Log1p(), a); }
Node* Float64Log2(Node* a) { return AddNode(machine()->Float64Log2(), a); }
Node* Float64Log10(Node* a) { return AddNode(machine()->Float64Log10(), a); }
Node* Float64Cbrt(Node* a) { return AddNode(machine()->Float64Cbrt(), a); }
Node* Float64Sqrt(Node* a) { return AddNode(machine()->Float64Sqrt(), a); }
Node* Float64Equal(Node* a, Node* b) {
return AddNode(machine()->Float64Equal(), a, b);
......
......@@ -675,6 +675,8 @@ const Operator* RepresentationChanger::Float64OperatorFor(
return machine()->Float64Exp();
case IrOpcode::kNumberFround:
return machine()->TruncateFloat64ToFloat32();
case IrOpcode::kNumberAtanh:
return machine()->Float64Atanh();
case IrOpcode::kNumberLog:
return machine()->Float64Log();
case IrOpcode::kNumberLog1p:
......@@ -685,6 +687,10 @@ const Operator* RepresentationChanger::Float64OperatorFor(
return machine()->Float64Log10();
case IrOpcode::kNumberSqrt:
return machine()->Float64Sqrt();
case IrOpcode::kNumberCbrt:
return machine()->Float64Cbrt();
case IrOpcode::kNumberExpm1:
return machine()->Float64Expm1();
case IrOpcode::kNumberSilenceNaN:
return machine()->Float64SilenceNaN();
default:
......
......@@ -1442,11 +1442,14 @@ class RepresentationSelector {
return;
}
case IrOpcode::kNumberAtan:
case IrOpcode::kNumberAtanh:
case IrOpcode::kNumberExp:
case IrOpcode::kNumberExpm1:
case IrOpcode::kNumberLog:
case IrOpcode::kNumberLog1p:
case IrOpcode::kNumberLog2:
case IrOpcode::kNumberLog10: {
case IrOpcode::kNumberLog10:
case IrOpcode::kNumberCbrt: {
VisitUnop(node, UseInfo::TruncatingFloat64(),
MachineRepresentation::kFloat64);
if (lower()) NodeProperties::ChangeOp(node, Float64Op(node));
......
......@@ -254,11 +254,14 @@ CompareOperationHints::Hint CompareOperationHintOf(const Operator* op) {
V(NumberFround, Operator::kNoProperties, 1) \
V(NumberAtan, Operator::kNoProperties, 1) \
V(NumberAtan2, Operator::kNoProperties, 2) \
V(NumberAtanh, Operator::kNoProperties, 1) \
V(NumberExp, Operator::kNoProperties, 1) \
V(NumberExpm1, Operator::kNoProperties, 1) \
V(NumberLog, Operator::kNoProperties, 1) \
V(NumberLog1p, Operator::kNoProperties, 1) \
V(NumberLog2, Operator::kNoProperties, 1) \
V(NumberLog10, Operator::kNoProperties, 1) \
V(NumberCbrt, Operator::kNoProperties, 1) \
V(NumberRound, Operator::kNoProperties, 1) \
V(NumberSqrt, Operator::kNoProperties, 1) \
V(NumberTrunc, Operator::kNoProperties, 1) \
......
......@@ -181,11 +181,14 @@ class SimplifiedOperatorBuilder final : public ZoneObject {
const Operator* NumberFround();
const Operator* NumberAtan();
const Operator* NumberAtan2();
const Operator* NumberAtanh();
const Operator* NumberExp();
const Operator* NumberExpm1();
const Operator* NumberLog();
const Operator* NumberLog1p();
const Operator* NumberLog2();
const Operator* NumberLog10();
const Operator* NumberCbrt();
const Operator* NumberRound();
const Operator* NumberSqrt();
const Operator* NumberTrunc();
......
......@@ -1801,10 +1801,15 @@ Type* Typer::Visitor::TypeNumberAtan(Node* node) { return Type::Number(); }
Type* Typer::Visitor::TypeNumberAtan2(Node* node) { return Type::Number(); }
Type* Typer::Visitor::TypeNumberAtanh(Node* node) { return Type::Number(); }
Type* Typer::Visitor::TypeNumberExp(Node* node) {
return Type::Union(Type::PlainNumber(), Type::NaN(), zone());
}
// TODO(mvstanton): Is this type sufficient, or should it look like Exp()?
Type* Typer::Visitor::TypeNumberExpm1(Node* node) { return Type::Number(); }
Type* Typer::Visitor::TypeNumberLog(Node* node) { return Type::Number(); }
Type* Typer::Visitor::TypeNumberLog1p(Node* node) { return Type::Number(); }
......@@ -1813,6 +1818,8 @@ Type* Typer::Visitor::TypeNumberLog2(Node* node) { return Type::Number(); }
Type* Typer::Visitor::TypeNumberLog10(Node* node) { return Type::Number(); }
Type* Typer::Visitor::TypeNumberCbrt(Node* node) { return Type::Number(); }
Type* Typer::Visitor::TypeNumberRound(Node* node) {
return TypeUnaryOp(node, NumberRound);
}
......@@ -2564,8 +2571,12 @@ Type* Typer::Visitor::TypeFloat64Atan(Node* node) { return Type::Number(); }
Type* Typer::Visitor::TypeFloat64Atan2(Node* node) { return Type::Number(); }
Type* Typer::Visitor::TypeFloat64Atanh(Node* node) { return Type::Number(); }
Type* Typer::Visitor::TypeFloat64Exp(Node* node) { return Type::Number(); }
Type* Typer::Visitor::TypeFloat64Expm1(Node* node) { return Type::Number(); }
Type* Typer::Visitor::TypeFloat64Log(Node* node) { return Type::Number(); }
Type* Typer::Visitor::TypeFloat64Log1p(Node* node) { return Type::Number(); }
......@@ -2574,6 +2585,8 @@ Type* Typer::Visitor::TypeFloat64Log2(Node* node) { return Type::Number(); }
Type* Typer::Visitor::TypeFloat64Log10(Node* node) { return Type::Number(); }
Type* Typer::Visitor::TypeFloat64Cbrt(Node* node) { return Type::Number(); }
Type* Typer::Visitor::TypeFloat64Sqrt(Node* node) { return Type::Number(); }
......
......@@ -753,11 +753,14 @@ void Verifier::Visitor::Check(Node* node) {
case IrOpcode::kNumberFloor:
case IrOpcode::kNumberFround:
case IrOpcode::kNumberAtan:
case IrOpcode::kNumberAtanh:
case IrOpcode::kNumberExp:
case IrOpcode::kNumberExpm1:
case IrOpcode::kNumberLog:
case IrOpcode::kNumberLog1p:
case IrOpcode::kNumberLog2:
case IrOpcode::kNumberLog10:
case IrOpcode::kNumberCbrt:
case IrOpcode::kNumberRound:
case IrOpcode::kNumberSqrt:
case IrOpcode::kNumberTrunc:
......@@ -1071,11 +1074,14 @@ void Verifier::Visitor::Check(Node* node) {
case IrOpcode::kFloat64Abs:
case IrOpcode::kFloat64Atan:
case IrOpcode::kFloat64Atan2:
case IrOpcode::kFloat64Atanh:
case IrOpcode::kFloat64Exp:
case IrOpcode::kFloat64Expm1:
case IrOpcode::kFloat64Log:
case IrOpcode::kFloat64Log1p:
case IrOpcode::kFloat64Log2:
case IrOpcode::kFloat64Log10:
case IrOpcode::kFloat64Cbrt:
case IrOpcode::kFloat64Sqrt:
case IrOpcode::kFloat32RoundDown:
case IrOpcode::kFloat64RoundDown:
......
......@@ -873,9 +873,15 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
case kIeee754Float64Atan2:
ASSEMBLE_IEEE754_BINOP(atan2);
break;
case kIeee754Float64Atanh:
ASSEMBLE_IEEE754_UNOP(atanh);
break;
case kIeee754Float64Exp:
ASSEMBLE_IEEE754_UNOP(exp);
break;
case kIeee754Float64Expm1:
ASSEMBLE_IEEE754_UNOP(expm1);
break;
case kIeee754Float64Log:
ASSEMBLE_IEEE754_UNOP(log);
break;
......@@ -888,6 +894,9 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
case kIeee754Float64Log10:
ASSEMBLE_IEEE754_UNOP(log10);
break;
case kIeee754Float64Cbrt:
ASSEMBLE_IEEE754_UNOP(cbrt);
break;
case kX64Add32:
ASSEMBLE_BINOP(addl);
break;
......
......@@ -71,8 +71,12 @@ ExternalReferenceTable::ExternalReferenceTable(Isolate* isolate) {
"base::ieee754::atan");
Add(ExternalReference::ieee754_atan2_function(isolate).address(),
"base::ieee754::atan2");
Add(ExternalReference::ieee754_atanh_function(isolate).address(),
"base::ieee754::atanh");
Add(ExternalReference::ieee754_exp_function(isolate).address(),
"base::ieee754::exp");
Add(ExternalReference::ieee754_expm1_function(isolate).address(),
"base::ieee754::expm1");
Add(ExternalReference::ieee754_log_function(isolate).address(),
"base::ieee754::log");
Add(ExternalReference::ieee754_log1p_function(isolate).address(),
......@@ -81,6 +85,8 @@ ExternalReferenceTable::ExternalReferenceTable(Isolate* isolate) {
"base::ieee754::log2");
Add(ExternalReference::ieee754_log10_function(isolate).address(),
"base::ieee754::log10");
Add(ExternalReference::ieee754_cbrt_function(isolate).address(),
"base::ieee754::cbrt");
Add(ExternalReference::store_buffer_top(isolate).address(),
"store_buffer_top");
Add(ExternalReference::address_of_the_hole_nan().address(), "the_hole_nan");
......
......@@ -88,16 +88,6 @@ function MathAcosh(x) {
return %math_log(x + %math_sqrt(x + 1) * %math_sqrt(x - 1));
}
// ES6 draft 09-27-13, section 20.2.2.7.
function MathAtanh(x) {
x = TO_NUMBER(x);
// Idempotent for +/-0.
if (x === 0) return x;
// Returns NaN for NaN and +/- Infinity.
if (!NUMBER_IS_FINITE(x)) return NaN;
return 0.5 * %math_log((1 + x) / (1 - x));
}
// ES6 draft 09-27-13, section 20.2.2.17.
function MathHypot(x, y) { // Function length is 2.
// We may want to introduce fast paths for two arguments and when
......@@ -127,29 +117,6 @@ function MathHypot(x, y) { // Function length is 2.
return %math_sqrt(sum) * max;
}
// ES6 draft 09-27-13, section 20.2.2.9.
// Cube root approximation, refer to: http://metamerist.com/cbrt/cbrt.htm
// Using initial approximation adapted from Kahan's cbrt and 4 iterations
// of Newton's method.
function MathCbrt(x) {
x = TO_NUMBER(x);
if (x == 0 || !NUMBER_IS_FINITE(x)) return x;
return x >= 0 ? CubeRoot(x) : -CubeRoot(-x);
}
macro NEWTON_ITERATION_CBRT(x, approx)
(1.0 / 3.0) * (x / (approx * approx) + 2 * approx);
endmacro
function CubeRoot(x) {
var approx_hi = %math_floor(%_DoubleHi(x) / 3) + 0x2A9F7893;
var approx = %_ConstructDouble(approx_hi | 0, 0);
approx = NEWTON_ITERATION_CBRT(x, approx);
approx = NEWTON_ITERATION_CBRT(x, approx);
approx = NEWTON_ITERATION_CBRT(x, approx);
return NEWTON_ITERATION_CBRT(x, approx);
}
// -------------------------------------------------------------------
%InstallToContext([
......@@ -183,9 +150,7 @@ utils.InstallFunctions(GlobalMath, DONT_ENUM, [
"sign", MathSign,
"asinh", MathAsinh,
"acosh", MathAcosh,
"atanh", MathAtanh,
"hypot", MathHypot,
"cbrt", MathCbrt
]);
%SetForceInlineFlag(MathAbs);
......
......@@ -6591,7 +6591,9 @@ class Script: public Struct {
V(Math, log1p, MathLog1p) \
V(Math, log2, MathLog2) \
V(Math, log10, MathLog10) \
V(Math, cbrt, MathCbrt) \
V(Math, exp, MathExp) \
V(Math, expm1, MathExpm1) \
V(Math, sqrt, MathSqrt) \
V(Math, pow, MathPow) \
V(Math, max, MathMax) \
......@@ -6603,6 +6605,7 @@ class Script: public Struct {
V(Math, asin, MathAsin) \
V(Math, atan, MathAtan) \
V(Math, atan2, MathAtan2) \
V(Math, atanh, MathAtanh) \
V(Math, imul, MathImul) \
V(Math, clz32, MathClz32) \
V(Math, fround, MathFround) \
......
......@@ -31,11 +31,13 @@
var GlobalFloat64Array = global.Float64Array;
var GlobalMath = global.Math;
var MathAbs;
var MathExpm1;
var NaN = %GetRootNaN();
var rempio2result;
utils.Import(function(from) {
MathAbs = from.MathAbs;
MathExpm1 = from.MathExpm1;
});
utils.CreateDoubleResultArray = function(global) {
......@@ -401,202 +403,6 @@ define LN2_LO = 1.90821492927058770002e-10;
// 2^54
define TWO54 = 18014398509481984;
// ES6 draft 09-27-13, section 20.2.2.14.
// Math.expm1
// Returns exp(x)-1, the exponential of x minus 1.
//
// Method
// 1. Argument reduction:
// Given x, find r and integer k such that
//
// x = k*ln2 + r, |r| <= 0.5*ln2 ~ 0.34658
//
// Here a correction term c will be computed to compensate
// the error in r when rounded to a floating-point number.
//
// 2. Approximating expm1(r) by a special rational function on
// the interval [0,0.34658]:
// Since
// r*(exp(r)+1)/(exp(r)-1) = 2+ r^2/6 - r^4/360 + ...
// we define R1(r*r) by
// r*(exp(r)+1)/(exp(r)-1) = 2+ r^2/6 * R1(r*r)
// That is,
// R1(r**2) = 6/r *((exp(r)+1)/(exp(r)-1) - 2/r)
// = 6/r * ( 1 + 2.0*(1/(exp(r)-1) - 1/r))
// = 1 - r^2/60 + r^4/2520 - r^6/100800 + ...
// We use a special Remes algorithm on [0,0.347] to generate
// a polynomial of degree 5 in r*r to approximate R1. The
// maximum error of this polynomial approximation is bounded
// by 2**-61. In other words,
// R1(z) ~ 1.0 + Q1*z + Q2*z**2 + Q3*z**3 + Q4*z**4 + Q5*z**5
// where Q1 = -1.6666666666666567384E-2,
// Q2 = 3.9682539681370365873E-4,
// Q3 = -9.9206344733435987357E-6,
// Q4 = 2.5051361420808517002E-7,
// Q5 = -6.2843505682382617102E-9;
// (where z=r*r, and the values of Q1 to Q5 are listed below)
// with error bounded by
// | 5 | -61
// | 1.0+Q1*z+...+Q5*z - R1(z) | <= 2
// | |
//
// expm1(r) = exp(r)-1 is then computed by the following
// specific way which minimize the accumulation rounding error:
// 2 3
// r r [ 3 - (R1 + R1*r/2) ]
// expm1(r) = r + --- + --- * [--------------------]
// 2 2 [ 6 - r*(3 - R1*r/2) ]
//
// To compensate the error in the argument reduction, we use
// expm1(r+c) = expm1(r) + c + expm1(r)*c
// ~ expm1(r) + c + r*c
// Thus c+r*c will be added in as the correction terms for
// expm1(r+c). Now rearrange the term to avoid optimization
// screw up:
// ( 2 2 )
// ({ ( r [ R1 - (3 - R1*r/2) ] ) } r )
// expm1(r+c)~r - ({r*(--- * [--------------------]-c)-c} - --- )
// ({ ( 2 [ 6 - r*(3 - R1*r/2) ] ) } 2 )
// ( )
//
// = r - E
// 3. Scale back to obtain expm1(x):
// From step 1, we have
// expm1(x) = either 2^k*[expm1(r)+1] - 1
// = or 2^k*[expm1(r) + (1-2^-k)]
// 4. Implementation notes:
// (A). To save one multiplication, we scale the coefficient Qi
// to Qi*2^i, and replace z by (x^2)/2.
// (B). To achieve maximum accuracy, we compute expm1(x) by
// (i) if x < -56*ln2, return -1.0, (raise inexact if x!=inf)
// (ii) if k=0, return r-E
// (iii) if k=-1, return 0.5*(r-E)-0.5
// (iv) if k=1 if r < -0.25, return 2*((r+0.5)- E)
// else return 1.0+2.0*(r-E);
// (v) if (k<-2||k>56) return 2^k(1-(E-r)) - 1 (or exp(x)-1)
// (vi) if k <= 20, return 2^k((1-2^-k)-(E-r)), else
// (vii) return 2^k(1-((E+2^-k)-r))
//
// Special cases:
// expm1(INF) is INF, expm1(NaN) is NaN;
// expm1(-INF) is -1, and
// for finite argument, only expm1(0)=0 is exact.
//
// Accuracy:
// according to an error analysis, the error is always less than
// 1 ulp (unit in the last place).
//
// Misc. info.
// For IEEE double
// if x > 7.09782712893383973096e+02 then expm1(x) overflow
//
define KEXPM1_OVERFLOW = 7.09782712893383973096e+02;
define INVLN2 = 1.44269504088896338700;
define EXPM1_1 = -3.33333333333331316428e-02;
define EXPM1_2 = 1.58730158725481460165e-03;
define EXPM1_3 = -7.93650757867487942473e-05;
define EXPM1_4 = 4.00821782732936239552e-06;
define EXPM1_5 = -2.01099218183624371326e-07;
function MathExpm1(x) {
x = x * 1; // Convert to number.
var y;
var hi;
var lo;
var k;
var t;
var c;
var hx = %_DoubleHi(x);
var xsb = hx & 0x80000000; // Sign bit of x
var y = (xsb === 0) ? x : -x; // y = |x|
hx &= 0x7fffffff; // High word of |x|
// Filter out huge and non-finite argument
if (hx >= 0x4043687a) { // if |x| ~=> 56 * ln2
if (hx >= 0x40862e42) { // if |x| >= 709.78
if (hx >= 0x7ff00000) {
// expm1(inf) = inf; expm1(-inf) = -1; expm1(nan) = nan;
return (x === -INFINITY) ? -1 : x;
}
if (x > KEXPM1_OVERFLOW) return INFINITY; // Overflow
}
if (xsb != 0) return -1; // x < -56 * ln2, return -1.
}
// Argument reduction
if (hx > 0x3fd62e42) { // if |x| > 0.5 * ln2
if (hx < 0x3ff0a2b2) { // and |x| < 1.5 * ln2
if (xsb === 0) {
hi = x - LN2_HI;
lo = LN2_LO;
k = 1;
} else {
hi = x + LN2_HI;
lo = -LN2_LO;
k = -1;
}
} else {
k = (INVLN2 * x + ((xsb === 0) ? 0.5 : -0.5)) | 0;
t = k;
// t * ln2_hi is exact here.
hi = x - t * LN2_HI;
lo = t * LN2_LO;
}
x = hi - lo;
c = (hi - x) - lo;
} else if (hx < 0x3c900000) {
// When |x| < 2^-54, we can return x.
return x;
} else {
// Fall through.
k = 0;
}
// x is now in primary range
var hfx = 0.5 * x;
var hxs = x * hfx;
var r1 = 1 + hxs * (EXPM1_1 + hxs * (EXPM1_2 + hxs *
(EXPM1_3 + hxs * (EXPM1_4 + hxs * EXPM1_5))));
t = 3 - r1 * hfx;
var e = hxs * ((r1 - t) / (6 - x * t));
if (k === 0) { // c is 0
return x - (x*e - hxs);
} else {
e = (x * (e - c) - c);
e -= hxs;
if (k === -1) return 0.5 * (x - e) - 0.5;
if (k === 1) {
if (x < -0.25) return -2 * (e - (x + 0.5));
return 1 + 2 * (x - e);
}
if (k <= -2 || k > 56) {
// suffice to return exp(x) + 1
y = 1 - (e - x);
// Add k to y's exponent
y = %_ConstructDouble(%_DoubleHi(y) + (k << 20), %_DoubleLo(y));
return y - 1;
}
if (k < 20) {
// t = 1 - 2^k
t = %_ConstructDouble(0x3ff00000 - (0x200000 >> k), 0);
y = t - (e - x);
// Add k to y's exponent
y = %_ConstructDouble(%_DoubleHi(y) + (k << 20), %_DoubleLo(y));
} else {
// t = 2^-k
t = %_ConstructDouble((0x3ff - k) << 20, 0);
y = x - (e + t);
y += 1;
// Add k to y's exponent
y = %_ConstructDouble(%_DoubleHi(y) + (k << 20), %_DoubleLo(y));
}
}
return y;
}
// ES6 draft 09-27-13, section 20.2.2.30.
// Math.sinh
// Method :
......@@ -763,8 +569,7 @@ utils.InstallFunctions(GlobalMath, DONT_ENUM, [
"tan", MathTan,
"sinh", MathSinh,
"cosh", MathCosh,
"tanh", MathTanh,
"expm1", MathExpm1
"tanh", MathTanh
]);
%SetForceInlineFlag(MathSin);
......
......@@ -5517,6 +5517,18 @@ TEST(RunFloat64Atan2) {
}
}
TEST(RunFloat64Atanh) {
BufferedRawMachineAssemblerTester<double> m(MachineType::Float64());
m.Return(m.Float64Atanh(m.Parameter(0)));
CHECK(std::isnan(m.Call(std::numeric_limits<double>::quiet_NaN())));
CHECK(std::isnan(m.Call(std::numeric_limits<double>::signaling_NaN())));
CHECK_DOUBLE_EQ(std::numeric_limits<double>::infinity(), m.Call(1.0));
CHECK_DOUBLE_EQ(-std::numeric_limits<double>::infinity(), m.Call(-1.0));
CHECK_DOUBLE_EQ(-0.0, m.Call(-0.0));
CHECK_DOUBLE_EQ(0.0, m.Call(0.0));
FOR_FLOAT64_INPUTS(i) { CHECK_DOUBLE_EQ(ieee754::atanh(*i), m.Call(*i)); }
}
TEST(RunFloat64Exp) {
BufferedRawMachineAssemblerTester<double> m(MachineType::Float64());
m.Return(m.Float64Exp(m.Parameter(0)));
......@@ -5530,6 +5542,17 @@ TEST(RunFloat64Exp) {
FOR_FLOAT64_INPUTS(i) { CHECK_DOUBLE_EQ(ieee754::exp(*i), m.Call(*i)); }
}
TEST(RunFloat64Expm1) {
BufferedRawMachineAssemblerTester<double> m(MachineType::Float64());
m.Return(m.Float64Expm1(m.Parameter(0)));
CHECK(std::isnan(m.Call(std::numeric_limits<double>::quiet_NaN())));
CHECK(std::isnan(m.Call(std::numeric_limits<double>::signaling_NaN())));
CHECK_EQ(-1.0, m.Call(-std::numeric_limits<double>::infinity()));
CHECK_DOUBLE_EQ(std::numeric_limits<double>::infinity(),
m.Call(std::numeric_limits<double>::infinity()));
FOR_FLOAT64_INPUTS(i) { CHECK_DOUBLE_EQ(ieee754::expm1(*i), m.Call(*i)); }
}
TEST(RunFloat64Log) {
BufferedRawMachineAssemblerTester<double> m(MachineType::Float64());
m.Return(m.Float64Log(m.Parameter(0)));
......@@ -5588,6 +5611,18 @@ TEST(RunFloat64Log10) {
FOR_FLOAT64_INPUTS(i) { CHECK_DOUBLE_EQ(ieee754::log10(*i), m.Call(*i)); }
}
TEST(RunFloat64Cbrt) {
BufferedRawMachineAssemblerTester<double> m(MachineType::Float64());
m.Return(m.Float64Cbrt(m.Parameter(0)));
CHECK(std::isnan(m.Call(std::numeric_limits<double>::quiet_NaN())));
CHECK(std::isnan(m.Call(std::numeric_limits<double>::signaling_NaN())));
CHECK_DOUBLE_EQ(std::numeric_limits<double>::infinity(),
m.Call(std::numeric_limits<double>::infinity()));
CHECK_DOUBLE_EQ(-std::numeric_limits<double>::infinity(),
m.Call(-std::numeric_limits<double>::infinity()));
FOR_FLOAT64_INPUTS(i) { CHECK_DOUBLE_EQ(ieee754::cbrt(*i), m.Call(*i)); }
}
static double two_30 = 1 << 30; // 2^30 is a smi boundary.
static double two_52 = two_30 * (1 << 22); // 2^52 is a precision boundary.
static double kValues[] = {0.1,
......
......@@ -54,6 +54,15 @@ TEST(Ieee754, Atan2) {
-std::numeric_limits<double>::infinity()));
}
TEST(Ieee754, Atanh) {
EXPECT_THAT(atanh(std::numeric_limits<double>::quiet_NaN()), IsNaN());
EXPECT_THAT(atanh(std::numeric_limits<double>::signaling_NaN()), IsNaN());
EXPECT_THAT(atanh(std::numeric_limits<double>::infinity()), IsNaN());
EXPECT_EQ(std::numeric_limits<double>::infinity(), atanh(1));
EXPECT_EQ(-std::numeric_limits<double>::infinity(), atanh(-1));
EXPECT_DOUBLE_EQ(0.54930614433405478, atanh(0.5));
}
TEST(Ieee754, Exp) {
EXPECT_THAT(exp(std::numeric_limits<double>::quiet_NaN()), IsNaN());
EXPECT_THAT(exp(std::numeric_limits<double>::signaling_NaN()), IsNaN());
......@@ -82,6 +91,20 @@ TEST(Ieee754, Exp) {
exp(std::numeric_limits<double>::infinity()));
}
TEST(Ieee754, Expm1) {
EXPECT_THAT(expm1(std::numeric_limits<double>::quiet_NaN()), IsNaN());
EXPECT_THAT(expm1(std::numeric_limits<double>::signaling_NaN()), IsNaN());
EXPECT_EQ(-1.0, expm1(-std::numeric_limits<double>::infinity()));
EXPECT_EQ(std::numeric_limits<double>::infinity(),
expm1(std::numeric_limits<double>::infinity()));
EXPECT_EQ(0.0, expm1(-0.0));
EXPECT_EQ(0.0, expm1(0.0));
EXPECT_EQ(1.718281828459045, expm1(1.0));
EXPECT_EQ(2.6881171418161356e+43, expm1(100.0));
EXPECT_EQ(8.218407461554972e+307, expm1(709.0));
EXPECT_EQ(std::numeric_limits<double>::infinity(), expm1(710.0));
}
TEST(Ieee754, Log) {
EXPECT_THAT(log(std::numeric_limits<double>::quiet_NaN()), IsNaN());
EXPECT_THAT(log(std::numeric_limits<double>::signaling_NaN()), IsNaN());
......@@ -146,6 +169,18 @@ TEST(Ieee754, Log10) {
EXPECT_EQ(-0.9083828622192334, log10(0.12348583358871));
}
TEST(Ieee754, cbrt) {
EXPECT_THAT(cbrt(std::numeric_limits<double>::quiet_NaN()), IsNaN());
EXPECT_THAT(cbrt(std::numeric_limits<double>::signaling_NaN()), IsNaN());
EXPECT_EQ(std::numeric_limits<double>::infinity(),
cbrt(std::numeric_limits<double>::infinity()));
EXPECT_EQ(-std::numeric_limits<double>::infinity(),
cbrt(-std::numeric_limits<double>::infinity()));
EXPECT_EQ(1.4422495703074083, cbrt(3));
EXPECT_EQ(100, cbrt(100 * 100 * 100));
EXPECT_EQ(46.415888336127786, cbrt(100000));
}
} // namespace ieee754
} // namespace base
} // namespace v8
......@@ -2311,9 +2311,11 @@ IS_UNOP_MATCHER(Float64RoundTiesAway)
IS_UNOP_MATCHER(Float64ExtractLowWord32)
IS_UNOP_MATCHER(Float64ExtractHighWord32)
IS_UNOP_MATCHER(NumberAtan)
IS_UNOP_MATCHER(NumberAtanh)
IS_UNOP_MATCHER(NumberCeil)
IS_UNOP_MATCHER(NumberClz32)
IS_UNOP_MATCHER(NumberExp)
IS_UNOP_MATCHER(NumberExpm1)
IS_UNOP_MATCHER(NumberFloor)
IS_UNOP_MATCHER(NumberFround)
IS_UNOP_MATCHER(NumberLog)
......@@ -2322,6 +2324,7 @@ IS_UNOP_MATCHER(NumberLog2)
IS_UNOP_MATCHER(NumberLog10)
IS_UNOP_MATCHER(NumberRound)
IS_UNOP_MATCHER(NumberSqrt)
IS_UNOP_MATCHER(NumberCbrt)
IS_UNOP_MATCHER(NumberTrunc)
IS_UNOP_MATCHER(NumberToInt32)
IS_UNOP_MATCHER(NumberToUint32)
......
......@@ -227,9 +227,11 @@ Matcher<Node*> IsNumberImul(const Matcher<Node*>& lhs_matcher,
Matcher<Node*> IsNumberAtan(const Matcher<Node*>& value_matcher);
Matcher<Node*> IsNumberAtan2(const Matcher<Node*>& lhs_matcher,
const Matcher<Node*>& rhs_matcher);
Matcher<Node*> IsNumberAtanh(const Matcher<Node*>& value_matcher);
Matcher<Node*> IsNumberCeil(const Matcher<Node*>& value_matcher);
Matcher<Node*> IsNumberClz32(const Matcher<Node*>& value_matcher);
Matcher<Node*> IsNumberExp(const Matcher<Node*>& value_matcher);
Matcher<Node*> IsNumberExpm1(const Matcher<Node*>& value_matcher);
Matcher<Node*> IsNumberFloor(const Matcher<Node*>& value_matcher);
Matcher<Node*> IsNumberFround(const Matcher<Node*>& value_matcher);
Matcher<Node*> IsNumberLog(const Matcher<Node*>& value_matcher);
......@@ -237,6 +239,7 @@ Matcher<Node*> IsNumberLog1p(const Matcher<Node*>& value_matcher);
Matcher<Node*> IsNumberLog2(const Matcher<Node*>& value_matcher);
Matcher<Node*> IsNumberLog10(const Matcher<Node*>& value_matcher);
Matcher<Node*> IsNumberRound(const Matcher<Node*>& value_matcher);
Matcher<Node*> IsNumberCbrt(const Matcher<Node*>& value_matcher);
Matcher<Node*> IsNumberSqrt(const Matcher<Node*>& value_matcher);
Matcher<Node*> IsNumberTrunc(const Matcher<Node*>& value_matcher);
Matcher<Node*> IsStringFromCharCode(const Matcher<Node*>& value_matcher);
......
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