Port StringToList to Torque

Bug: v8:8996
Change-Id: I264781f35b7b98cd7c34fc39b9c2451ea6c58ad6
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1606544
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: Simon Zünd <szuend@chromium.org>
Commit-Queue: Z Nguyen-Huu <duongn@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#61498}
This commit is contained in:
Z Duong Nguyen-Huu 2019-05-14 04:34:27 -07:00 committed by Commit Bot
parent 2dd0db19ba
commit bfc3e8bc6b
7 changed files with 44 additions and 75 deletions

View File

@ -2273,6 +2273,9 @@ extern macro CopyFixedArrayElements(
constexpr ElementsKind, FixedArray, constexpr ElementsKind, FixedArray, Smi,
Smi, Smi): void;
extern macro AllocateJSArray(
constexpr ElementsKind, Map, intptr, Smi,
constexpr AllocationFlags): JSArray;
extern macro AllocateJSArray(constexpr ElementsKind, Map, intptr, Smi): JSArray;
extern macro AllocateJSArray(constexpr ElementsKind, Map, Smi, Smi): JSArray;
extern macro AllocateJSArray(Map, FixedArrayBase, Smi): JSArray;

View File

@ -991,8 +991,6 @@ namespace internal {
/* ES6 #sec-string.raw */ \
CPP(StringRaw) \
\
TFS(StringToList, kSource) \
\
/* Symbol */ \
/* ES #sec-symbol-constructor */ \
CPP(SymbolConstructor) \

View File

@ -2178,65 +2178,5 @@ void StringBuiltinsAssembler::BranchIfStringPrimitiveWithNoCustomIteration(
if_true, if_false);
}
// This function assumes StringPrimitiveWithNoCustomIteration is true.
TNode<JSArray> StringBuiltinsAssembler::StringToList(TNode<Context> context,
TNode<String> string) {
const ElementsKind kind = PACKED_ELEMENTS;
const TNode<IntPtrT> length = LoadStringLengthAsWord(string);
TNode<Map> array_map =
LoadJSArrayElementsMap(kind, LoadNativeContext(context));
TNode<JSArray> array =
AllocateJSArray(kind, array_map, length, SmiTag(length), nullptr,
INTPTR_PARAMETERS, kAllowLargeObjectAllocation);
TNode<FixedArrayBase> elements = LoadElements(array);
const int first_element_offset = FixedArray::kHeaderSize - kHeapObjectTag;
TNode<IntPtrT> first_to_element_offset =
ElementOffsetFromIndex(IntPtrConstant(0), kind, INTPTR_PARAMETERS, 0);
TNode<IntPtrT> first_offset =
IntPtrAdd(first_to_element_offset, IntPtrConstant(first_element_offset));
TVARIABLE(IntPtrT, var_offset, first_offset);
TVARIABLE(IntPtrT, var_position, IntPtrConstant(0));
Label done(this), next_codepoint(this, {&var_position, &var_offset});
Goto(&next_codepoint);
BIND(&next_codepoint);
{
// Loop condition.
GotoIfNot(IntPtrLessThan(var_position.value(), length), &done);
const UnicodeEncoding encoding = UnicodeEncoding::UTF16;
TNode<Int32T> ch =
LoadSurrogatePairAt(string, length, var_position.value(), encoding);
TNode<String> value = StringFromSingleCodePoint(ch, encoding);
Store(elements, var_offset.value(), value);
// Increment the position.
TNode<IntPtrT> ch_length = LoadStringLengthAsWord(value);
var_position = IntPtrAdd(var_position.value(), ch_length);
// Increment the array offset and continue the loop.
var_offset = IntPtrAdd(var_offset.value(), IntPtrConstant(kTaggedSize));
Goto(&next_codepoint);
}
BIND(&done);
TNode<IntPtrT> new_length = IntPtrDiv(
IntPtrSub(var_offset.value(), first_offset), IntPtrConstant(kTaggedSize));
CSA_ASSERT(this, IntPtrGreaterThanOrEqual(new_length, IntPtrConstant(0)));
CSA_ASSERT(this, IntPtrGreaterThanOrEqual(length, new_length));
StoreObjectFieldNoWriteBarrier(array, JSArray::kLengthOffset,
SmiTag(new_length));
return UncheckedCast<JSArray>(array);
}
TF_BUILTIN(StringToList, StringBuiltinsAssembler) {
TNode<Context> context = CAST(Parameter(Descriptor::kContext));
TNode<String> string = CAST(Parameter(Descriptor::kSource));
Return(StringToList(context, string));
}
} // namespace internal
} // namespace v8

