[csa] Add IsNumber and IsNumberNormalized predicates

IsNumber returns true for Smi/HeapNumber arguments.

IsNumberNormalized expects a number argument and returns true if
it is either a Smi, or a HeapNumber with a value outside the Smi
range.

BUG=

Review-Url: https://codereview.chromium.org/2813623003
Cr-Commit-Position: refs/heads/master@{#44556}
This commit is contained in:
jgruber 2017-04-11 03:28:14 -07:00 committed by Commit bot
parent 55f5bac450
commit ea3bd03945
3 changed files with 39 additions and 6 deletions

View File

@ -249,7 +249,7 @@ Node* RegExpBuiltinsAssembler::IrregexpExec(Node* const context,
CSA_ASSERT(this, TaggedIsNotSmi(string));
CSA_ASSERT(this, IsString(string));
CSA_ASSERT(this, IsHeapNumberMap(LoadReceiverMap(last_index)));
CSA_ASSERT(this, IsNumber(last_index));
CSA_ASSERT(this, IsFixedArrayMap(LoadReceiverMap(match_info)));
Node* const int_zero = IntPtrConstant(0);
@ -1548,12 +1548,9 @@ Node* RegExpBuiltinsAssembler::AdvanceStringIndex(Node* const string,
Node* const is_unicode,
bool is_fastpath) {
CSA_ASSERT(this, IsString(string));
CSA_ASSERT(this, IsHeapNumberMap(LoadReceiverMap(index)));
CSA_ASSERT(this, IsNumberNormalized(index));
if (is_fastpath) CSA_ASSERT(this, TaggedIsPositiveSmi(index));
// Default to last_index + 1.
// Smi range.
// Default to last_index + 1.
Node* const index_plus_one = NumberInc(index);
VARIABLE(var_result, MachineRepresentation::kTagged, index_plus_one);
@ -2368,7 +2365,7 @@ TF_BUILTIN(RegExpSplit, RegExpBuiltinsAssembler) {
{
// The runtime call passes in limit to ensure the second ToUint32(limit)
// call is not observable.
CSA_ASSERT(this, IsHeapNumberMap(LoadReceiverMap(limit)));
CSA_ASSERT(this, IsNumber(limit));
Return(CallRuntime(Runtime::kRegExpSplit, context, regexp, string, limit));
}
}

View File

@ -3152,6 +3152,35 @@ Node* CodeStubAssembler::IsJSRegExp(Node* object) {
return HasInstanceType(object, JS_REGEXP_TYPE);
}
Node* CodeStubAssembler::IsNumber(Node* object) {
return Select(TaggedIsSmi(object), [=] { return Int32Constant(1); },
[=] { return IsHeapNumber(object); },
MachineRepresentation::kWord32);
}
Node* CodeStubAssembler::IsNumberNormalized(Node* number) {
CSA_ASSERT(this, IsNumber(number));
VARIABLE(var_result, MachineRepresentation::kWord32, Int32Constant(1));
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));
GotoIf(Float64LessThan(value, smi_min), &out);
GotoIf(Float64GreaterThan(value, smi_max), &out);
GotoIfNot(Float64Equal(value, value), &out); // NaN.
var_result.Bind(Int32Constant(0));
Goto(&out);
BIND(&out);
return var_result.value();
}
Node* CodeStubAssembler::StringCharCodeAt(Node* string, Node* index,
ParameterMode parameter_mode) {
if (parameter_mode == SMI_PARAMETERS) CSA_ASSERT(this, TaggedIsSmi(index));

View File

@ -739,6 +739,13 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler {
Node* IsFixedTypedArray(Node* object);
Node* IsJSRegExp(Node* object);
// True iff |object| is a Smi or a HeapNumber.
Node* IsNumber(Node* object);
// True iff |number| is either a Smi, or a HeapNumber whose value is not
// within Smi range.
Node* IsNumberNormalized(Node* number);
// ElementsKind helpers:
Node* IsFastElementsKind(Node* elements_kind);
Node* IsHoleyFastElementsKind(Node* elements_kind);