2016-07-20 07:38:14 +00:00
|
|
|
// Copyright 2016 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "src/builtins/builtins-utils.h"
|
2016-10-06 15:46:11 +00:00
|
|
|
#include "src/builtins/builtins.h"
|
|
|
|
#include "src/code-factory.h"
|
2016-07-20 07:38:14 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// ES6 section 20.1 Number Objects
|
|
|
|
|
2016-09-07 10:14:19 +00:00
|
|
|
// ES6 section 20.1.2.2 Number.isFinite ( number )
|
2016-11-24 08:57:28 +00:00
|
|
|
void Builtins::Generate_NumberIsFinite(compiler::CodeAssemblerState* state) {
|
|
|
|
typedef CodeStubAssembler::Label Label;
|
|
|
|
typedef compiler::Node Node;
|
|
|
|
CodeStubAssembler assembler(state);
|
|
|
|
|
|
|
|
Node* number = assembler.Parameter(1);
|
2016-09-07 10:14:19 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
Label return_true(&assembler), return_false(&assembler);
|
2016-09-07 10:14:19 +00:00
|
|
|
|
|
|
|
// Check if {number} is a Smi.
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.GotoIf(assembler.TaggedIsSmi(number), &return_true);
|
2016-09-07 10:14:19 +00:00
|
|
|
|
|
|
|
// Check if {number} is a HeapNumber.
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.GotoUnless(assembler.WordEqual(assembler.LoadMap(number),
|
|
|
|
assembler.HeapNumberMapConstant()),
|
|
|
|
&return_false);
|
2016-09-07 10:14:19 +00:00
|
|
|
|
|
|
|
// Check if {number} contains a finite, non-NaN value.
|
2016-11-24 08:57:28 +00:00
|
|
|
Node* number_value = assembler.LoadHeapNumberValue(number);
|
|
|
|
assembler.BranchIfFloat64IsNaN(
|
|
|
|
assembler.Float64Sub(number_value, number_value), &return_false,
|
|
|
|
&return_true);
|
2016-09-07 10:14:19 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&return_true);
|
|
|
|
assembler.Return(assembler.BooleanConstant(true));
|
2016-09-07 10:14:19 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&return_false);
|
|
|
|
assembler.Return(assembler.BooleanConstant(false));
|
2016-09-07 10:14:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ES6 section 20.1.2.3 Number.isInteger ( number )
|
2016-11-24 08:57:28 +00:00
|
|
|
void Builtins::Generate_NumberIsInteger(compiler::CodeAssemblerState* state) {
|
|
|
|
typedef CodeStubAssembler::Label Label;
|
|
|
|
typedef compiler::Node Node;
|
|
|
|
CodeStubAssembler assembler(state);
|
2016-09-07 10:14:19 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
Node* number = assembler.Parameter(1);
|
|
|
|
|
|
|
|
Label return_true(&assembler), return_false(&assembler);
|
2016-09-07 10:14:19 +00:00
|
|
|
|
|
|
|
// Check if {number} is a Smi.
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.GotoIf(assembler.TaggedIsSmi(number), &return_true);
|
2016-09-07 10:14:19 +00:00
|
|
|
|
|
|
|
// Check if {number} is a HeapNumber.
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.GotoUnless(assembler.WordEqual(assembler.LoadMap(number),
|
|
|
|
assembler.HeapNumberMapConstant()),
|
|
|
|
&return_false);
|
2016-09-07 10:14:19 +00:00
|
|
|
|
|
|
|
// Load the actual value of {number}.
|
2016-11-24 08:57:28 +00:00
|
|
|
Node* number_value = assembler.LoadHeapNumberValue(number);
|
2016-09-07 10:14:19 +00:00
|
|
|
|
|
|
|
// Truncate the value of {number} to an integer (or an infinity).
|
2016-11-24 08:57:28 +00:00
|
|
|
Node* integer = assembler.Float64Trunc(number_value);
|
2016-09-07 10:14:19 +00:00
|
|
|
|
|
|
|
// Check if {number}s value matches the integer (ruling out the infinities).
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Branch(
|
|
|
|
assembler.Float64Equal(assembler.Float64Sub(number_value, integer),
|
|
|
|
assembler.Float64Constant(0.0)),
|
|
|
|
&return_true, &return_false);
|
2016-09-07 10:14:19 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&return_true);
|
|
|
|
assembler.Return(assembler.BooleanConstant(true));
|
2016-09-07 10:14:19 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&return_false);
|
|
|
|
assembler.Return(assembler.BooleanConstant(false));
|
2016-09-07 10:14:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ES6 section 20.1.2.4 Number.isNaN ( number )
|
2016-11-24 08:57:28 +00:00
|
|
|
void Builtins::Generate_NumberIsNaN(compiler::CodeAssemblerState* state) {
|
|
|
|
typedef CodeStubAssembler::Label Label;
|
|
|
|
typedef compiler::Node Node;
|
|
|
|
CodeStubAssembler assembler(state);
|
|
|
|
|
|
|
|
Node* number = assembler.Parameter(1);
|
2016-09-07 10:14:19 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
Label return_true(&assembler), return_false(&assembler);
|
2016-09-07 10:14:19 +00:00
|
|
|
|
|
|
|
// Check if {number} is a Smi.
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.GotoIf(assembler.TaggedIsSmi(number), &return_false);
|
2016-09-07 10:14:19 +00:00
|
|
|
|
|
|
|
// Check if {number} is a HeapNumber.
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.GotoUnless(assembler.WordEqual(assembler.LoadMap(number),
|
|
|
|
assembler.HeapNumberMapConstant()),
|
|
|
|
&return_false);
|
2016-09-07 10:14:19 +00:00
|
|
|
|
|
|
|
// Check if {number} contains a NaN value.
|
2016-11-24 08:57:28 +00:00
|
|
|
Node* number_value = assembler.LoadHeapNumberValue(number);
|
|
|
|
assembler.BranchIfFloat64IsNaN(number_value, &return_true, &return_false);
|
2016-09-07 10:14:19 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&return_true);
|
|
|
|
assembler.Return(assembler.BooleanConstant(true));
|
2016-09-07 10:14:19 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&return_false);
|
|
|
|
assembler.Return(assembler.BooleanConstant(false));
|
2016-09-07 10:14:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ES6 section 20.1.2.5 Number.isSafeInteger ( number )
|
2016-11-24 08:57:28 +00:00
|
|
|
void Builtins::Generate_NumberIsSafeInteger(
|
|
|
|
compiler::CodeAssemblerState* state) {
|
|
|
|
typedef CodeStubAssembler::Label Label;
|
|
|
|
typedef compiler::Node Node;
|
|
|
|
CodeStubAssembler assembler(state);
|
2016-09-07 10:14:19 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
Node* number = assembler.Parameter(1);
|
|
|
|
|
|
|
|
Label return_true(&assembler), return_false(&assembler);
|
2016-09-07 10:14:19 +00:00
|
|
|
|
|
|
|
// Check if {number} is a Smi.
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.GotoIf(assembler.TaggedIsSmi(number), &return_true);
|
2016-09-07 10:14:19 +00:00
|
|
|
|
|
|
|
// Check if {number} is a HeapNumber.
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.GotoUnless(assembler.WordEqual(assembler.LoadMap(number),
|
|
|
|
assembler.HeapNumberMapConstant()),
|
|
|
|
&return_false);
|
2016-09-07 10:14:19 +00:00
|
|
|
|
|
|
|
// Load the actual value of {number}.
|
2016-11-24 08:57:28 +00:00
|
|
|
Node* number_value = assembler.LoadHeapNumberValue(number);
|
2016-09-07 10:14:19 +00:00
|
|
|
|
|
|
|
// Truncate the value of {number} to an integer (or an infinity).
|
2016-11-24 08:57:28 +00:00
|
|
|
Node* integer = assembler.Float64Trunc(number_value);
|
2016-09-07 10:14:19 +00:00
|
|
|
|
|
|
|
// Check if {number}s value matches the integer (ruling out the infinities).
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.GotoUnless(
|
|
|
|
assembler.Float64Equal(assembler.Float64Sub(number_value, integer),
|
|
|
|
assembler.Float64Constant(0.0)),
|
2016-09-07 10:14:19 +00:00
|
|
|
&return_false);
|
|
|
|
|
|
|
|
// Check if the {integer} value is in safe integer range.
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Branch(assembler.Float64LessThanOrEqual(
|
|
|
|
assembler.Float64Abs(integer),
|
|
|
|
assembler.Float64Constant(kMaxSafeInteger)),
|
|
|
|
&return_true, &return_false);
|
2016-09-07 10:14:19 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&return_true);
|
|
|
|
assembler.Return(assembler.BooleanConstant(true));
|
2016-09-07 10:14:19 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&return_false);
|
|
|
|
assembler.Return(assembler.BooleanConstant(false));
|
2016-09-07 10:14:19 +00:00
|
|
|
}
|
|
|
|
|
2016-10-07 08:58:43 +00:00
|
|
|
// ES6 section 20.1.2.12 Number.parseFloat ( string )
|
2016-11-24 08:57:28 +00:00
|
|
|
void Builtins::Generate_NumberParseFloat(compiler::CodeAssemblerState* state) {
|
|
|
|
typedef CodeStubAssembler::Label Label;
|
|
|
|
typedef compiler::Node Node;
|
|
|
|
typedef CodeStubAssembler::Variable Variable;
|
|
|
|
CodeStubAssembler assembler(state);
|
|
|
|
|
|
|
|
Node* context = assembler.Parameter(4);
|
2016-10-07 08:58:43 +00:00
|
|
|
|
|
|
|
// We might need to loop once for ToString conversion.
|
2016-11-24 08:57:28 +00:00
|
|
|
Variable var_input(&assembler, MachineRepresentation::kTagged);
|
|
|
|
Label loop(&assembler, &var_input);
|
|
|
|
var_input.Bind(assembler.Parameter(1));
|
|
|
|
assembler.Goto(&loop);
|
|
|
|
assembler.Bind(&loop);
|
2016-10-07 08:58:43 +00:00
|
|
|
{
|
|
|
|
// Load the current {input} value.
|
|
|
|
Node* input = var_input.value();
|
|
|
|
|
|
|
|
// Check if the {input} is a HeapObject or a Smi.
|
2016-11-24 08:57:28 +00:00
|
|
|
Label if_inputissmi(&assembler), if_inputisnotsmi(&assembler);
|
|
|
|
assembler.Branch(assembler.TaggedIsSmi(input), &if_inputissmi,
|
|
|
|
&if_inputisnotsmi);
|
2016-10-07 08:58:43 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&if_inputissmi);
|
2016-10-07 08:58:43 +00:00
|
|
|
{
|
|
|
|
// The {input} is already a Number, no need to do anything.
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Return(input);
|
2016-10-07 08:58:43 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&if_inputisnotsmi);
|
2016-10-07 08:58:43 +00:00
|
|
|
{
|
|
|
|
// The {input} is a HeapObject, check if it's already a String.
|
2016-11-24 08:57:28 +00:00
|
|
|
Label if_inputisstring(&assembler), if_inputisnotstring(&assembler);
|
|
|
|
Node* input_map = assembler.LoadMap(input);
|
|
|
|
Node* input_instance_type = assembler.LoadMapInstanceType(input_map);
|
|
|
|
assembler.Branch(assembler.IsStringInstanceType(input_instance_type),
|
|
|
|
&if_inputisstring, &if_inputisnotstring);
|
2016-10-07 08:58:43 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&if_inputisstring);
|
2016-10-07 08:58:43 +00:00
|
|
|
{
|
|
|
|
// The {input} is already a String, check if {input} contains
|
|
|
|
// a cached array index.
|
2016-11-24 08:57:28 +00:00
|
|
|
Label if_inputcached(&assembler), if_inputnotcached(&assembler);
|
|
|
|
Node* input_hash = assembler.LoadNameHashField(input);
|
|
|
|
Node* input_bit = assembler.Word32And(
|
|
|
|
input_hash,
|
|
|
|
assembler.Int32Constant(String::kContainsCachedArrayIndexMask));
|
|
|
|
assembler.Branch(
|
|
|
|
assembler.Word32Equal(input_bit, assembler.Int32Constant(0)),
|
|
|
|
&if_inputcached, &if_inputnotcached);
|
|
|
|
|
|
|
|
assembler.Bind(&if_inputcached);
|
2016-10-07 08:58:43 +00:00
|
|
|
{
|
|
|
|
// Just return the {input}s cached array index.
|
|
|
|
Node* input_array_index =
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.DecodeWordFromWord32<String::ArrayIndexValueBits>(
|
|
|
|
input_hash);
|
|
|
|
assembler.Return(assembler.SmiTag(input_array_index));
|
2016-10-07 08:58:43 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&if_inputnotcached);
|
2016-10-07 08:58:43 +00:00
|
|
|
{
|
|
|
|
// Need to fall back to the runtime to convert {input} to double.
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Return(assembler.CallRuntime(Runtime::kStringParseFloat,
|
|
|
|
context, input));
|
2016-10-07 08:58:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&if_inputisnotstring);
|
2016-10-07 08:58:43 +00:00
|
|
|
{
|
|
|
|
// The {input} is neither a String nor a Smi, check for HeapNumber.
|
2016-11-24 08:57:28 +00:00
|
|
|
Label if_inputisnumber(&assembler),
|
|
|
|
if_inputisnotnumber(&assembler, Label::kDeferred);
|
|
|
|
assembler.Branch(
|
|
|
|
assembler.WordEqual(input_map, assembler.HeapNumberMapConstant()),
|
|
|
|
&if_inputisnumber, &if_inputisnotnumber);
|
2016-10-07 08:58:43 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&if_inputisnumber);
|
2016-10-07 08:58:43 +00:00
|
|
|
{
|
|
|
|
// The {input} is already a Number, take care of -0.
|
2016-11-24 08:57:28 +00:00
|
|
|
Label if_inputiszero(&assembler), if_inputisnotzero(&assembler);
|
|
|
|
Node* input_value = assembler.LoadHeapNumberValue(input);
|
|
|
|
assembler.Branch(assembler.Float64Equal(
|
|
|
|
input_value, assembler.Float64Constant(0.0)),
|
|
|
|
&if_inputiszero, &if_inputisnotzero);
|
2016-10-07 08:58:43 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&if_inputiszero);
|
|
|
|
assembler.Return(assembler.SmiConstant(0));
|
2016-10-07 08:58:43 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&if_inputisnotzero);
|
|
|
|
assembler.Return(input);
|
2016-10-07 08:58:43 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&if_inputisnotnumber);
|
2016-10-07 08:58:43 +00:00
|
|
|
{
|
|
|
|
// Need to convert the {input} to String first.
|
|
|
|
// TODO(bmeurer): This could be more efficient if necessary.
|
2016-11-24 08:57:28 +00:00
|
|
|
Callable callable = CodeFactory::ToString(assembler.isolate());
|
|
|
|
var_input.Bind(assembler.CallStub(callable, context, input));
|
|
|
|
assembler.Goto(&loop);
|
2016-10-07 08:58:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-18 12:44:48 +00:00
|
|
|
// ES6 section 20.1.2.13 Number.parseInt ( string, radix )
|
2016-11-24 08:57:28 +00:00
|
|
|
void Builtins::Generate_NumberParseInt(compiler::CodeAssemblerState* state) {
|
|
|
|
typedef CodeStubAssembler::Label Label;
|
|
|
|
typedef compiler::Node Node;
|
|
|
|
CodeStubAssembler assembler(state);
|
2016-10-18 12:44:48 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
Node* input = assembler.Parameter(1);
|
|
|
|
Node* radix = assembler.Parameter(2);
|
|
|
|
Node* context = assembler.Parameter(5);
|
2016-11-24 00:41:19 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
// Check if {radix} is treated as 10 (i.e. undefined, 0 or 10).
|
|
|
|
Label if_radix10(&assembler), if_generic(&assembler, Label::kDeferred);
|
|
|
|
assembler.GotoIf(assembler.WordEqual(radix, assembler.UndefinedConstant()),
|
|
|
|
&if_radix10);
|
|
|
|
assembler.GotoIf(
|
|
|
|
assembler.WordEqual(radix, assembler.SmiConstant(Smi::FromInt(10))),
|
|
|
|
&if_radix10);
|
|
|
|
assembler.GotoIf(
|
|
|
|
assembler.WordEqual(radix, assembler.SmiConstant(Smi::FromInt(0))),
|
|
|
|
&if_radix10);
|
|
|
|
assembler.Goto(&if_generic);
|
|
|
|
|
|
|
|
assembler.Bind(&if_radix10);
|
2016-10-18 12:44:48 +00:00
|
|
|
{
|
|
|
|
// Check if we can avoid the ToString conversion on {input}.
|
2016-11-24 08:57:28 +00:00
|
|
|
Label if_inputissmi(&assembler), if_inputisheapnumber(&assembler),
|
|
|
|
if_inputisstring(&assembler);
|
|
|
|
assembler.GotoIf(assembler.TaggedIsSmi(input), &if_inputissmi);
|
|
|
|
Node* input_map = assembler.LoadMap(input);
|
|
|
|
assembler.GotoIf(
|
|
|
|
assembler.WordEqual(input_map, assembler.HeapNumberMapConstant()),
|
|
|
|
&if_inputisheapnumber);
|
|
|
|
Node* input_instance_type = assembler.LoadMapInstanceType(input_map);
|
|
|
|
assembler.Branch(assembler.IsStringInstanceType(input_instance_type),
|
|
|
|
&if_inputisstring, &if_generic);
|
|
|
|
|
|
|
|
assembler.Bind(&if_inputissmi);
|
2016-10-18 12:44:48 +00:00
|
|
|
{
|
|
|
|
// Just return the {input}.
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Return(input);
|
2016-10-18 12:44:48 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&if_inputisheapnumber);
|
2016-10-18 12:44:48 +00:00
|
|
|
{
|
2016-10-19 05:41:05 +00:00
|
|
|
// Check if the {input} value is in Signed32 range.
|
2016-11-24 08:57:28 +00:00
|
|
|
Label if_inputissigned32(&assembler);
|
|
|
|
Node* input_value = assembler.LoadHeapNumberValue(input);
|
|
|
|
Node* input_value32 = assembler.TruncateFloat64ToWord32(input_value);
|
|
|
|
assembler.GotoIf(
|
|
|
|
assembler.Float64Equal(input_value,
|
|
|
|
assembler.ChangeInt32ToFloat64(input_value32)),
|
|
|
|
&if_inputissigned32);
|
2016-10-19 05:41:05 +00:00
|
|
|
|
|
|
|
// Check if the absolute {input} value is in the ]0.01,1e9[ range.
|
2016-11-24 08:57:28 +00:00
|
|
|
Node* input_value_abs = assembler.Float64Abs(input_value);
|
2016-10-18 12:44:48 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.GotoUnless(assembler.Float64LessThan(
|
|
|
|
input_value_abs, assembler.Float64Constant(1e9)),
|
|
|
|
&if_generic);
|
|
|
|
assembler.Branch(assembler.Float64LessThan(
|
|
|
|
assembler.Float64Constant(0.01), input_value_abs),
|
|
|
|
&if_inputissigned32, &if_generic);
|
2016-10-18 12:44:48 +00:00
|
|
|
|
|
|
|
// Return the truncated int32 value, and return the tagged result.
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&if_inputissigned32);
|
|
|
|
Node* result = assembler.ChangeInt32ToTagged(input_value32);
|
|
|
|
assembler.Return(result);
|
2016-10-18 12:44:48 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&if_inputisstring);
|
2016-10-18 12:44:48 +00:00
|
|
|
{
|
|
|
|
// Check if the String {input} has a cached array index.
|
2016-11-24 08:57:28 +00:00
|
|
|
Node* input_hash = assembler.LoadNameHashField(input);
|
|
|
|
Node* input_bit = assembler.Word32And(
|
|
|
|
input_hash,
|
|
|
|
assembler.Int32Constant(String::kContainsCachedArrayIndexMask));
|
|
|
|
assembler.GotoIf(
|
|
|
|
assembler.Word32NotEqual(input_bit, assembler.Int32Constant(0)),
|
|
|
|
&if_generic);
|
2016-10-18 12:44:48 +00:00
|
|
|
|
|
|
|
// Return the cached array index as result.
|
|
|
|
Node* input_index =
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.DecodeWordFromWord32<String::ArrayIndexValueBits>(
|
|
|
|
input_hash);
|
|
|
|
Node* result = assembler.SmiTag(input_index);
|
|
|
|
assembler.Return(result);
|
2016-10-18 12:44:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&if_generic);
|
2016-10-18 12:44:48 +00:00
|
|
|
{
|
2016-11-24 08:57:28 +00:00
|
|
|
Node* result =
|
|
|
|
assembler.CallRuntime(Runtime::kStringParseInt, context, input, radix);
|
|
|
|
assembler.Return(result);
|
2016-10-18 12:44:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-20 07:38:14 +00:00
|
|
|
// ES6 section 20.1.3.2 Number.prototype.toExponential ( fractionDigits )
|
|
|
|
BUILTIN(NumberPrototypeToExponential) {
|
|
|
|
HandleScope scope(isolate);
|
|
|
|
Handle<Object> value = args.at<Object>(0);
|
|
|
|
Handle<Object> fraction_digits = args.atOrUndefined(isolate, 1);
|
|
|
|
|
|
|
|
// Unwrap the receiver {value}.
|
|
|
|
if (value->IsJSValue()) {
|
|
|
|
value = handle(Handle<JSValue>::cast(value)->value(), isolate);
|
|
|
|
}
|
|
|
|
if (!value->IsNumber()) {
|
|
|
|
THROW_NEW_ERROR_RETURN_FAILURE(
|
|
|
|
isolate, NewTypeError(MessageTemplate::kNotGeneric,
|
|
|
|
isolate->factory()->NewStringFromAsciiChecked(
|
|
|
|
"Number.prototype.toExponential")));
|
|
|
|
}
|
|
|
|
double const value_number = value->Number();
|
|
|
|
|
|
|
|
// Convert the {fraction_digits} to an integer first.
|
|
|
|
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
|
|
|
|
isolate, fraction_digits, Object::ToInteger(isolate, fraction_digits));
|
|
|
|
double const fraction_digits_number = fraction_digits->Number();
|
|
|
|
|
|
|
|
if (std::isnan(value_number)) return isolate->heap()->nan_string();
|
|
|
|
if (std::isinf(value_number)) {
|
|
|
|
return (value_number < 0.0) ? isolate->heap()->minus_infinity_string()
|
|
|
|
: isolate->heap()->infinity_string();
|
|
|
|
}
|
|
|
|
if (fraction_digits_number < 0.0 || fraction_digits_number > 20.0) {
|
|
|
|
THROW_NEW_ERROR_RETURN_FAILURE(
|
|
|
|
isolate, NewRangeError(MessageTemplate::kNumberFormatRange,
|
|
|
|
isolate->factory()->NewStringFromAsciiChecked(
|
|
|
|
"toExponential()")));
|
|
|
|
}
|
|
|
|
int const f = args.atOrUndefined(isolate, 1)->IsUndefined(isolate)
|
|
|
|
? -1
|
|
|
|
: static_cast<int>(fraction_digits_number);
|
|
|
|
char* const str = DoubleToExponentialCString(value_number, f);
|
|
|
|
Handle<String> result = isolate->factory()->NewStringFromAsciiChecked(str);
|
|
|
|
DeleteArray(str);
|
|
|
|
return *result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ES6 section 20.1.3.3 Number.prototype.toFixed ( fractionDigits )
|
|
|
|
BUILTIN(NumberPrototypeToFixed) {
|
|
|
|
HandleScope scope(isolate);
|
|
|
|
Handle<Object> value = args.at<Object>(0);
|
|
|
|
Handle<Object> fraction_digits = args.atOrUndefined(isolate, 1);
|
|
|
|
|
|
|
|
// Unwrap the receiver {value}.
|
|
|
|
if (value->IsJSValue()) {
|
|
|
|
value = handle(Handle<JSValue>::cast(value)->value(), isolate);
|
|
|
|
}
|
|
|
|
if (!value->IsNumber()) {
|
|
|
|
THROW_NEW_ERROR_RETURN_FAILURE(
|
|
|
|
isolate, NewTypeError(MessageTemplate::kNotGeneric,
|
|
|
|
isolate->factory()->NewStringFromAsciiChecked(
|
|
|
|
"Number.prototype.toFixed")));
|
|
|
|
}
|
|
|
|
double const value_number = value->Number();
|
|
|
|
|
|
|
|
// Convert the {fraction_digits} to an integer first.
|
|
|
|
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
|
|
|
|
isolate, fraction_digits, Object::ToInteger(isolate, fraction_digits));
|
|
|
|
double const fraction_digits_number = fraction_digits->Number();
|
|
|
|
|
|
|
|
// Check if the {fraction_digits} are in the supported range.
|
|
|
|
if (fraction_digits_number < 0.0 || fraction_digits_number > 20.0) {
|
|
|
|
THROW_NEW_ERROR_RETURN_FAILURE(
|
|
|
|
isolate, NewRangeError(MessageTemplate::kNumberFormatRange,
|
|
|
|
isolate->factory()->NewStringFromAsciiChecked(
|
|
|
|
"toFixed() digits")));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (std::isnan(value_number)) return isolate->heap()->nan_string();
|
|
|
|
if (std::isinf(value_number)) {
|
|
|
|
return (value_number < 0.0) ? isolate->heap()->minus_infinity_string()
|
|
|
|
: isolate->heap()->infinity_string();
|
|
|
|
}
|
|
|
|
char* const str = DoubleToFixedCString(
|
|
|
|
value_number, static_cast<int>(fraction_digits_number));
|
|
|
|
Handle<String> result = isolate->factory()->NewStringFromAsciiChecked(str);
|
|
|
|
DeleteArray(str);
|
|
|
|
return *result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ES6 section 20.1.3.4 Number.prototype.toLocaleString ( [ r1 [ , r2 ] ] )
|
|
|
|
BUILTIN(NumberPrototypeToLocaleString) {
|
|
|
|
HandleScope scope(isolate);
|
|
|
|
Handle<Object> value = args.at<Object>(0);
|
|
|
|
|
|
|
|
// Unwrap the receiver {value}.
|
|
|
|
if (value->IsJSValue()) {
|
|
|
|
value = handle(Handle<JSValue>::cast(value)->value(), isolate);
|
|
|
|
}
|
|
|
|
if (!value->IsNumber()) {
|
|
|
|
THROW_NEW_ERROR_RETURN_FAILURE(
|
|
|
|
isolate, NewTypeError(MessageTemplate::kNotGeneric,
|
|
|
|
isolate->factory()->NewStringFromAsciiChecked(
|
|
|
|
"Number.prototype.toLocaleString")));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Turn the {value} into a String.
|
|
|
|
return *isolate->factory()->NumberToString(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ES6 section 20.1.3.5 Number.prototype.toPrecision ( precision )
|
|
|
|
BUILTIN(NumberPrototypeToPrecision) {
|
|
|
|
HandleScope scope(isolate);
|
|
|
|
Handle<Object> value = args.at<Object>(0);
|
|
|
|
Handle<Object> precision = args.atOrUndefined(isolate, 1);
|
|
|
|
|
|
|
|
// Unwrap the receiver {value}.
|
|
|
|
if (value->IsJSValue()) {
|
|
|
|
value = handle(Handle<JSValue>::cast(value)->value(), isolate);
|
|
|
|
}
|
|
|
|
if (!value->IsNumber()) {
|
|
|
|
THROW_NEW_ERROR_RETURN_FAILURE(
|
|
|
|
isolate, NewTypeError(MessageTemplate::kNotGeneric,
|
|
|
|
isolate->factory()->NewStringFromAsciiChecked(
|
|
|
|
"Number.prototype.toPrecision")));
|
|
|
|
}
|
|
|
|
double const value_number = value->Number();
|
|
|
|
|
|
|
|
// If no {precision} was specified, just return ToString of {value}.
|
|
|
|
if (precision->IsUndefined(isolate)) {
|
|
|
|
return *isolate->factory()->NumberToString(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convert the {precision} to an integer first.
|
|
|
|
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, precision,
|
|
|
|
Object::ToInteger(isolate, precision));
|
|
|
|
double const precision_number = precision->Number();
|
|
|
|
|
|
|
|
if (std::isnan(value_number)) return isolate->heap()->nan_string();
|
|
|
|
if (std::isinf(value_number)) {
|
|
|
|
return (value_number < 0.0) ? isolate->heap()->minus_infinity_string()
|
|
|
|
: isolate->heap()->infinity_string();
|
|
|
|
}
|
|
|
|
if (precision_number < 1.0 || precision_number > 21.0) {
|
|
|
|
THROW_NEW_ERROR_RETURN_FAILURE(
|
|
|
|
isolate, NewRangeError(MessageTemplate::kToPrecisionFormatRange));
|
|
|
|
}
|
|
|
|
char* const str = DoubleToPrecisionCString(
|
|
|
|
value_number, static_cast<int>(precision_number));
|
|
|
|
Handle<String> result = isolate->factory()->NewStringFromAsciiChecked(str);
|
|
|
|
DeleteArray(str);
|
|
|
|
return *result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ES6 section 20.1.3.6 Number.prototype.toString ( [ radix ] )
|
|
|
|
BUILTIN(NumberPrototypeToString) {
|
|
|
|
HandleScope scope(isolate);
|
|
|
|
Handle<Object> value = args.at<Object>(0);
|
|
|
|
Handle<Object> radix = args.atOrUndefined(isolate, 1);
|
|
|
|
|
|
|
|
// Unwrap the receiver {value}.
|
|
|
|
if (value->IsJSValue()) {
|
|
|
|
value = handle(Handle<JSValue>::cast(value)->value(), isolate);
|
|
|
|
}
|
|
|
|
if (!value->IsNumber()) {
|
|
|
|
THROW_NEW_ERROR_RETURN_FAILURE(
|
|
|
|
isolate, NewTypeError(MessageTemplate::kNotGeneric,
|
|
|
|
isolate->factory()->NewStringFromAsciiChecked(
|
|
|
|
"Number.prototype.toString")));
|
|
|
|
}
|
|
|
|
double const value_number = value->Number();
|
|
|
|
|
|
|
|
// If no {radix} was specified, just return ToString of {value}.
|
|
|
|
if (radix->IsUndefined(isolate)) {
|
|
|
|
return *isolate->factory()->NumberToString(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convert the {radix} to an integer first.
|
|
|
|
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, radix,
|
|
|
|
Object::ToInteger(isolate, radix));
|
|
|
|
double const radix_number = radix->Number();
|
|
|
|
|
|
|
|
// If {radix} is 10, just return ToString of {value}.
|
|
|
|
if (radix_number == 10.0) return *isolate->factory()->NumberToString(value);
|
|
|
|
|
|
|
|
// Make sure the {radix} is within the valid range.
|
|
|
|
if (radix_number < 2.0 || radix_number > 36.0) {
|
|
|
|
THROW_NEW_ERROR_RETURN_FAILURE(
|
|
|
|
isolate, NewRangeError(MessageTemplate::kToRadixFormatRange));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fast case where the result is a one character string.
|
|
|
|
if (IsUint32Double(value_number) && value_number < radix_number) {
|
|
|
|
// Character array used for conversion.
|
|
|
|
static const char kCharTable[] = "0123456789abcdefghijklmnopqrstuvwxyz";
|
|
|
|
return *isolate->factory()->LookupSingleCharacterStringFromCode(
|
|
|
|
kCharTable[static_cast<uint32_t>(value_number)]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Slow case.
|
|
|
|
if (std::isnan(value_number)) return isolate->heap()->nan_string();
|
|
|
|
if (std::isinf(value_number)) {
|
|
|
|
return (value_number < 0.0) ? isolate->heap()->minus_infinity_string()
|
|
|
|
: isolate->heap()->infinity_string();
|
|
|
|
}
|
|
|
|
char* const str =
|
|
|
|
DoubleToRadixCString(value_number, static_cast<int>(radix_number));
|
|
|
|
Handle<String> result = isolate->factory()->NewStringFromAsciiChecked(str);
|
|
|
|
DeleteArray(str);
|
|
|
|
return *result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ES6 section 20.1.3.7 Number.prototype.valueOf ( )
|
2016-11-24 08:57:28 +00:00
|
|
|
void Builtins::Generate_NumberPrototypeValueOf(
|
|
|
|
compiler::CodeAssemblerState* state) {
|
|
|
|
typedef compiler::Node Node;
|
|
|
|
CodeStubAssembler assembler(state);
|
|
|
|
|
|
|
|
Node* receiver = assembler.Parameter(0);
|
|
|
|
Node* context = assembler.Parameter(3);
|
2016-07-20 07:38:14 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
Node* result = assembler.ToThisValue(
|
|
|
|
context, receiver, PrimitiveType::kNumber, "Number.prototype.valueOf");
|
|
|
|
assembler.Return(result);
|
2016-07-20 07:38:14 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
// static
|
|
|
|
void Builtins::Generate_Add(compiler::CodeAssemblerState* state) {
|
|
|
|
typedef CodeStubAssembler::Label Label;
|
|
|
|
typedef compiler::Node Node;
|
|
|
|
typedef CodeStubAssembler::Variable Variable;
|
|
|
|
CodeStubAssembler assembler(state);
|
|
|
|
|
|
|
|
Node* left = assembler.Parameter(0);
|
|
|
|
Node* right = assembler.Parameter(1);
|
|
|
|
Node* context = assembler.Parameter(2);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
|
|
|
// Shared entry for floating point addition.
|
2016-11-24 08:57:28 +00:00
|
|
|
Label do_fadd(&assembler);
|
|
|
|
Variable var_fadd_lhs(&assembler, MachineRepresentation::kFloat64),
|
|
|
|
var_fadd_rhs(&assembler, MachineRepresentation::kFloat64);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
|
|
|
// We might need to loop several times due to ToPrimitive, ToString and/or
|
|
|
|
// ToNumber conversions.
|
2016-11-24 08:57:28 +00:00
|
|
|
Variable var_lhs(&assembler, MachineRepresentation::kTagged),
|
|
|
|
var_rhs(&assembler, MachineRepresentation::kTagged),
|
|
|
|
var_result(&assembler, MachineRepresentation::kTagged);
|
2016-10-06 15:46:11 +00:00
|
|
|
Variable* loop_vars[2] = {&var_lhs, &var_rhs};
|
2016-11-24 08:57:28 +00:00
|
|
|
Label loop(&assembler, 2, loop_vars), end(&assembler),
|
|
|
|
string_add_convert_left(&assembler, Label::kDeferred),
|
|
|
|
string_add_convert_right(&assembler, Label::kDeferred);
|
2016-10-06 15:46:11 +00:00
|
|
|
var_lhs.Bind(left);
|
|
|
|
var_rhs.Bind(right);
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Goto(&loop);
|
|
|
|
assembler.Bind(&loop);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Load the current {lhs} and {rhs} values.
|
|
|
|
Node* lhs = var_lhs.value();
|
|
|
|
Node* rhs = var_rhs.value();
|
|
|
|
|
|
|
|
// Check if the {lhs} is a Smi or a HeapObject.
|
2016-11-24 08:57:28 +00:00
|
|
|
Label if_lhsissmi(&assembler), if_lhsisnotsmi(&assembler);
|
|
|
|
assembler.Branch(assembler.TaggedIsSmi(lhs), &if_lhsissmi, &if_lhsisnotsmi);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&if_lhsissmi);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Check if the {rhs} is also a Smi.
|
2016-11-24 08:57:28 +00:00
|
|
|
Label if_rhsissmi(&assembler), if_rhsisnotsmi(&assembler);
|
|
|
|
assembler.Branch(assembler.TaggedIsSmi(rhs), &if_rhsissmi,
|
|
|
|
&if_rhsisnotsmi);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&if_rhsissmi);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Try fast Smi addition first.
|
2016-11-24 08:57:28 +00:00
|
|
|
Node* pair =
|
|
|
|
assembler.IntPtrAddWithOverflow(assembler.BitcastTaggedToWord(lhs),
|
|
|
|
assembler.BitcastTaggedToWord(rhs));
|
|
|
|
Node* overflow = assembler.Projection(1, pair);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
|
|
|
// Check if the Smi additon overflowed.
|
2016-11-24 08:57:28 +00:00
|
|
|
Label if_overflow(&assembler), if_notoverflow(&assembler);
|
|
|
|
assembler.Branch(overflow, &if_overflow, &if_notoverflow);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&if_overflow);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
2016-11-24 08:57:28 +00:00
|
|
|
var_fadd_lhs.Bind(assembler.SmiToFloat64(lhs));
|
|
|
|
var_fadd_rhs.Bind(assembler.SmiToFloat64(rhs));
|
|
|
|
assembler.Goto(&do_fadd);
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&if_notoverflow);
|
|
|
|
var_result.Bind(
|
|
|
|
assembler.BitcastWordToTaggedSigned(assembler.Projection(0, pair)));
|
|
|
|
assembler.Goto(&end);
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&if_rhsisnotsmi);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Load the map of {rhs}.
|
2016-11-24 08:57:28 +00:00
|
|
|
Node* rhs_map = assembler.LoadMap(rhs);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
|
|
|
// Check if the {rhs} is a HeapNumber.
|
2016-11-24 08:57:28 +00:00
|
|
|
Label if_rhsisnumber(&assembler),
|
|
|
|
if_rhsisnotnumber(&assembler, Label::kDeferred);
|
|
|
|
assembler.Branch(assembler.IsHeapNumberMap(rhs_map), &if_rhsisnumber,
|
|
|
|
&if_rhsisnotnumber);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&if_rhsisnumber);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
2016-11-24 08:57:28 +00:00
|
|
|
var_fadd_lhs.Bind(assembler.SmiToFloat64(lhs));
|
|
|
|
var_fadd_rhs.Bind(assembler.LoadHeapNumberValue(rhs));
|
|
|
|
assembler.Goto(&do_fadd);
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&if_rhsisnotnumber);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Load the instance type of {rhs}.
|
2016-11-24 08:57:28 +00:00
|
|
|
Node* rhs_instance_type = assembler.LoadMapInstanceType(rhs_map);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
|
|
|
// Check if the {rhs} is a String.
|
2016-11-24 08:57:28 +00:00
|
|
|
Label if_rhsisstring(&assembler, Label::kDeferred),
|
|
|
|
if_rhsisnotstring(&assembler, Label::kDeferred);
|
|
|
|
assembler.Branch(assembler.IsStringInstanceType(rhs_instance_type),
|
|
|
|
&if_rhsisstring, &if_rhsisnotstring);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&if_rhsisstring);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
var_lhs.Bind(lhs);
|
|
|
|
var_rhs.Bind(rhs);
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Goto(&string_add_convert_left);
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&if_rhsisnotstring);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Check if {rhs} is a JSReceiver.
|
2016-11-24 08:57:28 +00:00
|
|
|
Label if_rhsisreceiver(&assembler, Label::kDeferred),
|
|
|
|
if_rhsisnotreceiver(&assembler, Label::kDeferred);
|
|
|
|
assembler.Branch(
|
|
|
|
assembler.IsJSReceiverInstanceType(rhs_instance_type),
|
|
|
|
&if_rhsisreceiver, &if_rhsisnotreceiver);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&if_rhsisreceiver);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Convert {rhs} to a primitive first passing no hint.
|
|
|
|
Callable callable =
|
2016-11-24 08:57:28 +00:00
|
|
|
CodeFactory::NonPrimitiveToPrimitive(assembler.isolate());
|
|
|
|
var_rhs.Bind(assembler.CallStub(callable, context, rhs));
|
|
|
|
assembler.Goto(&loop);
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&if_rhsisnotreceiver);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Convert {rhs} to a Number first.
|
2016-11-24 08:57:28 +00:00
|
|
|
Callable callable =
|
|
|
|
CodeFactory::NonNumberToNumber(assembler.isolate());
|
|
|
|
var_rhs.Bind(assembler.CallStub(callable, context, rhs));
|
|
|
|
assembler.Goto(&loop);
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&if_lhsisnotsmi);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Load the map and instance type of {lhs}.
|
2016-11-24 08:57:28 +00:00
|
|
|
Node* lhs_instance_type = assembler.LoadInstanceType(lhs);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
|
|
|
// Check if {lhs} is a String.
|
2016-11-24 08:57:28 +00:00
|
|
|
Label if_lhsisstring(&assembler), if_lhsisnotstring(&assembler);
|
|
|
|
assembler.Branch(assembler.IsStringInstanceType(lhs_instance_type),
|
|
|
|
&if_lhsisstring, &if_lhsisnotstring);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&if_lhsisstring);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
var_lhs.Bind(lhs);
|
|
|
|
var_rhs.Bind(rhs);
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Goto(&string_add_convert_right);
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&if_lhsisnotstring);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Check if {rhs} is a Smi.
|
2016-11-24 08:57:28 +00:00
|
|
|
Label if_rhsissmi(&assembler), if_rhsisnotsmi(&assembler);
|
|
|
|
assembler.Branch(assembler.TaggedIsSmi(rhs), &if_rhsissmi,
|
|
|
|
&if_rhsisnotsmi);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&if_rhsissmi);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Check if {lhs} is a Number.
|
2016-11-24 08:57:28 +00:00
|
|
|
Label if_lhsisnumber(&assembler),
|
|
|
|
if_lhsisnotnumber(&assembler, Label::kDeferred);
|
|
|
|
assembler.Branch(
|
|
|
|
assembler.Word32Equal(lhs_instance_type,
|
|
|
|
assembler.Int32Constant(HEAP_NUMBER_TYPE)),
|
2016-11-16 11:48:07 +00:00
|
|
|
&if_lhsisnumber, &if_lhsisnotnumber);
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&if_lhsisnumber);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// The {lhs} is a HeapNumber, the {rhs} is a Smi, just add them.
|
2016-11-24 08:57:28 +00:00
|
|
|
var_fadd_lhs.Bind(assembler.LoadHeapNumberValue(lhs));
|
|
|
|
var_fadd_rhs.Bind(assembler.SmiToFloat64(rhs));
|
|
|
|
assembler.Goto(&do_fadd);
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&if_lhsisnotnumber);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// The {lhs} is neither a Number nor a String, and the {rhs} is a
|
|
|
|
// Smi.
|
2016-11-24 08:57:28 +00:00
|
|
|
Label if_lhsisreceiver(&assembler, Label::kDeferred),
|
|
|
|
if_lhsisnotreceiver(&assembler, Label::kDeferred);
|
|
|
|
assembler.Branch(
|
|
|
|
assembler.IsJSReceiverInstanceType(lhs_instance_type),
|
|
|
|
&if_lhsisreceiver, &if_lhsisnotreceiver);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&if_lhsisreceiver);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Convert {lhs} to a primitive first passing no hint.
|
|
|
|
Callable callable =
|
2016-11-24 08:57:28 +00:00
|
|
|
CodeFactory::NonPrimitiveToPrimitive(assembler.isolate());
|
|
|
|
var_lhs.Bind(assembler.CallStub(callable, context, lhs));
|
|
|
|
assembler.Goto(&loop);
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&if_lhsisnotreceiver);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Convert {lhs} to a Number first.
|
2016-11-24 08:57:28 +00:00
|
|
|
Callable callable =
|
|
|
|
CodeFactory::NonNumberToNumber(assembler.isolate());
|
|
|
|
var_lhs.Bind(assembler.CallStub(callable, context, lhs));
|
|
|
|
assembler.Goto(&loop);
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&if_rhsisnotsmi);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Load the instance type of {rhs}.
|
2016-11-24 08:57:28 +00:00
|
|
|
Node* rhs_instance_type = assembler.LoadInstanceType(rhs);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
|
|
|
// Check if {rhs} is a String.
|
2016-11-24 08:57:28 +00:00
|
|
|
Label if_rhsisstring(&assembler), if_rhsisnotstring(&assembler);
|
|
|
|
assembler.Branch(assembler.IsStringInstanceType(rhs_instance_type),
|
|
|
|
&if_rhsisstring, &if_rhsisnotstring);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&if_rhsisstring);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
var_lhs.Bind(lhs);
|
|
|
|
var_rhs.Bind(rhs);
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Goto(&string_add_convert_left);
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&if_rhsisnotstring);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Check if {lhs} is a HeapNumber.
|
2016-11-24 08:57:28 +00:00
|
|
|
Label if_lhsisnumber(&assembler), if_lhsisnotnumber(&assembler);
|
|
|
|
assembler.Branch(assembler.Word32Equal(
|
|
|
|
lhs_instance_type,
|
|
|
|
assembler.Int32Constant(HEAP_NUMBER_TYPE)),
|
|
|
|
&if_lhsisnumber, &if_lhsisnotnumber);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&if_lhsisnumber);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Check if {rhs} is also a HeapNumber.
|
2016-11-24 08:57:28 +00:00
|
|
|
Label if_rhsisnumber(&assembler),
|
|
|
|
if_rhsisnotnumber(&assembler, Label::kDeferred);
|
|
|
|
assembler.Branch(assembler.Word32Equal(
|
|
|
|
rhs_instance_type,
|
|
|
|
assembler.Int32Constant(HEAP_NUMBER_TYPE)),
|
|
|
|
&if_rhsisnumber, &if_rhsisnotnumber);
|
|
|
|
|
|
|
|
assembler.Bind(&if_rhsisnumber);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Perform a floating point addition.
|
2016-11-24 08:57:28 +00:00
|
|
|
var_fadd_lhs.Bind(assembler.LoadHeapNumberValue(lhs));
|
|
|
|
var_fadd_rhs.Bind(assembler.LoadHeapNumberValue(rhs));
|
|
|
|
assembler.Goto(&do_fadd);
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&if_rhsisnotnumber);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Check if {rhs} is a JSReceiver.
|
2016-11-24 08:57:28 +00:00
|
|
|
Label if_rhsisreceiver(&assembler, Label::kDeferred),
|
|
|
|
if_rhsisnotreceiver(&assembler, Label::kDeferred);
|
|
|
|
assembler.Branch(
|
|
|
|
assembler.IsJSReceiverInstanceType(rhs_instance_type),
|
|
|
|
&if_rhsisreceiver, &if_rhsisnotreceiver);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&if_rhsisreceiver);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Convert {rhs} to a primitive first passing no hint.
|
2016-11-16 11:48:07 +00:00
|
|
|
Callable callable =
|
2016-11-24 08:57:28 +00:00
|
|
|
CodeFactory::NonPrimitiveToPrimitive(assembler.isolate());
|
|
|
|
var_rhs.Bind(assembler.CallStub(callable, context, rhs));
|
|
|
|
assembler.Goto(&loop);
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&if_rhsisnotreceiver);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Convert {rhs} to a Number first.
|
2016-11-24 08:57:28 +00:00
|
|
|
Callable callable =
|
|
|
|
CodeFactory::NonNumberToNumber(assembler.isolate());
|
|
|
|
var_rhs.Bind(assembler.CallStub(callable, context, rhs));
|
|
|
|
assembler.Goto(&loop);
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&if_lhsisnotnumber);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Check if {lhs} is a JSReceiver.
|
2016-11-24 08:57:28 +00:00
|
|
|
Label if_lhsisreceiver(&assembler, Label::kDeferred),
|
|
|
|
if_lhsisnotreceiver(&assembler);
|
|
|
|
assembler.Branch(
|
|
|
|
assembler.IsJSReceiverInstanceType(lhs_instance_type),
|
|
|
|
&if_lhsisreceiver, &if_lhsisnotreceiver);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&if_lhsisreceiver);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Convert {lhs} to a primitive first passing no hint.
|
|
|
|
Callable callable =
|
2016-11-24 08:57:28 +00:00
|
|
|
CodeFactory::NonPrimitiveToPrimitive(assembler.isolate());
|
|
|
|
var_lhs.Bind(assembler.CallStub(callable, context, lhs));
|
|
|
|
assembler.Goto(&loop);
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&if_lhsisnotreceiver);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Check if {rhs} is a JSReceiver.
|
2016-11-24 08:57:28 +00:00
|
|
|
Label if_rhsisreceiver(&assembler, Label::kDeferred),
|
|
|
|
if_rhsisnotreceiver(&assembler, Label::kDeferred);
|
|
|
|
assembler.Branch(
|
|
|
|
assembler.IsJSReceiverInstanceType(rhs_instance_type),
|
|
|
|
&if_rhsisreceiver, &if_rhsisnotreceiver);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&if_rhsisreceiver);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Convert {rhs} to a primitive first passing no hint.
|
2016-11-16 11:48:07 +00:00
|
|
|
Callable callable =
|
2016-11-24 08:57:28 +00:00
|
|
|
CodeFactory::NonPrimitiveToPrimitive(assembler.isolate());
|
|
|
|
var_rhs.Bind(assembler.CallStub(callable, context, rhs));
|
|
|
|
assembler.Goto(&loop);
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&if_rhsisnotreceiver);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Convert {lhs} to a Number first.
|
2016-11-24 08:57:28 +00:00
|
|
|
Callable callable =
|
|
|
|
CodeFactory::NonNumberToNumber(assembler.isolate());
|
|
|
|
var_lhs.Bind(assembler.CallStub(callable, context, lhs));
|
|
|
|
assembler.Goto(&loop);
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&string_add_convert_left);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Convert {lhs}, which is a Smi, to a String and concatenate the
|
|
|
|
// resulting string with the String {rhs}.
|
2016-11-24 08:57:28 +00:00
|
|
|
Callable callable = CodeFactory::StringAdd(
|
|
|
|
assembler.isolate(), STRING_ADD_CONVERT_LEFT, NOT_TENURED);
|
|
|
|
var_result.Bind(assembler.CallStub(callable, context, var_lhs.value(),
|
|
|
|
var_rhs.value()));
|
|
|
|
assembler.Goto(&end);
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&string_add_convert_right);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Convert {lhs}, which is a Smi, to a String and concatenate the
|
|
|
|
// resulting string with the String {rhs}.
|
|
|
|
Callable callable = CodeFactory::StringAdd(
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.isolate(), STRING_ADD_CONVERT_RIGHT, NOT_TENURED);
|
|
|
|
var_result.Bind(assembler.CallStub(callable, context, var_lhs.value(),
|
|
|
|
var_rhs.value()));
|
|
|
|
assembler.Goto(&end);
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&do_fadd);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
Node* lhs_value = var_fadd_lhs.value();
|
|
|
|
Node* rhs_value = var_fadd_rhs.value();
|
2016-11-24 08:57:28 +00:00
|
|
|
Node* value = assembler.Float64Add(lhs_value, rhs_value);
|
|
|
|
Node* result = assembler.AllocateHeapNumberWithValue(value);
|
2016-10-06 15:46:11 +00:00
|
|
|
var_result.Bind(result);
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Goto(&end);
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&end);
|
|
|
|
assembler.Return(var_result.value());
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
void Builtins::Generate_Subtract(compiler::CodeAssemblerState* state) {
|
|
|
|
typedef CodeStubAssembler::Label Label;
|
|
|
|
typedef compiler::Node Node;
|
|
|
|
typedef CodeStubAssembler::Variable Variable;
|
|
|
|
CodeStubAssembler assembler(state);
|
|
|
|
|
|
|
|
Node* left = assembler.Parameter(0);
|
|
|
|
Node* right = assembler.Parameter(1);
|
|
|
|
Node* context = assembler.Parameter(2);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
|
|
|
// Shared entry for floating point subtraction.
|
2016-11-24 08:57:28 +00:00
|
|
|
Label do_fsub(&assembler), end(&assembler);
|
|
|
|
Variable var_fsub_lhs(&assembler, MachineRepresentation::kFloat64),
|
|
|
|
var_fsub_rhs(&assembler, MachineRepresentation::kFloat64);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
|
|
|
// We might need to loop several times due to ToPrimitive and/or ToNumber
|
|
|
|
// conversions.
|
2016-11-24 08:57:28 +00:00
|
|
|
Variable var_lhs(&assembler, MachineRepresentation::kTagged),
|
|
|
|
var_rhs(&assembler, MachineRepresentation::kTagged),
|
|
|
|
var_result(&assembler, MachineRepresentation::kTagged);
|
2016-10-06 15:46:11 +00:00
|
|
|
Variable* loop_vars[2] = {&var_lhs, &var_rhs};
|
2016-11-24 08:57:28 +00:00
|
|
|
Label loop(&assembler, 2, loop_vars);
|
2016-10-06 15:46:11 +00:00
|
|
|
var_lhs.Bind(left);
|
|
|
|
var_rhs.Bind(right);
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Goto(&loop);
|
|
|
|
assembler.Bind(&loop);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Load the current {lhs} and {rhs} values.
|
|
|
|
Node* lhs = var_lhs.value();
|
|
|
|
Node* rhs = var_rhs.value();
|
|
|
|
|
|
|
|
// Check if the {lhs} is a Smi or a HeapObject.
|
2016-11-24 08:57:28 +00:00
|
|
|
Label if_lhsissmi(&assembler), if_lhsisnotsmi(&assembler);
|
|
|
|
assembler.Branch(assembler.TaggedIsSmi(lhs), &if_lhsissmi, &if_lhsisnotsmi);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&if_lhsissmi);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Check if the {rhs} is also a Smi.
|
2016-11-24 08:57:28 +00:00
|
|
|
Label if_rhsissmi(&assembler), if_rhsisnotsmi(&assembler);
|
|
|
|
assembler.Branch(assembler.TaggedIsSmi(rhs), &if_rhsissmi,
|
|
|
|
&if_rhsisnotsmi);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&if_rhsissmi);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Try a fast Smi subtraction first.
|
2016-11-24 08:57:28 +00:00
|
|
|
Node* pair =
|
|
|
|
assembler.IntPtrSubWithOverflow(assembler.BitcastTaggedToWord(lhs),
|
|
|
|
assembler.BitcastTaggedToWord(rhs));
|
|
|
|
Node* overflow = assembler.Projection(1, pair);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
|
|
|
// Check if the Smi subtraction overflowed.
|
2016-11-24 08:57:28 +00:00
|
|
|
Label if_overflow(&assembler), if_notoverflow(&assembler);
|
|
|
|
assembler.Branch(overflow, &if_overflow, &if_notoverflow);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&if_overflow);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// The result doesn't fit into Smi range.
|
2016-11-24 08:57:28 +00:00
|
|
|
var_fsub_lhs.Bind(assembler.SmiToFloat64(lhs));
|
|
|
|
var_fsub_rhs.Bind(assembler.SmiToFloat64(rhs));
|
|
|
|
assembler.Goto(&do_fsub);
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&if_notoverflow);
|
|
|
|
var_result.Bind(
|
|
|
|
assembler.BitcastWordToTaggedSigned(assembler.Projection(0, pair)));
|
|
|
|
assembler.Goto(&end);
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&if_rhsisnotsmi);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Load the map of the {rhs}.
|
2016-11-24 08:57:28 +00:00
|
|
|
Node* rhs_map = assembler.LoadMap(rhs);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
|
|
|
// Check if {rhs} is a HeapNumber.
|
2016-11-24 08:57:28 +00:00
|
|
|
Label if_rhsisnumber(&assembler),
|
|
|
|
if_rhsisnotnumber(&assembler, Label::kDeferred);
|
|
|
|
assembler.Branch(assembler.IsHeapNumberMap(rhs_map), &if_rhsisnumber,
|
|
|
|
&if_rhsisnotnumber);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&if_rhsisnumber);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Perform a floating point subtraction.
|
2016-11-24 08:57:28 +00:00
|
|
|
var_fsub_lhs.Bind(assembler.SmiToFloat64(lhs));
|
|
|
|
var_fsub_rhs.Bind(assembler.LoadHeapNumberValue(rhs));
|
|
|
|
assembler.Goto(&do_fsub);
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&if_rhsisnotnumber);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Convert the {rhs} to a Number first.
|
2016-11-24 08:57:28 +00:00
|
|
|
Callable callable =
|
|
|
|
CodeFactory::NonNumberToNumber(assembler.isolate());
|
|
|
|
var_rhs.Bind(assembler.CallStub(callable, context, rhs));
|
|
|
|
assembler.Goto(&loop);
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&if_lhsisnotsmi);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Load the map of the {lhs}.
|
2016-11-24 08:57:28 +00:00
|
|
|
Node* lhs_map = assembler.LoadMap(lhs);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
|
|
|
// Check if the {lhs} is a HeapNumber.
|
2016-11-24 08:57:28 +00:00
|
|
|
Label if_lhsisnumber(&assembler),
|
|
|
|
if_lhsisnotnumber(&assembler, Label::kDeferred);
|
|
|
|
Node* number_map = assembler.HeapNumberMapConstant();
|
|
|
|
assembler.Branch(assembler.WordEqual(lhs_map, number_map),
|
|
|
|
&if_lhsisnumber, &if_lhsisnotnumber);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&if_lhsisnumber);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Check if the {rhs} is a Smi.
|
2016-11-24 08:57:28 +00:00
|
|
|
Label if_rhsissmi(&assembler), if_rhsisnotsmi(&assembler);
|
|
|
|
assembler.Branch(assembler.TaggedIsSmi(rhs), &if_rhsissmi,
|
|
|
|
&if_rhsisnotsmi);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&if_rhsissmi);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Perform a floating point subtraction.
|
2016-11-24 08:57:28 +00:00
|
|
|
var_fsub_lhs.Bind(assembler.LoadHeapNumberValue(lhs));
|
|
|
|
var_fsub_rhs.Bind(assembler.SmiToFloat64(rhs));
|
|
|
|
assembler.Goto(&do_fsub);
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&if_rhsisnotsmi);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Load the map of the {rhs}.
|
2016-11-24 08:57:28 +00:00
|
|
|
Node* rhs_map = assembler.LoadMap(rhs);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
|
|
|
// Check if the {rhs} is a HeapNumber.
|
2016-11-24 08:57:28 +00:00
|
|
|
Label if_rhsisnumber(&assembler),
|
|
|
|
if_rhsisnotnumber(&assembler, Label::kDeferred);
|
|
|
|
assembler.Branch(assembler.WordEqual(rhs_map, number_map),
|
|
|
|
&if_rhsisnumber, &if_rhsisnotnumber);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&if_rhsisnumber);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Perform a floating point subtraction.
|
2016-11-24 08:57:28 +00:00
|
|
|
var_fsub_lhs.Bind(assembler.LoadHeapNumberValue(lhs));
|
|
|
|
var_fsub_rhs.Bind(assembler.LoadHeapNumberValue(rhs));
|
|
|
|
assembler.Goto(&do_fsub);
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&if_rhsisnotnumber);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Convert the {rhs} to a Number first.
|
2016-11-24 08:57:28 +00:00
|
|
|
Callable callable =
|
|
|
|
CodeFactory::NonNumberToNumber(assembler.isolate());
|
|
|
|
var_rhs.Bind(assembler.CallStub(callable, context, rhs));
|
|
|
|
assembler.Goto(&loop);
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&if_lhsisnotnumber);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Convert the {lhs} to a Number first.
|
2016-11-24 08:57:28 +00:00
|
|
|
Callable callable = CodeFactory::NonNumberToNumber(assembler.isolate());
|
|
|
|
var_lhs.Bind(assembler.CallStub(callable, context, lhs));
|
|
|
|
assembler.Goto(&loop);
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&do_fsub);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
Node* lhs_value = var_fsub_lhs.value();
|
|
|
|
Node* rhs_value = var_fsub_rhs.value();
|
2016-11-24 08:57:28 +00:00
|
|
|
Node* value = assembler.Float64Sub(lhs_value, rhs_value);
|
|
|
|
var_result.Bind(assembler.AllocateHeapNumberWithValue(value));
|
|
|
|
assembler.Goto(&end);
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&end);
|
|
|
|
assembler.Return(var_result.value());
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
void Builtins::Generate_Multiply(compiler::CodeAssemblerState* state) {
|
|
|
|
typedef CodeStubAssembler::Label Label;
|
|
|
|
typedef compiler::Node Node;
|
|
|
|
typedef CodeStubAssembler::Variable Variable;
|
|
|
|
CodeStubAssembler assembler(state);
|
|
|
|
|
|
|
|
Node* left = assembler.Parameter(0);
|
|
|
|
Node* right = assembler.Parameter(1);
|
|
|
|
Node* context = assembler.Parameter(2);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
|
|
|
// Shared entry point for floating point multiplication.
|
2016-11-24 08:57:28 +00:00
|
|
|
Label do_fmul(&assembler), return_result(&assembler);
|
|
|
|
Variable var_lhs_float64(&assembler, MachineRepresentation::kFloat64),
|
|
|
|
var_rhs_float64(&assembler, MachineRepresentation::kFloat64);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
Node* number_map = assembler.HeapNumberMapConstant();
|
2016-10-06 15:46:11 +00:00
|
|
|
|
|
|
|
// We might need to loop one or two times due to ToNumber conversions.
|
2016-11-24 08:57:28 +00:00
|
|
|
Variable var_lhs(&assembler, MachineRepresentation::kTagged),
|
|
|
|
var_rhs(&assembler, MachineRepresentation::kTagged),
|
|
|
|
var_result(&assembler, MachineRepresentation::kTagged);
|
2016-10-06 15:46:11 +00:00
|
|
|
Variable* loop_variables[] = {&var_lhs, &var_rhs};
|
2016-11-24 08:57:28 +00:00
|
|
|
Label loop(&assembler, 2, loop_variables);
|
2016-10-06 15:46:11 +00:00
|
|
|
var_lhs.Bind(left);
|
|
|
|
var_rhs.Bind(right);
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Goto(&loop);
|
|
|
|
assembler.Bind(&loop);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
Node* lhs = var_lhs.value();
|
|
|
|
Node* rhs = var_rhs.value();
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
Label lhs_is_smi(&assembler), lhs_is_not_smi(&assembler);
|
|
|
|
assembler.Branch(assembler.TaggedIsSmi(lhs), &lhs_is_smi, &lhs_is_not_smi);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&lhs_is_smi);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
2016-11-24 08:57:28 +00:00
|
|
|
Label rhs_is_smi(&assembler), rhs_is_not_smi(&assembler);
|
|
|
|
assembler.Branch(assembler.TaggedIsSmi(rhs), &rhs_is_smi,
|
|
|
|
&rhs_is_not_smi);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&rhs_is_smi);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Both {lhs} and {rhs} are Smis. The result is not necessarily a smi,
|
|
|
|
// in case of overflow.
|
2016-11-24 08:57:28 +00:00
|
|
|
var_result.Bind(assembler.SmiMul(lhs, rhs));
|
|
|
|
assembler.Goto(&return_result);
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&rhs_is_not_smi);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
2016-11-24 08:57:28 +00:00
|
|
|
Node* rhs_map = assembler.LoadMap(rhs);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
|
|
|
// Check if {rhs} is a HeapNumber.
|
2016-11-24 08:57:28 +00:00
|
|
|
Label rhs_is_number(&assembler),
|
|
|
|
rhs_is_not_number(&assembler, Label::kDeferred);
|
|
|
|
assembler.Branch(assembler.WordEqual(rhs_map, number_map),
|
|
|
|
&rhs_is_number, &rhs_is_not_number);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&rhs_is_number);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Convert {lhs} to a double and multiply it with the value of {rhs}.
|
2016-11-24 08:57:28 +00:00
|
|
|
var_lhs_float64.Bind(assembler.SmiToFloat64(lhs));
|
|
|
|
var_rhs_float64.Bind(assembler.LoadHeapNumberValue(rhs));
|
|
|
|
assembler.Goto(&do_fmul);
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&rhs_is_not_number);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Multiplication is commutative, swap {lhs} with {rhs} and loop.
|
|
|
|
var_lhs.Bind(rhs);
|
|
|
|
var_rhs.Bind(lhs);
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Goto(&loop);
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&lhs_is_not_smi);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
2016-11-24 08:57:28 +00:00
|
|
|
Node* lhs_map = assembler.LoadMap(lhs);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
|
|
|
// Check if {lhs} is a HeapNumber.
|
2016-11-24 08:57:28 +00:00
|
|
|
Label lhs_is_number(&assembler),
|
|
|
|
lhs_is_not_number(&assembler, Label::kDeferred);
|
|
|
|
assembler.Branch(assembler.WordEqual(lhs_map, number_map), &lhs_is_number,
|
|
|
|
&lhs_is_not_number);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&lhs_is_number);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Check if {rhs} is a Smi.
|
2016-11-24 08:57:28 +00:00
|
|
|
Label rhs_is_smi(&assembler), rhs_is_not_smi(&assembler);
|
|
|
|
assembler.Branch(assembler.TaggedIsSmi(rhs), &rhs_is_smi,
|
|
|
|
&rhs_is_not_smi);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&rhs_is_smi);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Convert {rhs} to a double and multiply it with the value of {lhs}.
|
2016-11-24 08:57:28 +00:00
|
|
|
var_lhs_float64.Bind(assembler.LoadHeapNumberValue(lhs));
|
|
|
|
var_rhs_float64.Bind(assembler.SmiToFloat64(rhs));
|
|
|
|
assembler.Goto(&do_fmul);
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&rhs_is_not_smi);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
2016-11-24 08:57:28 +00:00
|
|
|
Node* rhs_map = assembler.LoadMap(rhs);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
|
|
|
// Check if {rhs} is a HeapNumber.
|
2016-11-24 08:57:28 +00:00
|
|
|
Label rhs_is_number(&assembler),
|
|
|
|
rhs_is_not_number(&assembler, Label::kDeferred);
|
|
|
|
assembler.Branch(assembler.WordEqual(rhs_map, number_map),
|
|
|
|
&rhs_is_number, &rhs_is_not_number);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&rhs_is_number);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Both {lhs} and {rhs} are HeapNumbers. Load their values and
|
|
|
|
// multiply them.
|
2016-11-24 08:57:28 +00:00
|
|
|
var_lhs_float64.Bind(assembler.LoadHeapNumberValue(lhs));
|
|
|
|
var_rhs_float64.Bind(assembler.LoadHeapNumberValue(rhs));
|
|
|
|
assembler.Goto(&do_fmul);
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&rhs_is_not_number);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Multiplication is commutative, swap {lhs} with {rhs} and loop.
|
|
|
|
var_lhs.Bind(rhs);
|
|
|
|
var_rhs.Bind(lhs);
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Goto(&loop);
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&lhs_is_not_number);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Convert {lhs} to a Number and loop.
|
2016-11-24 08:57:28 +00:00
|
|
|
Callable callable = CodeFactory::NonNumberToNumber(assembler.isolate());
|
|
|
|
var_lhs.Bind(assembler.CallStub(callable, context, lhs));
|
|
|
|
assembler.Goto(&loop);
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&do_fmul);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
2016-11-24 08:57:28 +00:00
|
|
|
Node* value =
|
|
|
|
assembler.Float64Mul(var_lhs_float64.value(), var_rhs_float64.value());
|
|
|
|
Node* result = assembler.AllocateHeapNumberWithValue(value);
|
2016-10-06 15:46:11 +00:00
|
|
|
var_result.Bind(result);
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Goto(&return_result);
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&return_result);
|
|
|
|
assembler.Return(var_result.value());
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
void Builtins::Generate_Divide(compiler::CodeAssemblerState* state) {
|
|
|
|
typedef CodeStubAssembler::Label Label;
|
|
|
|
typedef compiler::Node Node;
|
|
|
|
typedef CodeStubAssembler::Variable Variable;
|
|
|
|
CodeStubAssembler assembler(state);
|
|
|
|
|
|
|
|
Node* left = assembler.Parameter(0);
|
|
|
|
Node* right = assembler.Parameter(1);
|
|
|
|
Node* context = assembler.Parameter(2);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
|
|
|
// Shared entry point for floating point division.
|
2016-11-24 08:57:28 +00:00
|
|
|
Label do_fdiv(&assembler), end(&assembler);
|
|
|
|
Variable var_dividend_float64(&assembler, MachineRepresentation::kFloat64),
|
|
|
|
var_divisor_float64(&assembler, MachineRepresentation::kFloat64);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
Node* number_map = assembler.HeapNumberMapConstant();
|
2016-10-06 15:46:11 +00:00
|
|
|
|
|
|
|
// We might need to loop one or two times due to ToNumber conversions.
|
2016-11-24 08:57:28 +00:00
|
|
|
Variable var_dividend(&assembler, MachineRepresentation::kTagged),
|
|
|
|
var_divisor(&assembler, MachineRepresentation::kTagged),
|
|
|
|
var_result(&assembler, MachineRepresentation::kTagged);
|
2016-10-06 15:46:11 +00:00
|
|
|
Variable* loop_variables[] = {&var_dividend, &var_divisor};
|
2016-11-24 08:57:28 +00:00
|
|
|
Label loop(&assembler, 2, loop_variables);
|
2016-10-06 15:46:11 +00:00
|
|
|
var_dividend.Bind(left);
|
|
|
|
var_divisor.Bind(right);
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Goto(&loop);
|
|
|
|
assembler.Bind(&loop);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
Node* dividend = var_dividend.value();
|
|
|
|
Node* divisor = var_divisor.value();
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
Label dividend_is_smi(&assembler), dividend_is_not_smi(&assembler);
|
|
|
|
assembler.Branch(assembler.TaggedIsSmi(dividend), ÷nd_is_smi,
|
|
|
|
÷nd_is_not_smi);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(÷nd_is_smi);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
2016-11-24 08:57:28 +00:00
|
|
|
Label divisor_is_smi(&assembler), divisor_is_not_smi(&assembler);
|
|
|
|
assembler.Branch(assembler.TaggedIsSmi(divisor), &divisor_is_smi,
|
|
|
|
&divisor_is_not_smi);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&divisor_is_smi);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
2016-11-24 08:57:28 +00:00
|
|
|
Label bailout(&assembler);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
|
|
|
// Do floating point division if {divisor} is zero.
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.GotoIf(
|
|
|
|
assembler.WordEqual(divisor, assembler.IntPtrConstant(0)),
|
|
|
|
&bailout);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
|
|
|
// Do floating point division {dividend} is zero and {divisor} is
|
|
|
|
// negative.
|
2016-11-24 08:57:28 +00:00
|
|
|
Label dividend_is_zero(&assembler), dividend_is_not_zero(&assembler);
|
|
|
|
assembler.Branch(
|
|
|
|
assembler.WordEqual(dividend, assembler.IntPtrConstant(0)),
|
|
|
|
÷nd_is_zero, ÷nd_is_not_zero);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(÷nd_is_zero);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.GotoIf(
|
|
|
|
assembler.IntPtrLessThan(divisor, assembler.IntPtrConstant(0)),
|
|
|
|
&bailout);
|
|
|
|
assembler.Goto(÷nd_is_not_zero);
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(÷nd_is_not_zero);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
Node* untagged_divisor = assembler.SmiUntag(divisor);
|
|
|
|
Node* untagged_dividend = assembler.SmiUntag(dividend);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
|
|
|
// Do floating point division if {dividend} is kMinInt (or kMinInt - 1
|
|
|
|
// if the Smi size is 31) and {divisor} is -1.
|
2016-11-24 08:57:28 +00:00
|
|
|
Label divisor_is_minus_one(&assembler),
|
|
|
|
divisor_is_not_minus_one(&assembler);
|
|
|
|
assembler.Branch(assembler.Word32Equal(untagged_divisor,
|
|
|
|
assembler.Int32Constant(-1)),
|
|
|
|
&divisor_is_minus_one, &divisor_is_not_minus_one);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&divisor_is_minus_one);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.GotoIf(
|
|
|
|
assembler.Word32Equal(
|
|
|
|
untagged_dividend,
|
|
|
|
assembler.Int32Constant(
|
|
|
|
kSmiValueSize == 32 ? kMinInt : (kMinInt >> 1))),
|
2016-10-06 15:46:11 +00:00
|
|
|
&bailout);
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Goto(&divisor_is_not_minus_one);
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&divisor_is_not_minus_one);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
|
|
|
// TODO(epertoso): consider adding a machine instruction that returns
|
|
|
|
// both the result and the remainder.
|
2016-11-24 08:57:28 +00:00
|
|
|
Node* untagged_result =
|
|
|
|
assembler.Int32Div(untagged_dividend, untagged_divisor);
|
|
|
|
Node* truncated = assembler.Int32Mul(untagged_result, untagged_divisor);
|
2016-10-06 15:46:11 +00:00
|
|
|
// Do floating point division if the remainder is not 0.
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.GotoIf(assembler.Word32NotEqual(untagged_dividend, truncated),
|
|
|
|
&bailout);
|
|
|
|
var_result.Bind(assembler.SmiTag(untagged_result));
|
|
|
|
assembler.Goto(&end);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
|
|
|
// Bailout: convert {dividend} and {divisor} to double and do double
|
|
|
|
// division.
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&bailout);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
2016-11-24 08:57:28 +00:00
|
|
|
var_dividend_float64.Bind(assembler.SmiToFloat64(dividend));
|
|
|
|
var_divisor_float64.Bind(assembler.SmiToFloat64(divisor));
|
|
|
|
assembler.Goto(&do_fdiv);
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&divisor_is_not_smi);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
2016-11-24 08:57:28 +00:00
|
|
|
Node* divisor_map = assembler.LoadMap(divisor);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
|
|
|
// Check if {divisor} is a HeapNumber.
|
2016-11-24 08:57:28 +00:00
|
|
|
Label divisor_is_number(&assembler),
|
|
|
|
divisor_is_not_number(&assembler, Label::kDeferred);
|
|
|
|
assembler.Branch(assembler.WordEqual(divisor_map, number_map),
|
|
|
|
&divisor_is_number, &divisor_is_not_number);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&divisor_is_number);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Convert {dividend} to a double and divide it with the value of
|
|
|
|
// {divisor}.
|
2016-11-24 08:57:28 +00:00
|
|
|
var_dividend_float64.Bind(assembler.SmiToFloat64(dividend));
|
|
|
|
var_divisor_float64.Bind(assembler.LoadHeapNumberValue(divisor));
|
|
|
|
assembler.Goto(&do_fdiv);
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&divisor_is_not_number);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Convert {divisor} to a number and loop.
|
2016-11-24 08:57:28 +00:00
|
|
|
Callable callable =
|
|
|
|
CodeFactory::NonNumberToNumber(assembler.isolate());
|
|
|
|
var_divisor.Bind(assembler.CallStub(callable, context, divisor));
|
|
|
|
assembler.Goto(&loop);
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(÷nd_is_not_smi);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
2016-11-24 08:57:28 +00:00
|
|
|
Node* dividend_map = assembler.LoadMap(dividend);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
|
|
|
// Check if {dividend} is a HeapNumber.
|
2016-11-24 08:57:28 +00:00
|
|
|
Label dividend_is_number(&assembler),
|
|
|
|
dividend_is_not_number(&assembler, Label::kDeferred);
|
|
|
|
assembler.Branch(assembler.WordEqual(dividend_map, number_map),
|
|
|
|
÷nd_is_number, ÷nd_is_not_number);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(÷nd_is_number);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Check if {divisor} is a Smi.
|
2016-11-24 08:57:28 +00:00
|
|
|
Label divisor_is_smi(&assembler), divisor_is_not_smi(&assembler);
|
|
|
|
assembler.Branch(assembler.TaggedIsSmi(divisor), &divisor_is_smi,
|
|
|
|
&divisor_is_not_smi);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&divisor_is_smi);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Convert {divisor} to a double and use it for a floating point
|
|
|
|
// division.
|
2016-11-24 08:57:28 +00:00
|
|
|
var_dividend_float64.Bind(assembler.LoadHeapNumberValue(dividend));
|
|
|
|
var_divisor_float64.Bind(assembler.SmiToFloat64(divisor));
|
|
|
|
assembler.Goto(&do_fdiv);
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&divisor_is_not_smi);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
2016-11-24 08:57:28 +00:00
|
|
|
Node* divisor_map = assembler.LoadMap(divisor);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
|
|
|
// Check if {divisor} is a HeapNumber.
|
2016-11-24 08:57:28 +00:00
|
|
|
Label divisor_is_number(&assembler),
|
|
|
|
divisor_is_not_number(&assembler, Label::kDeferred);
|
|
|
|
assembler.Branch(assembler.WordEqual(divisor_map, number_map),
|
|
|
|
&divisor_is_number, &divisor_is_not_number);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&divisor_is_number);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Both {dividend} and {divisor} are HeapNumbers. Load their values
|
|
|
|
// and divide them.
|
2016-11-24 08:57:28 +00:00
|
|
|
var_dividend_float64.Bind(assembler.LoadHeapNumberValue(dividend));
|
|
|
|
var_divisor_float64.Bind(assembler.LoadHeapNumberValue(divisor));
|
|
|
|
assembler.Goto(&do_fdiv);
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&divisor_is_not_number);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Convert {divisor} to a number and loop.
|
2016-11-24 08:57:28 +00:00
|
|
|
Callable callable =
|
|
|
|
CodeFactory::NonNumberToNumber(assembler.isolate());
|
|
|
|
var_divisor.Bind(assembler.CallStub(callable, context, divisor));
|
|
|
|
assembler.Goto(&loop);
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(÷nd_is_not_number);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Convert {dividend} to a Number and loop.
|
2016-11-24 08:57:28 +00:00
|
|
|
Callable callable = CodeFactory::NonNumberToNumber(assembler.isolate());
|
|
|
|
var_dividend.Bind(assembler.CallStub(callable, context, dividend));
|
|
|
|
assembler.Goto(&loop);
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&do_fdiv);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
2016-11-24 08:57:28 +00:00
|
|
|
Node* value = assembler.Float64Div(var_dividend_float64.value(),
|
|
|
|
var_divisor_float64.value());
|
|
|
|
var_result.Bind(assembler.AllocateHeapNumberWithValue(value));
|
|
|
|
assembler.Goto(&end);
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&end);
|
|
|
|
assembler.Return(var_result.value());
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
void Builtins::Generate_Modulus(compiler::CodeAssemblerState* state) {
|
|
|
|
typedef CodeStubAssembler::Label Label;
|
|
|
|
typedef compiler::Node Node;
|
|
|
|
typedef CodeStubAssembler::Variable Variable;
|
|
|
|
CodeStubAssembler assembler(state);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
Node* left = assembler.Parameter(0);
|
|
|
|
Node* right = assembler.Parameter(1);
|
|
|
|
Node* context = assembler.Parameter(2);
|
|
|
|
|
|
|
|
Variable var_result(&assembler, MachineRepresentation::kTagged);
|
|
|
|
Label return_result(&assembler, &var_result);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
|
|
|
// Shared entry point for floating point modulus.
|
2016-11-24 08:57:28 +00:00
|
|
|
Label do_fmod(&assembler);
|
|
|
|
Variable var_dividend_float64(&assembler, MachineRepresentation::kFloat64),
|
|
|
|
var_divisor_float64(&assembler, MachineRepresentation::kFloat64);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
Node* number_map = assembler.HeapNumberMapConstant();
|
2016-10-06 15:46:11 +00:00
|
|
|
|
|
|
|
// We might need to loop one or two times due to ToNumber conversions.
|
2016-11-24 08:57:28 +00:00
|
|
|
Variable var_dividend(&assembler, MachineRepresentation::kTagged),
|
|
|
|
var_divisor(&assembler, MachineRepresentation::kTagged);
|
2016-10-06 15:46:11 +00:00
|
|
|
Variable* loop_variables[] = {&var_dividend, &var_divisor};
|
2016-11-24 08:57:28 +00:00
|
|
|
Label loop(&assembler, 2, loop_variables);
|
2016-10-06 15:46:11 +00:00
|
|
|
var_dividend.Bind(left);
|
|
|
|
var_divisor.Bind(right);
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Goto(&loop);
|
|
|
|
assembler.Bind(&loop);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
Node* dividend = var_dividend.value();
|
|
|
|
Node* divisor = var_divisor.value();
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
Label dividend_is_smi(&assembler), dividend_is_not_smi(&assembler);
|
|
|
|
assembler.Branch(assembler.TaggedIsSmi(dividend), ÷nd_is_smi,
|
|
|
|
÷nd_is_not_smi);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(÷nd_is_smi);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
2016-11-24 08:57:28 +00:00
|
|
|
Label dividend_is_not_zero(&assembler);
|
|
|
|
Label divisor_is_smi(&assembler), divisor_is_not_smi(&assembler);
|
|
|
|
assembler.Branch(assembler.TaggedIsSmi(divisor), &divisor_is_smi,
|
|
|
|
&divisor_is_not_smi);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&divisor_is_smi);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Compute the modulus of two Smis.
|
2016-11-24 08:57:28 +00:00
|
|
|
var_result.Bind(assembler.SmiMod(dividend, divisor));
|
|
|
|
assembler.Goto(&return_result);
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&divisor_is_not_smi);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
2016-11-24 08:57:28 +00:00
|
|
|
Node* divisor_map = assembler.LoadMap(divisor);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
|
|
|
// Check if {divisor} is a HeapNumber.
|
2016-11-24 08:57:28 +00:00
|
|
|
Label divisor_is_number(&assembler),
|
|
|
|
divisor_is_not_number(&assembler, Label::kDeferred);
|
|
|
|
assembler.Branch(assembler.WordEqual(divisor_map, number_map),
|
|
|
|
&divisor_is_number, &divisor_is_not_number);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&divisor_is_number);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Convert {dividend} to a double and compute its modulus with the
|
|
|
|
// value of {dividend}.
|
2016-11-24 08:57:28 +00:00
|
|
|
var_dividend_float64.Bind(assembler.SmiToFloat64(dividend));
|
|
|
|
var_divisor_float64.Bind(assembler.LoadHeapNumberValue(divisor));
|
|
|
|
assembler.Goto(&do_fmod);
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&divisor_is_not_number);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Convert {divisor} to a number and loop.
|
2016-11-24 08:57:28 +00:00
|
|
|
Callable callable =
|
|
|
|
CodeFactory::NonNumberToNumber(assembler.isolate());
|
|
|
|
var_divisor.Bind(assembler.CallStub(callable, context, divisor));
|
|
|
|
assembler.Goto(&loop);
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(÷nd_is_not_smi);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
2016-11-24 08:57:28 +00:00
|
|
|
Node* dividend_map = assembler.LoadMap(dividend);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
|
|
|
// Check if {dividend} is a HeapNumber.
|
2016-11-24 08:57:28 +00:00
|
|
|
Label dividend_is_number(&assembler),
|
|
|
|
dividend_is_not_number(&assembler, Label::kDeferred);
|
|
|
|
assembler.Branch(assembler.WordEqual(dividend_map, number_map),
|
|
|
|
÷nd_is_number, ÷nd_is_not_number);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(÷nd_is_number);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Check if {divisor} is a Smi.
|
2016-11-24 08:57:28 +00:00
|
|
|
Label divisor_is_smi(&assembler), divisor_is_not_smi(&assembler);
|
|
|
|
assembler.Branch(assembler.TaggedIsSmi(divisor), &divisor_is_smi,
|
|
|
|
&divisor_is_not_smi);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&divisor_is_smi);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Convert {divisor} to a double and compute {dividend}'s modulus with
|
|
|
|
// it.
|
2016-11-24 08:57:28 +00:00
|
|
|
var_dividend_float64.Bind(assembler.LoadHeapNumberValue(dividend));
|
|
|
|
var_divisor_float64.Bind(assembler.SmiToFloat64(divisor));
|
|
|
|
assembler.Goto(&do_fmod);
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&divisor_is_not_smi);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
2016-11-24 08:57:28 +00:00
|
|
|
Node* divisor_map = assembler.LoadMap(divisor);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
|
|
|
// Check if {divisor} is a HeapNumber.
|
2016-11-24 08:57:28 +00:00
|
|
|
Label divisor_is_number(&assembler),
|
|
|
|
divisor_is_not_number(&assembler, Label::kDeferred);
|
|
|
|
assembler.Branch(assembler.WordEqual(divisor_map, number_map),
|
|
|
|
&divisor_is_number, &divisor_is_not_number);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&divisor_is_number);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Both {dividend} and {divisor} are HeapNumbers. Load their values
|
|
|
|
// and compute their modulus.
|
2016-11-24 08:57:28 +00:00
|
|
|
var_dividend_float64.Bind(assembler.LoadHeapNumberValue(dividend));
|
|
|
|
var_divisor_float64.Bind(assembler.LoadHeapNumberValue(divisor));
|
|
|
|
assembler.Goto(&do_fmod);
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&divisor_is_not_number);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Convert {divisor} to a number and loop.
|
2016-11-24 08:57:28 +00:00
|
|
|
Callable callable =
|
|
|
|
CodeFactory::NonNumberToNumber(assembler.isolate());
|
|
|
|
var_divisor.Bind(assembler.CallStub(callable, context, divisor));
|
|
|
|
assembler.Goto(&loop);
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(÷nd_is_not_number);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
|
|
|
// Convert {dividend} to a Number and loop.
|
2016-11-24 08:57:28 +00:00
|
|
|
Callable callable = CodeFactory::NonNumberToNumber(assembler.isolate());
|
|
|
|
var_dividend.Bind(assembler.CallStub(callable, context, dividend));
|
|
|
|
assembler.Goto(&loop);
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&do_fmod);
|
2016-10-06 15:46:11 +00:00
|
|
|
{
|
2016-11-24 08:57:28 +00:00
|
|
|
Node* value = assembler.Float64Mod(var_dividend_float64.value(),
|
|
|
|
var_divisor_float64.value());
|
|
|
|
var_result.Bind(assembler.AllocateHeapNumberWithValue(value));
|
|
|
|
assembler.Goto(&return_result);
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Bind(&return_result);
|
|
|
|
assembler.Return(var_result.value());
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
void Builtins::Generate_ShiftLeft(compiler::CodeAssemblerState* state) {
|
|
|
|
using compiler::Node;
|
|
|
|
CodeStubAssembler assembler(state);
|
|
|
|
|
|
|
|
Node* left = assembler.Parameter(0);
|
|
|
|
Node* right = assembler.Parameter(1);
|
|
|
|
Node* context = assembler.Parameter(2);
|
|
|
|
|
|
|
|
Node* lhs_value = assembler.TruncateTaggedToWord32(context, left);
|
|
|
|
Node* rhs_value = assembler.TruncateTaggedToWord32(context, right);
|
|
|
|
Node* shift_count =
|
|
|
|
assembler.Word32And(rhs_value, assembler.Int32Constant(0x1f));
|
|
|
|
Node* value = assembler.Word32Shl(lhs_value, shift_count);
|
|
|
|
Node* result = assembler.ChangeInt32ToTagged(value);
|
|
|
|
assembler.Return(result);
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
void Builtins::Generate_ShiftRight(compiler::CodeAssemblerState* state) {
|
|
|
|
using compiler::Node;
|
|
|
|
CodeStubAssembler assembler(state);
|
|
|
|
|
|
|
|
Node* left = assembler.Parameter(0);
|
|
|
|
Node* right = assembler.Parameter(1);
|
|
|
|
Node* context = assembler.Parameter(2);
|
|
|
|
|
|
|
|
Node* lhs_value = assembler.TruncateTaggedToWord32(context, left);
|
|
|
|
Node* rhs_value = assembler.TruncateTaggedToWord32(context, right);
|
|
|
|
Node* shift_count =
|
|
|
|
assembler.Word32And(rhs_value, assembler.Int32Constant(0x1f));
|
|
|
|
Node* value = assembler.Word32Sar(lhs_value, shift_count);
|
|
|
|
Node* result = assembler.ChangeInt32ToTagged(value);
|
|
|
|
assembler.Return(result);
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
void Builtins::Generate_ShiftRightLogical(compiler::CodeAssemblerState* state) {
|
|
|
|
using compiler::Node;
|
|
|
|
CodeStubAssembler assembler(state);
|
|
|
|
|
|
|
|
Node* left = assembler.Parameter(0);
|
|
|
|
Node* right = assembler.Parameter(1);
|
|
|
|
Node* context = assembler.Parameter(2);
|
|
|
|
|
|
|
|
Node* lhs_value = assembler.TruncateTaggedToWord32(context, left);
|
|
|
|
Node* rhs_value = assembler.TruncateTaggedToWord32(context, right);
|
|
|
|
Node* shift_count =
|
|
|
|
assembler.Word32And(rhs_value, assembler.Int32Constant(0x1f));
|
|
|
|
Node* value = assembler.Word32Shr(lhs_value, shift_count);
|
|
|
|
Node* result = assembler.ChangeUint32ToTagged(value);
|
|
|
|
assembler.Return(result);
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
void Builtins::Generate_BitwiseAnd(compiler::CodeAssemblerState* state) {
|
|
|
|
CodeStubAssembler assembler(state);
|
|
|
|
using compiler::Node;
|
|
|
|
|
|
|
|
Node* left = assembler.Parameter(0);
|
|
|
|
Node* right = assembler.Parameter(1);
|
|
|
|
Node* context = assembler.Parameter(2);
|
|
|
|
|
|
|
|
Node* lhs_value = assembler.TruncateTaggedToWord32(context, left);
|
|
|
|
Node* rhs_value = assembler.TruncateTaggedToWord32(context, right);
|
|
|
|
Node* value = assembler.Word32And(lhs_value, rhs_value);
|
|
|
|
Node* result = assembler.ChangeInt32ToTagged(value);
|
|
|
|
assembler.Return(result);
|
2016-11-16 11:48:07 +00:00
|
|
|
}
|
2016-10-06 15:46:11 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
void Builtins::Generate_BitwiseOr(compiler::CodeAssemblerState* state) {
|
|
|
|
CodeStubAssembler assembler(state);
|
|
|
|
using compiler::Node;
|
|
|
|
|
|
|
|
Node* left = assembler.Parameter(0);
|
|
|
|
Node* right = assembler.Parameter(1);
|
|
|
|
Node* context = assembler.Parameter(2);
|
|
|
|
|
|
|
|
Node* lhs_value = assembler.TruncateTaggedToWord32(context, left);
|
|
|
|
Node* rhs_value = assembler.TruncateTaggedToWord32(context, right);
|
|
|
|
Node* value = assembler.Word32Or(lhs_value, rhs_value);
|
|
|
|
Node* result = assembler.ChangeInt32ToTagged(value);
|
|
|
|
assembler.Return(result);
|
2016-11-16 11:48:07 +00:00
|
|
|
}
|
2016-10-06 15:46:11 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
void Builtins::Generate_BitwiseXor(compiler::CodeAssemblerState* state) {
|
|
|
|
CodeStubAssembler assembler(state);
|
|
|
|
using compiler::Node;
|
|
|
|
|
|
|
|
Node* left = assembler.Parameter(0);
|
|
|
|
Node* right = assembler.Parameter(1);
|
|
|
|
Node* context = assembler.Parameter(2);
|
|
|
|
|
|
|
|
Node* lhs_value = assembler.TruncateTaggedToWord32(context, left);
|
|
|
|
Node* rhs_value = assembler.TruncateTaggedToWord32(context, right);
|
|
|
|
Node* value = assembler.Word32Xor(lhs_value, rhs_value);
|
|
|
|
Node* result = assembler.ChangeInt32ToTagged(value);
|
|
|
|
assembler.Return(result);
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
void Builtins::Generate_LessThan(compiler::CodeAssemblerState* state) {
|
|
|
|
CodeStubAssembler assembler(state);
|
|
|
|
compiler::Node* lhs = assembler.Parameter(0);
|
|
|
|
compiler::Node* rhs = assembler.Parameter(1);
|
|
|
|
compiler::Node* context = assembler.Parameter(2);
|
|
|
|
|
|
|
|
assembler.Return(assembler.RelationalComparison(CodeStubAssembler::kLessThan,
|
|
|
|
lhs, rhs, context));
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
void Builtins::Generate_LessThanOrEqual(compiler::CodeAssemblerState* state) {
|
|
|
|
CodeStubAssembler assembler(state);
|
|
|
|
compiler::Node* lhs = assembler.Parameter(0);
|
|
|
|
compiler::Node* rhs = assembler.Parameter(1);
|
|
|
|
compiler::Node* context = assembler.Parameter(2);
|
|
|
|
|
|
|
|
assembler.Return(assembler.RelationalComparison(
|
|
|
|
CodeStubAssembler::kLessThanOrEqual, lhs, rhs, context));
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
void Builtins::Generate_GreaterThan(compiler::CodeAssemblerState* state) {
|
|
|
|
CodeStubAssembler assembler(state);
|
|
|
|
compiler::Node* lhs = assembler.Parameter(0);
|
|
|
|
compiler::Node* rhs = assembler.Parameter(1);
|
|
|
|
compiler::Node* context = assembler.Parameter(2);
|
|
|
|
|
|
|
|
assembler.Return(assembler.RelationalComparison(
|
|
|
|
CodeStubAssembler::kGreaterThan, lhs, rhs, context));
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
void Builtins::Generate_GreaterThanOrEqual(
|
|
|
|
compiler::CodeAssemblerState* state) {
|
|
|
|
CodeStubAssembler assembler(state);
|
|
|
|
compiler::Node* lhs = assembler.Parameter(0);
|
|
|
|
compiler::Node* rhs = assembler.Parameter(1);
|
|
|
|
compiler::Node* context = assembler.Parameter(2);
|
|
|
|
|
|
|
|
assembler.Return(assembler.RelationalComparison(
|
|
|
|
CodeStubAssembler::kGreaterThanOrEqual, lhs, rhs, context));
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
void Builtins::Generate_Equal(compiler::CodeAssemblerState* state) {
|
|
|
|
CodeStubAssembler assembler(state);
|
|
|
|
compiler::Node* lhs = assembler.Parameter(0);
|
|
|
|
compiler::Node* rhs = assembler.Parameter(1);
|
|
|
|
compiler::Node* context = assembler.Parameter(2);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Return(
|
|
|
|
assembler.Equal(CodeStubAssembler::kDontNegateResult, lhs, rhs, context));
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
void Builtins::Generate_NotEqual(compiler::CodeAssemblerState* state) {
|
|
|
|
CodeStubAssembler assembler(state);
|
|
|
|
compiler::Node* lhs = assembler.Parameter(0);
|
|
|
|
compiler::Node* rhs = assembler.Parameter(1);
|
|
|
|
compiler::Node* context = assembler.Parameter(2);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Return(
|
|
|
|
assembler.Equal(CodeStubAssembler::kNegateResult, lhs, rhs, context));
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
void Builtins::Generate_StrictEqual(compiler::CodeAssemblerState* state) {
|
|
|
|
CodeStubAssembler assembler(state);
|
|
|
|
compiler::Node* lhs = assembler.Parameter(0);
|
|
|
|
compiler::Node* rhs = assembler.Parameter(1);
|
|
|
|
compiler::Node* context = assembler.Parameter(2);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Return(assembler.StrictEqual(CodeStubAssembler::kDontNegateResult,
|
|
|
|
lhs, rhs, context));
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
void Builtins::Generate_StrictNotEqual(compiler::CodeAssemblerState* state) {
|
|
|
|
CodeStubAssembler assembler(state);
|
|
|
|
compiler::Node* lhs = assembler.Parameter(0);
|
|
|
|
compiler::Node* rhs = assembler.Parameter(1);
|
|
|
|
compiler::Node* context = assembler.Parameter(2);
|
2016-10-06 15:46:11 +00:00
|
|
|
|
2016-11-24 08:57:28 +00:00
|
|
|
assembler.Return(assembler.StrictEqual(CodeStubAssembler::kNegateResult, lhs,
|
|
|
|
rhs, context));
|
2016-10-06 15:46:11 +00:00
|
|
|
}
|
|
|
|
|
2016-07-20 07:38:14 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|