Commit fc2d563a authored by Peter Marshall's avatar Peter Marshall Committed by Commit Bot

[clenaup] Add CSA types to some number helpers

Change-Id: I3255e2ed0e370e019cf06e95aaf4fe2eb9ce5de1
Reviewed-on: https://chromium-review.googlesource.com/980760
Commit-Queue: Peter Marshall <petermarshall@chromium.org>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#52269}
parent 77a71f85
......@@ -4750,7 +4750,12 @@ Node* CodeStubAssembler::IsJSRegExp(Node* object) {
return HasInstanceType(object, JS_REGEXP_TYPE);
}
Node* CodeStubAssembler::IsNumeric(Node* object) {
TNode<BoolT> CodeStubAssembler::IsNumber(SloppyTNode<Object> object) {
return Select<BoolT>(TaggedIsSmi(object), [=] { return Int32TrueConstant(); },
[=] { return IsHeapNumber(object); });
}
TNode<BoolT> CodeStubAssembler::IsNumeric(SloppyTNode<Object> object) {
return Select<BoolT>(TaggedIsSmi(object), [=] { return Int32TrueConstant(); },
[=] {
return UncheckedCast<BoolT>(
......@@ -4758,56 +4763,41 @@ Node* CodeStubAssembler::IsNumeric(Node* object) {
});
}
Node* CodeStubAssembler::IsNumber(Node* object) {
return Select<BoolT>(TaggedIsSmi(object), [=] { return Int32TrueConstant(); },
[=] { return IsHeapNumber(object); });
}
Node* CodeStubAssembler::FixedArraySizeDoesntFitInNewSpace(Node* element_count,
int base_size,
ParameterMode mode) {
int max_newspace_elements =
(kMaxRegularHeapObjectSize - base_size) / kPointerSize;
return IntPtrOrSmiGreaterThan(
element_count, IntPtrOrSmiConstant(max_newspace_elements, mode), mode);
}
Node* CodeStubAssembler::IsNumberNormalized(Node* number) {
CSA_ASSERT(this, IsNumber(number));
VARIABLE(var_result, MachineRepresentation::kWord32, Int32Constant(1));
TNode<BoolT> CodeStubAssembler::IsNumberNormalized(SloppyTNode<Number> number) {
TVARIABLE(BoolT, var_result, Int32TrueConstant());
Label out(this);
GotoIf(TaggedIsSmi(number), &out);
Node* const value = LoadHeapNumberValue(number);
Node* const smi_min = Float64Constant(static_cast<double>(Smi::kMinValue));
Node* const smi_max = Float64Constant(static_cast<double>(Smi::kMaxValue));
TNode<Float64T> value = LoadHeapNumberValue(CAST(number));
TNode<Float64T> smi_min =
Float64Constant(static_cast<double>(Smi::kMinValue));
TNode<Float64T> smi_max =
Float64Constant(static_cast<double>(Smi::kMaxValue));
GotoIf(Float64LessThan(value, smi_min), &out);
GotoIf(Float64GreaterThan(value, smi_max), &out);
GotoIfNot(Float64Equal(value, value), &out); // NaN.
var_result.Bind(Int32Constant(0));
var_result = Int32FalseConstant();
Goto(&out);
BIND(&out);
return var_result.value();
}
Node* CodeStubAssembler::IsNumberPositive(Node* number) {
CSA_ASSERT(this, IsNumber(number));
Node* const float_zero = Float64Constant(0.);
TNode<BoolT> CodeStubAssembler::IsNumberPositive(SloppyTNode<Number> number) {
TNode<Float64T> float_zero = Float64Constant(0.);
return Select<BoolT>(TaggedIsSmi(number),
[=] { return TaggedIsPositiveSmi(number); },
[=] {
Node* v = LoadHeapNumberValue(number);
TNode<Float64T> v = LoadHeapNumberValue(CAST(number));
return Float64GreaterThanOrEqual(v, float_zero);
});
}
Node* CodeStubAssembler::IsNumberArrayIndex(Node* number) {
VARIABLE(var_result, MachineRepresentation::kWord32, Int32Constant(1));
TNode<BoolT> CodeStubAssembler::IsNumberArrayIndex(SloppyTNode<Number> number) {
TVARIABLE(BoolT, var_result, Int32TrueConstant());
Label check_upper_bound(this), check_is_integer(this), out(this),
return_false(this);
......@@ -4823,19 +4813,28 @@ Node* CodeStubAssembler::IsNumberArrayIndex(Node* number) {
BIND(&check_is_integer);
GotoIf(TaggedIsSmi(number), &out);
// Check that the HeapNumber is a valid uint32
Node* value = LoadHeapNumberValue(number);
Node* int_value = ChangeFloat64ToUint32(value);
TNode<Float64T> value = LoadHeapNumberValue(CAST(number));
TNode<Uint32T> int_value = ChangeFloat64ToUint32(value);
GotoIf(Float64Equal(value, ChangeUint32ToFloat64(int_value)), &out);
Goto(&return_false);
BIND(&return_false);
var_result.Bind(Int32Constant(0));
var_result = Int32FalseConstant();
Goto(&out);
BIND(&out);
return var_result.value();
}
Node* CodeStubAssembler::FixedArraySizeDoesntFitInNewSpace(Node* element_count,
int base_size,
ParameterMode mode) {
int max_newspace_elements =
(kMaxRegularHeapObjectSize - base_size) / kPointerSize;
return IntPtrOrSmiGreaterThan(
element_count, IntPtrOrSmiConstant(max_newspace_elements, mode), mode);
}
TNode<Int32T> CodeStubAssembler::StringCharCodeAt(SloppyTNode<String> string,
SloppyTNode<IntPtrT> index) {
CSA_ASSERT(this, IsString(string));
......@@ -6238,8 +6237,9 @@ TNode<Number> CodeStubAssembler::ToInteger(SloppyTNode<Context> context,
}
BIND(&out);
if (mode == kTruncateMinusZero)
CSA_ASSERT(this, IsNumberNormalized(var_arg.value()));
if (mode == kTruncateMinusZero) {
CSA_ASSERT(this, IsNumberNormalized(CAST(var_arg.value())));
}
return CAST(var_arg.value());
}
......
......@@ -1200,17 +1200,21 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler {
Node* IsSpeciesProtectorCellInvalid();
// True iff |object| is a Smi or a HeapNumber.
Node* IsNumber(Node* object);
TNode<BoolT> IsNumber(SloppyTNode<Object> object);
// True iff |object| is a Smi or a HeapNumber or a BigInt.
Node* IsNumeric(Node* object);
TNode<BoolT> IsNumeric(SloppyTNode<Object> object);
// True iff |number| is either a Smi, or a HeapNumber whose value is not
// within Smi range.
Node* IsNumberNormalized(Node* number);
Node* IsNumberPositive(Node* number);
TNode<BoolT> IsNumberNormalized(SloppyTNode<Number> number);
TNode<BoolT> IsNumberPositive(SloppyTNode<Number> number);
// True iff {number} is a positive number and a valid array index in the range
// [0, 2^32-1).
Node* IsNumberArrayIndex(Node* number);
TNode<BoolT> IsNumberArrayIndex(SloppyTNode<Number> number);
Node* FixedArraySizeDoesntFitInNewSpace(
Node* element_count, int base_size = FixedArray::kHeaderSize,
ParameterMode mode = INTPTR_PARAMETERS);
// ElementsKind helpers:
Node* IsFastElementsKind(Node* elements_kind);
......@@ -1219,10 +1223,6 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler {
Node* IsElementsKindGreaterThan(Node* target_kind,
ElementsKind reference_kind);
Node* FixedArraySizeDoesntFitInNewSpace(
Node* element_count, int base_size = FixedArray::kHeaderSize,
ParameterMode mode = INTPTR_PARAMETERS);
// String helpers.
// Load a character from a String (might flatten a ConsString).
TNode<Int32T> StringCharCodeAt(SloppyTNode<String> string,
......
......@@ -2727,7 +2727,8 @@ TEST(IsNumberArrayIndex) {
CodeAssemblerTester asm_tester(isolate, kNumParams);
{
CodeStubAssembler m(asm_tester.state());
m.Return(m.SmiFromInt32(m.IsNumberArrayIndex(m.Parameter(0))));
m.Return(m.SmiFromInt32(
m.UncheckedCast<Int32T>(m.IsNumberArrayIndex(m.Parameter(0)))));
}
FunctionTester ft(asm_tester.GenerateCode(), kNumParams);
......
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