Commit 8e13ddc6 authored by peterwmwong's avatar peterwmwong Committed by Commit Bot

[builtins] Port TypedArray TypedArrayInitializeWithBuffer to Torque

Two small changes were done as part of the port:
- Changes TypedArrayInitializeWithBuffer from a TFS builtin to a macro.
  It was only called from ConstructByArrayBuffer and this removes the
  overhead of the TFS call.
- Introduces a GetTypedArrayElementsInfo that retrieves both the element
  size and map. Instead of generating the elements kind switch code (
  DispatchTypedArrayByElementsKind) twice, just generate once at the
  beginning of CreateTypedArray.

This reduces overall builtins size by 364 bytes (Mac x64.release)
  - Before
    1364 - TypedArrayInitializeWithBuffer
    6468 - CreateTypedArray
  - After
    7468 - CreateTypedArray

This also improves performance of TypedArray JSPerf benchmarks
(SubarrayNoSpecies, ConstructByArrayBuffer) by 5-8%.

Bug: v8:7161
Change-Id: I68eed2ea4db103f44ad9751229c29fba9bc9d24d
Reviewed-on: https://chromium-review.googlesource.com/c/1437822
Commit-Queue: Peter Wong <peter.wm.wong@gmail.com>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#59135}
parent 7215f6d6
......@@ -1157,8 +1157,6 @@ namespace internal {
/* TypedArray */ \
TFS(TypedArrayInitialize, kHolder, kLength, kElementSize, kInitialize, \
kBufferConstructor) \
TFS(TypedArrayInitializeWithBuffer, kHolder, kLength, kBuffer, kElementSize, \
kByteOffset) \
/* ES #sec-typedarray-constructors */ \
TFJ(TypedArrayBaseConstructor, 0, kReceiver) \
TFJ(GenericConstructorLazyDeoptContinuation, 1, kReceiver, kResult) \
......
......@@ -10,7 +10,6 @@
#include "src/builtins/growable-fixed-array-gen.h"
#include "src/handles-inl.h"
#include "src/heap/factory-inl.h"
#include "torque-generated/builtins-typed-array-from-dsl-gen.h"
namespace v8 {
namespace internal {
......@@ -106,24 +105,6 @@ void TypedArrayBuiltinsAssembler::AttachBuffer(TNode<JSTypedArray> holder,
StoreObjectField(holder, JSObject::kElementsOffset, elements);
}
TF_BUILTIN(TypedArrayInitializeWithBuffer, TypedArrayBuiltinsAssembler) {
TNode<JSTypedArray> holder = CAST(Parameter(Descriptor::kHolder));
TNode<Smi> length = CAST(Parameter(Descriptor::kLength));
TNode<JSArrayBuffer> buffer = CAST(Parameter(Descriptor::kBuffer));
TNode<Smi> element_size = CAST(Parameter(Descriptor::kElementSize));
TNode<Number> byte_offset = CAST(Parameter(Descriptor::kByteOffset));
TNode<Map> fixed_typed_map = LoadMapForType(holder);
// SmiMul returns a heap number in case of Smi overflow.
TNode<Number> byte_length = SmiMul(length, element_size);
SetupTypedArray(holder, length, ChangeNonnegativeNumberToUintPtr(byte_offset),
ChangeNonnegativeNumberToUintPtr(byte_length));
AttachBuffer(holder, buffer, fixed_typed_map, length, byte_offset);
Return(UndefinedConstant());
}
TF_BUILTIN(TypedArrayInitialize, TypedArrayBuiltinsAssembler) {
TNode<JSTypedArray> holder = CAST(Parameter(Descriptor::kHolder));
TNode<Smi> length = CAST(Parameter(Descriptor::kLength));
......@@ -463,6 +444,28 @@ TNode<IntPtrT> TypedArrayBuiltinsAssembler::GetTypedArrayElementSize(
return element_size.value();
}
TypedArrayBuiltinsFromDSLAssembler::TypedArrayElementsInfo
TypedArrayBuiltinsAssembler::GetTypedArrayElementsInfo(
TNode<JSTypedArray> typed_array) {
TNode<Int32T> elements_kind = LoadElementsKind(typed_array);
TVARIABLE(Smi, var_element_size);
TVARIABLE(Map, var_map);
ReadOnlyRoots roots(isolate());
DispatchTypedArrayByElementsKind(
elements_kind,
[&](ElementsKind kind, int size, int typed_array_fun_index) {
DCHECK_GT(size, 0);
var_element_size = SmiConstant(size);
Handle<Map> map(roots.MapForFixedTypedArray(kind), isolate());
var_map = HeapConstant(map);
});
return TypedArrayBuiltinsFromDSLAssembler::TypedArrayElementsInfo{
var_element_size.value(), var_map.value(), elements_kind};
}
TNode<JSFunction> TypedArrayBuiltinsAssembler::GetDefaultConstructor(
TNode<Context> context, TNode<JSTypedArray> exemplar) {
TVARIABLE(IntPtrT, context_slot);
......
......@@ -6,6 +6,7 @@
#define V8_BUILTINS_BUILTINS_TYPED_ARRAY_GEN_H_
#include "src/code-stub-assembler.h"
#include "torque-generated/builtins-typed-array-from-dsl-gen.h"
namespace v8 {
namespace internal {
......@@ -52,6 +53,10 @@ class TypedArrayBuiltinsAssembler : public CodeStubAssembler {
// Returns the byte size of an element for a TypedArray elements kind.
TNode<IntPtrT> GetTypedArrayElementSize(TNode<Word32T> elements_kind);
// Returns information (byte size and map) about a TypedArray's elements.
TypedArrayBuiltinsFromDSLAssembler::TypedArrayElementsInfo
GetTypedArrayElementsInfo(TNode<JSTypedArray> typed_array);
TNode<JSArrayBuffer> LoadTypedArrayBuffer(TNode<JSTypedArray> typed_array) {
return LoadObjectField<JSArrayBuffer>(typed_array,
JSTypedArray::kBufferOffset);
......
......@@ -5,10 +5,18 @@
#include 'src/builtins/builtins-typed-array-gen.h'
namespace typed_array {
struct TypedArrayElementsInfo {
size: PositiveSmi;
map: Map;
kind: ElementsKind;
}
extern runtime TypedArraySortFast(Context, Object): JSTypedArray;
extern macro TypedArrayBuiltinsAssembler::ValidateTypedArray(
Context, Object, constexpr string): JSTypedArray;
extern macro TypedArrayBuiltinsAssembler::GetTypedArrayElementsInfo(
JSTypedArray): TypedArrayElementsInfo;
extern macro LoadFixedTypedArrayElementAsTagged(
RawPtr, Smi, constexpr ElementsKind, constexpr ParameterMode): Object;
extern macro StoreFixedTypedArrayElementFromTagged(
......
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