View File

@ -34,8 +34,6 @@ class StringBuiltinsAssembler : public CodeStubAssembler {
UnicodeEncoding encoding);
protected:
TNode<JSArray> StringToList(TNode<Context> context, TNode<String> string);
void StringEqual_Loop(Node* lhs, Node* lhs_instance_type,
MachineType lhs_type, Node* rhs,
Node* rhs_instance_type, MachineType rhs_type,

View File

@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include 'src/builtins/builtins-string-gen.h'
namespace string_iterator {
macro NewJSStringIterator(implicit context: Context)(
@ -26,11 +24,6 @@ namespace string_iterator {
return NewJSStringIterator(name, index);
}
extern macro StringBuiltinsAssembler::LoadSurrogatePairAt(
String, intptr, intptr, constexpr UnicodeEncoding): int32;
extern macro StringFromSingleCodePoint(int32, constexpr UnicodeEncoding):
String;
// ES6 #sec-%stringiteratorprototype%.next
transitioning javascript builtin StringIteratorPrototypeNext(
implicit context: Context)(receiver: Object): JSIteratorResult {
@ -45,8 +38,8 @@ namespace string_iterator {
}
// Move to next codepoint.
const encoding = UTF16;
const ch = LoadSurrogatePairAt(string, length, position, encoding);
const value: String = StringFromSingleCodePoint(ch, encoding);
const ch = string::LoadSurrogatePairAt(string, length, position, encoding);
const value: String = string::StringFromSingleCodePoint(ch, encoding);
iterator.next_index = SmiTag(position + value.length_intptr);
return NewJSIteratorResult(value, False);
}

View File

@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include 'src/builtins/builtins-string-gen.h'
namespace string {
// ES6 #sec-string.prototype.tostring
transitioning javascript builtin
@ -14,4 +16,38 @@ namespace string {
StringPrototypeValueOf(implicit context: Context)(receiver: Object): Object {
return ToThisValue(receiver, kString, 'String.prototype.valueOf');
}
extern macro StringBuiltinsAssembler::LoadSurrogatePairAt(
String, intptr, intptr, constexpr UnicodeEncoding): int32;
extern macro StringFromSingleCodePoint(int32, constexpr UnicodeEncoding):
String;
// This function assumes StringPrimitiveWithNoCustomIteration is true.
transitioning builtin StringToList(implicit context: Context)(string: String):
JSArray {
const kind = PACKED_ELEMENTS;
const stringLength: intptr = string.length_intptr;
const map: Map = LoadJSArrayElementsMap(kind, LoadNativeContext(context));
const array: JSArray = AllocateJSArray(
kind, map, stringLength, SmiTag(stringLength),
kAllowLargeObjectAllocation);
const elements = UnsafeCast<FixedArray>(array.elements);
const encoding = UTF16;
let arrayLength: Smi = 0;
let i: intptr = 0;
while (i < stringLength) {
const ch: int32 = LoadSurrogatePairAt(string, stringLength, i, encoding);
const value: String = StringFromSingleCodePoint(ch, encoding);
elements[arrayLength] = value;
// Increment and continue the loop.
i = i + value.length_intptr;
arrayLength++;
}
assert(arrayLength >= 0);
assert(SmiTag(stringLength) >= arrayLength);
array.length = arrayLength;
return array;
}
}

View File

@ -1612,9 +1612,10 @@ class V8_EXPORT_PRIVATE CodeStubAssembler
}
TNode<JSArray> AllocateJSArray(ElementsKind kind, TNode<Map> array_map,
TNode<IntPtrT> capacity, TNode<Smi> length) {
TNode<IntPtrT> capacity, TNode<Smi> length,
AllocationFlags allocation_flags = kNone) {
return AllocateJSArray(kind, array_map, capacity, length, nullptr,
INTPTR_PARAMETERS);
INTPTR_PARAMETERS, allocation_flags);
}
// Allocate a JSArray and initialize the header fields.