Commit d1c15973 authored by peterwmwong's avatar peterwmwong Committed by Commit Bot

[builtins] Port TypedArray join, toString, and toLocaleString to Torque.

Micro-benchmarks show speed improvements across the various types:

TypedArrays-JoinBigIntTypes                7246   8297  14.50%
TypedArrays-JoinBigIntTypes                7194   8637  20.06%
TypedArrays-JoinBigIntTypes                7258   8586  18.30%
TypedArrays-JoinFloatTypes                24461  28628  17.04%
TypedArrays-JoinFloatTypes                24523  29647  20.89%
TypedArrays-JoinFloatTypes                24419  29327  20.10%
TypedArrays-JoinIntTypes                  23378  33928  45.13%
TypedArrays-JoinIntTypes                  23333  34034  45.86%
TypedArrays-JoinIntTypes                  21653  34000  57.02%
TypedArrays-JoinWithSeparatorBigIntTypes   6620   7339  10.86%
TypedArrays-JoinWithSeparatorBigIntTypes   6566   7579  15.43%
TypedArrays-JoinWithSeparatorBigIntTypes   6631   7481  12.82%
TypedArrays-JoinWithSeparatorFloatTypes   18695  19670   5.22%
TypedArrays-JoinWithSeparatorFloatTypes   18518  20088   8.48%
TypedArrays-JoinWithSeparatorFloatTypes   18482  20193   9.26%
TypedArrays-JoinWithSeparatorIntTypes     17849  21482  20.35%
TypedArrays-JoinWithSeparatorIntTypes     17831  21578  21.01%
TypedArrays-JoinWithSeparatorIntTypes     17937  21578  20.30%

Drive-by: Removed unused CSA helper InternalArrayCreate.

