Commit 64cee297 authored by Peter Marshall's avatar Peter Marshall Committed by Commit Bot

[cleanup] Add CSA types to ToSmiIndex and callers.

Also a small drive-by cleanup to ToSmiLength to make the two functions
more consistent.

Bug: v8:7310
Change-Id: Ied01b72c2d30445eebac2bdab33d96e2df994274
Reviewed-on: https://chromium-review.googlesource.com/931545Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Commit-Queue: Peter Marshall <petermarshall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51497}
parent 6be614fb
......@@ -95,7 +95,7 @@ Node* SharedArrayBufferBuiltinsAssembler::ConvertTaggedAtomicIndexToWord32(
// The |number_index| output parameter is used only for architectures that
// don't currently have a TF implementation and forward to runtime functions
// instead; they expect the value has already been coerced to an integer.
*number_index = ToSmiIndex(tagged, context, &range_error);
*number_index = ToSmiIndex(CAST(tagged), CAST(context), &range_error);
var_result.Bind(SmiToWord32(*number_index));
Goto(&done);
......
......@@ -393,7 +393,7 @@ void TypedArrayBuiltinsAssembler::ConstructByArrayBuffer(
BIND(&length_defined);
{
Node* new_length = ToSmiIndex(length, context, &invalid_length);
TNode<Smi> new_length = ToSmiIndex(length, context, &invalid_length);
GotoIf(IsDetachedBuffer(buffer), &detached_error);
new_byte_length.Bind(SmiMul(new_length, element_size));
// Reading the byte length must come after the ToIndex operation, which
......@@ -411,10 +411,10 @@ void TypedArrayBuiltinsAssembler::ConstructByArrayBuffer(
BIND(&call_init);
{
Node* new_length = CallBuiltin(Builtins::kDivide, context,
new_byte_length.value(), element_size);
TNode<Object> raw_length = CAST(CallBuiltin(
Builtins::kDivide, context, new_byte_length.value(), element_size));
// Force the result into a Smi, or throw a range error if it doesn't fit.
new_length = ToSmiIndex(new_length, context, &invalid_length);
TNode<Smi> new_length = ToSmiIndex(raw_length, context, &invalid_length);
CallBuiltin(Builtins::kTypedArrayInitializeWithBuffer, context, holder,
new_length, buffer, element_size, offset.value());
......
......@@ -6111,32 +6111,35 @@ TNode<JSReceiver> CodeStubAssembler::ToObject(SloppyTNode<Context> context,
return CAST(CallBuiltin(Builtins::kToObject, context, input));
}
Node* CodeStubAssembler::ToSmiIndex(Node* const input, Node* const context,
TNode<Smi> CodeStubAssembler::ToSmiIndex(TNode<Object> input,
TNode<Context> context,
Label* range_error) {
VARIABLE(result, MachineRepresentation::kTagged, input);
TVARIABLE(Smi, result);
Label check_undefined(this), return_zero(this), defined(this),
negative_check(this), done(this);
Branch(TaggedIsSmi(result.value()), &negative_check, &check_undefined);
GotoIfNot(TaggedIsSmi(input), &check_undefined);
result = CAST(input);
Goto(&negative_check);
BIND(&check_undefined);
Branch(IsUndefined(result.value()), &return_zero, &defined);
Branch(IsUndefined(input), &return_zero, &defined);
BIND(&defined);
result.Bind(ToInteger_Inline(CAST(context), CAST(result.value()),
CodeStubAssembler::kTruncateMinusZero));
GotoIfNot(TaggedIsSmi(result.value()), range_error);
CSA_ASSERT(this, TaggedIsSmi(result.value()));
TNode<Object> integer_input =
ToInteger_Inline(context, input, CodeStubAssembler::kTruncateMinusZero);
GotoIfNot(TaggedIsSmi(integer_input), range_error);
result = CAST(integer_input);
Goto(&negative_check);
BIND(&negative_check);
Branch(SmiLessThan(result.value(), SmiConstant(0)), range_error, &done);
BIND(&return_zero);
result.Bind(SmiConstant(0));
result = SmiConstant(0);
Goto(&done);
BIND(&done);
CSA_SLOW_ASSERT(this, TaggedIsSmi(result.value()));
return result.value();
}
......@@ -6144,9 +6147,12 @@ TNode<Smi> CodeStubAssembler::ToSmiLength(TNode<Object> input,
TNode<Context> context,
Label* range_error) {
TVARIABLE(Smi, result);
Label to_integer(this), if_issmi(this), negative_check(this),
Label to_integer(this), negative_check(this),
heap_number_negative_check(this), return_zero(this), done(this);
Branch(TaggedIsSmi(input), &if_issmi, &to_integer);
GotoIfNot(TaggedIsSmi(input), &to_integer);
result = CAST(input);
Goto(&negative_check);
BIND(&to_integer);
{
......@@ -6164,10 +6170,6 @@ TNode<Smi> CodeStubAssembler::ToSmiLength(TNode<Object> input,
&return_zero, range_error);
}
BIND(&if_issmi);
result = CAST(input);
Goto(&negative_check);
BIND(&negative_check);
Branch(SmiLessThan(result.value(), SmiConstant(0)), &return_zero, &done);
......
......@@ -1295,7 +1295,8 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler {
};
// ES6 7.1.17 ToIndex, but jumps to range_error if the result is not a Smi.
Node* ToSmiIndex(Node* const input, Node* const context, Label* range_error);
TNode<Smi> ToSmiIndex(TNode<Object> input, TNode<Context> context,
Label* range_error);
// ES6 7.1.15 ToLength, but jumps to range_error if the result is not a Smi.
TNode<Smi> ToSmiLength(TNode<Object> input, TNode<Context> context,
......
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