Bug: v8:7624
Change-Id: I8e63815982439cfd2267417d03cd2b71b4b7a812
Reviewed-on: https://chromium-review.googlesource.com/c/1369330
Commit-Queue: Peter Wong <peter.wm.wong@gmail.com>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Reviewed-by: 's avatarPeter Marshall <petermarshall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58167}
parent 9b4f14de
......@@ -724,8 +724,6 @@ action("js2c") {
"src/js/macros.py",
"src/message-template.h",
"src/js/prologue.js",
"src/js/array.js",
"src/js/typedarray.js",
]
outputs = [
......
......@@ -1629,6 +1629,7 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
*info);
}
Handle<JSFunction> array_prototype_to_string_fun;
{ // --- A r r a y ---
Handle<JSFunction> array_function = InstallFunction(
isolate_, global, "Array", JS_ARRAY_TYPE, JSArray::kSize, 0,
......@@ -1745,8 +1746,9 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
Builtins::kArrayReduceRight, 1, false);
SimpleInstallFunction(isolate_, proto, "toLocaleString",
Builtins::kArrayPrototypeToLocaleString, 0, false);
SimpleInstallFunction(isolate_, proto, "toString",
Builtins::kArrayPrototypeToString, 0, false);
array_prototype_to_string_fun =
SimpleInstallFunction(isolate_, proto, "toString",
Builtins::kArrayPrototypeToString, 0, false);
}
{ // --- A r r a y I t e r a t o r ---
......@@ -3201,6 +3203,8 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
Builtins::kTypedArrayPrototypeIncludes, 1, false);
SimpleInstallFunction(isolate_, prototype, "indexOf",
Builtins::kTypedArrayPrototypeIndexOf, 1, false);
SimpleInstallFunction(isolate_, prototype, "join",
Builtins::kTypedArrayPrototypeJoin, 1, false);
SimpleInstallFunction(isolate_, prototype, "lastIndexOf",
Builtins::kTypedArrayPrototypeLastIndexOf, 1, false);
SimpleInstallFunction(isolate_, prototype, "map",
......@@ -3221,6 +3225,11 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
Builtins::kTypedArrayPrototypeSort, 1, false);
SimpleInstallFunction(isolate_, prototype, "subarray",
Builtins::kTypedArrayPrototypeSubArray, 2, false);
SimpleInstallFunction(isolate_, prototype, "toLocaleString",
Builtins::kTypedArrayPrototypeToLocaleString, 0,
false);
JSObject::AddProperty(isolate_, prototype, factory->toString_string(),
array_prototype_to_string_fun, DONT_ENUM);
}
{ // -- T y p e d A r r a y s
......
This diff is collapsed.
......@@ -322,7 +322,6 @@ extern macro ThrowTypeError(
Context, constexpr MessageTemplate, Object, Object, Object): never;
extern macro ArraySpeciesCreate(Context, Object, Number): JSReceiver;
extern macro ArrayCreate(implicit context: Context)(Number): JSArray;
extern macro InternalArrayCreate(Context, Number): JSArray;
extern macro EnsureArrayPushable(Map): ElementsKind
labels Bailout;
extern macro EnsureArrayLengthWritable(Map) labels Bailout;
......@@ -526,6 +525,8 @@ extern macro IsValidPositiveSmi(intptr): bool;
extern macro HeapObjectToJSDataView(HeapObject): JSDataView
labels CastError;
extern macro HeapObjectToJSTypedArray(HeapObject): JSTypedArray
labels CastError;
extern macro TaggedToHeapObject(Object): HeapObject
labels CastError;
extern macro TaggedToSmi(Object): Smi
......@@ -578,6 +579,12 @@ CastHeapObject<JSDataView>(o: HeapObject): JSDataView
return HeapObjectToJSDataView(o) otherwise CastError;
}
CastHeapObject<JSTypedArray>(o: HeapObject): JSTypedArray
labels CastError {
if (IsJSTypedArray(o)) return %RawObjectCast<JSTypedArray>(o);
goto CastError;
}
CastHeapObject<Callable>(o: HeapObject): Callable
labels CastError {
return HeapObjectToCallable(o) otherwise CastError;
......@@ -1180,6 +1187,7 @@ extern macro IsJSArray(HeapObject): bool;
extern macro IsMap(HeapObject): bool;
extern macro IsJSFunction(HeapObject): bool;
extern macro IsJSObject(HeapObject): bool;
extern macro IsJSTypedArray(HeapObject): bool;
extern macro IsNumberDictionary(HeapObject): bool;
extern macro IsFixedTypedArray(HeapObject): bool;
extern macro IsContext(HeapObject): bool;
......
......@@ -12928,14 +12928,6 @@ TNode<JSReceiver> CodeStubAssembler::ArraySpeciesCreate(TNode<Context> context,
return Construct(context, constructor, len);
}
TNode<JSReceiver> CodeStubAssembler::InternalArrayCreate(TNode<Context> context,
TNode<Number> len) {
TNode<Context> native_context = LoadNativeContext(context);
TNode<JSReceiver> constructor = CAST(LoadContextElement(
native_context, Context::INTERNAL_ARRAY_FUNCTION_INDEX));
return Construct(context, constructor, len);
}
Node* CodeStubAssembler::IsDetachedBuffer(Node* buffer) {
CSA_ASSERT(this, HasInstanceType(buffer, JS_ARRAY_BUFFER_TYPE));
TNode<Uint32T> buffer_bit_field = LoadJSArrayBufferBitField(CAST(buffer));
......
......@@ -1516,8 +1516,6 @@ class V8_EXPORT_PRIVATE CodeStubAssembler
TNode<JSReceiver> ArraySpeciesCreate(TNode<Context> context,
TNode<Object> originalArray,
TNode<Number> len);
TNode<JSReceiver> InternalArrayCreate(TNode<Context> context,
TNode<Number> len);
void FillFixedArrayWithValue(ElementsKind kind, Node* array, Node* from_index,
Node* to_index, RootIndex value_root_index,
......
This diff is collapsed.
......@@ -68,6 +68,8 @@ function SetUpLockedPrototype(
%ToFastProperties(prototype);
}
var GlobalArray = global.Array;
var InternalArray;
// -----------------------------------------------------------------------
// To be called by bootstrapper
......@@ -75,6 +77,81 @@ function SetUpLockedPrototype(
function PostNatives(utils) {
%CheckIsBootstrapping();
// -------------------------------------------------------------------
// Array
InternalArray = utils.InternalArray;
var iteratorSymbol = ImportNow("iterator_symbol");
var unscopablesSymbol = ImportNow("unscopables_symbol");
// Set up unscopable properties on the Array.prototype object.
var unscopables = {
__proto__: null,
copyWithin: true,
entries: true,
fill: true,
find: true,
findIndex: true,
includes: true,
keys: true,
};
%ToFastProperties(unscopables);
%AddNamedProperty(GlobalArray.prototype, unscopablesSymbol, unscopables,
DONT_ENUM | READ_ONLY);
var ArrayIndexOf = GlobalArray.prototype.indexOf;
var ArrayJoin = GlobalArray.prototype.join;
var ArrayPop = GlobalArray.prototype.pop;
var ArrayPush = GlobalArray.prototype.push;
var ArraySlice = GlobalArray.prototype.slice;
var ArrayShift = GlobalArray.prototype.shift;
var ArraySort = GlobalArray.prototype.sort;
var ArraySplice = GlobalArray.prototype.splice;
var ArrayUnshift = GlobalArray.prototype.unshift;
// Array prototype functions that return iterators. They are exposed to the
// public API via Template::SetIntrinsicDataProperty().
var ArrayEntries = GlobalArray.prototype.entries;
var ArrayForEach = GlobalArray.prototype.forEach;
var ArrayKeys = GlobalArray.prototype.keys;
var ArrayValues = GlobalArray.prototype[iteratorSymbol];
// The internal Array prototype doesn't need to be fancy, since it's never
// exposed to user code.
// Adding only the functions that are actually used.
SetUpLockedPrototype(InternalArray, GlobalArray(), [
"indexOf", ArrayIndexOf,
"join", ArrayJoin,
"pop", ArrayPop,
"push", ArrayPush,
"shift", ArrayShift,
"sort", ArraySort,
"splice", ArraySplice
]);
// V8 extras get a separate copy of InternalPackedArray. We give them the basic
// manipulation methods.
SetUpLockedPrototype(extrasUtils.InternalPackedArray, GlobalArray(), [
"push", ArrayPush,
"pop", ArrayPop,
"shift", ArrayShift,
"unshift", ArrayUnshift,
"splice", ArraySplice,
"slice", ArraySlice
]);
%InstallToContext([
"array_entries_iterator", ArrayEntries,
"array_for_each_iterator", ArrayForEach,
"array_keys_iterator", ArrayKeys,
"array_values_iterator", ArrayValues,
]);
// -------------------------------------------------------------------
for ( ; !IS_UNDEFINED(imports); imports = imports.next) {
imports(exports_container);
}
......@@ -94,7 +171,6 @@ function PostNatives(utils) {
utils.Import = Import;
utils.ImportNow = ImportNow;
utils.Export = Export;
utils.SetUpLockedPrototype = SetUpLockedPrototype;
utils.PostNatives = PostNatives;
%ToFastProperties(utils);
......
// Copyright 2013 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.
(function(global, utils) {
"use strict";
%CheckIsBootstrapping();
// -------------------------------------------------------------------
// Imports
// array.js has to come before typedarray.js for this to work
var ArrayToString = utils.ImportNow("ArrayToString");
var InnerArrayJoin;
var InnerArrayToLocaleString;
macro TYPED_ARRAYS(FUNCTION)
FUNCTION(Uint8Array, 1)
FUNCTION(Int8Array, 1)
FUNCTION(Uint16Array, 2)
FUNCTION(Int16Array, 2)
FUNCTION(Uint32Array, 4)
FUNCTION(Int32Array, 4)
FUNCTION(Float32Array, 4)
FUNCTION(Float64Array, 8)
FUNCTION(Uint8ClampedArray, 1)
FUNCTION(BigUint64Array, 8)
FUNCTION(BigInt64Array, 8)
endmacro
macro DECLARE_GLOBALS(NAME, SIZE)
var GlobalNAME = global.NAME;
endmacro
TYPED_ARRAYS(DECLARE_GLOBALS)
macro IS_TYPEDARRAY(arg)
(%_IsTypedArray(arg))
endmacro
var GlobalTypedArray = %object_get_prototype_of(GlobalUint8Array);
utils.Import(function(from) {
InnerArrayJoin = from.InnerArrayJoin;
InnerArrayToLocaleString = from.InnerArrayToLocaleString;
});
// --------------- Typed Arrays ---------------------
// ES6 section 22.2.3.5.1 ValidateTypedArray ( O )
function ValidateTypedArray(array, methodName) {
if (!IS_TYPEDARRAY(array)) throw %make_type_error(kNotTypedArray);
if (%ArrayBufferViewWasDetached(array))
throw %make_type_error(kDetachedOperation, methodName);
}
// ES6 section 22.2.3.27
// ecma402 #sup-array.prototype.tolocalestring
DEFINE_METHOD(
GlobalTypedArray.prototype,
toLocaleString() {
ValidateTypedArray(this, "%TypedArray%.prototype.toLocaleString");
var locales = arguments[0];
var options = arguments[1];
var length = %TypedArrayGetLength(this);
return InnerArrayToLocaleString(this, length, locales, options);
}
);
// ES6 section 22.2.3.14
DEFINE_METHOD(
GlobalTypedArray.prototype,
join(separator) {
ValidateTypedArray(this, "%TypedArray%.prototype.join");
var length = %TypedArrayGetLength(this);
return InnerArrayJoin(separator, this, length);
}
);
// -------------------------------------------------------------------
%AddNamedProperty(GlobalTypedArray.prototype, "toString", ArrayToString,
DONT_ENUM);
})
......@@ -4296,9 +4296,9 @@ UNINITIALIZED_TEST(LoadedAtStartupScripts) {
CHECK_EQ(count_by_type[i::Script::TYPE_WASM], 0);
CHECK_EQ(count_by_type[i::Script::TYPE_INSPECTOR], 0);
i::Handle<i::Script> native_array_script =
FindScript(i_isolate, scripts, "native array.js").ToHandleChecked();
CHECK_EQ(native_array_script->type(), i::Script::TYPE_NATIVE);
i::Handle<i::Script> native_prologue_script =
FindScript(i_isolate, scripts, "native prologue.js").ToHandleChecked();
CHECK_EQ(native_prologue_script->type(), i::Script::TYPE_NATIVE);
i::Handle<i::Script> gc_script =
FindScript(i_isolate, scripts, "v8/gc").ToHandleChecked();
......
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