Commit a6c71508 authored by Simon Zünd's avatar Simon Zünd Committed by Commit Bot

[typedarray] Change TypedArray.p.sort implementation.

This CL uses the new function pointers and generic features of Torque
to improve the performance of TypedArray.p.sort.

Instead of one Load/Store builtin that dispatches at runtime based on
the element kind, there are now many small builtins (one for each
element kind). The sorting algorithm then uses function pointers to
those small builtins, which get set once.

Changes in the relevant benchmarks:

Benchmark   Original (JS)   Current   This CL
IntTypes             83.9     202.3     240.7
BigIntTypes          32.1      47.2      53.3
FloatTypes           99.3     109.3     129.3

Bug: v8:7382
Change-Id: I8684410524d546615b19f6edcbfdc615068196aa
Reviewed-on: https://chromium-review.googlesource.com/1070069
Commit-Queue: Simon Zünd <szuend@google.com>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53322}
parent 94313abc
...@@ -33,6 +33,10 @@ type FixedArrayBase extends HeapObject generates 'TNode<FixedArrayBase>'; ...@@ -33,6 +33,10 @@ type FixedArrayBase extends HeapObject generates 'TNode<FixedArrayBase>';
type FixedArray extends FixedArrayBase generates 'TNode<FixedArray>'; type FixedArray extends FixedArrayBase generates 'TNode<FixedArray>';
type FixedDoubleArray extends FixedArrayBase generates type FixedDoubleArray extends FixedArrayBase generates
'TNode<FixedDoubleArray>'; 'TNode<FixedDoubleArray>';
type FixedTypedArrayBase extends FixedArrayBase generates
'TNode<FixedTypedArrayBase>';
type FixedTypedArray extends FixedTypedArrayBase generates
'TNode<FixedTypedArray>';
type JSArrayBuffer extends Object generates 'TNode<JSArrayBuffer>'; type JSArrayBuffer extends Object generates 'TNode<JSArrayBuffer>';
type JSArrayBufferView extends Object generates 'TNode<JSArrayBufferView>'; type JSArrayBufferView extends Object generates 'TNode<JSArrayBufferView>';
...@@ -47,6 +51,8 @@ type ExtractFixedArrayFlags generates ...@@ -47,6 +51,8 @@ type ExtractFixedArrayFlags generates
type MessageTemplate; type MessageTemplate;
type HasPropertyFlag generates 'HasPropertyLookupMode'; type HasPropertyFlag generates 'HasPropertyLookupMode';
const NO_ELEMENTS: constexpr ElementsKind = 'NO_ELEMENTS';
const PACKED_SMI_ELEMENTS: constexpr ElementsKind = 'PACKED_SMI_ELEMENTS'; const PACKED_SMI_ELEMENTS: constexpr ElementsKind = 'PACKED_SMI_ELEMENTS';
const HOLEY_SMI_ELEMENTS: constexpr ElementsKind = 'HOLEY_SMI_ELEMENTS'; const HOLEY_SMI_ELEMENTS: constexpr ElementsKind = 'HOLEY_SMI_ELEMENTS';
const PACKED_ELEMENTS: constexpr ElementsKind = 'PACKED_ELEMENTS'; const PACKED_ELEMENTS: constexpr ElementsKind = 'PACKED_ELEMENTS';
...@@ -66,6 +72,18 @@ const UINT8_CLAMPED_ELEMENTS: constexpr ElementsKind = 'UINT8_CLAMPED_ELEMENTS'; ...@@ -66,6 +72,18 @@ const UINT8_CLAMPED_ELEMENTS: constexpr ElementsKind = 'UINT8_CLAMPED_ELEMENTS';
const BIGUINT64_ELEMENTS: constexpr ElementsKind = 'BIGUINT64_ELEMENTS'; const BIGUINT64_ELEMENTS: constexpr ElementsKind = 'BIGUINT64_ELEMENTS';
const BIGINT64_ELEMENTS: constexpr ElementsKind = 'BIGINT64_ELEMENTS'; const BIGINT64_ELEMENTS: constexpr ElementsKind = 'BIGINT64_ELEMENTS';
type FixedUint8Array extends FixedTypedArray;
type FixedInt8Array extends FixedTypedArray;
type FixedUint16Array extends FixedTypedArray;
type FixedInt16Array extends FixedTypedArray;
type FixedUint32Array extends FixedTypedArray;
type FixedInt32Array extends FixedTypedArray;
type FixedFloat32Array extends FixedTypedArray;
type FixedFloat64Array extends FixedTypedArray;
type FixedUint8ClampedArray extends FixedTypedArray;
type FixedBigUint64Array extends FixedTypedArray;
type FixedBigInt64Array extends FixedTypedArray;
const kAllFixedArrays: constexpr ExtractFixedArrayFlags = const kAllFixedArrays: constexpr ExtractFixedArrayFlags =
'ExtractFixedArrayFlag::kAllFixedArrays'; 'ExtractFixedArrayFlag::kAllFixedArrays';
...@@ -223,7 +241,8 @@ extern implicit operator ...@@ -223,7 +241,8 @@ extern implicit operator
extern implicit operator 'convert<>' macro BoolConstant(constexpr bool): bool; extern implicit operator 'convert<>' macro BoolConstant(constexpr bool): bool;
extern implicit operator 'convert<>' macro LanguageModeConstant( extern implicit operator 'convert<>' macro LanguageModeConstant(
constexpr LanguageMode): LanguageMode; constexpr LanguageMode): LanguageMode;
extern operator
'convert<>' macro Int32Constant(constexpr ElementsKind): ElementsKind;
extern implicit operator 'convert<>' macro SmiFromInt32(ElementsKind): Smi; extern implicit operator 'convert<>' macro SmiFromInt32(ElementsKind): Smi;
extern operator 'convert<>' macro ChangeInt32ToTagged(int32): Number; extern operator 'convert<>' macro ChangeInt32ToTagged(int32): Number;
......
...@@ -1147,8 +1147,6 @@ namespace internal { ...@@ -1147,8 +1147,6 @@ namespace internal {
TFJ(TypedArrayOf, SharedFunctionInfo::kDontAdaptArgumentsSentinel) \ TFJ(TypedArrayOf, SharedFunctionInfo::kDontAdaptArgumentsSentinel) \
/* ES6 %TypedArray%.from */ \ /* ES6 %TypedArray%.from */ \
TFJ(TypedArrayFrom, SharedFunctionInfo::kDontAdaptArgumentsSentinel) \ TFJ(TypedArrayFrom, SharedFunctionInfo::kDontAdaptArgumentsSentinel) \
TFS(TypedArrayLoadElementAsTagged, kArray, kKind, kIndex) \
TFS(TypedArrayStoreElementFromTagged, kArray, kKind, kIndex, kValue) \
\ \
/* Wasm */ \ /* Wasm */ \
ASM(WasmCompileLazy) \ ASM(WasmCompileLazy) \
......
...@@ -873,42 +873,6 @@ TNode<IntPtrT> TypedArrayBuiltinsAssembler::GetTypedArrayElementSize( ...@@ -873,42 +873,6 @@ TNode<IntPtrT> TypedArrayBuiltinsAssembler::GetTypedArrayElementSize(
return element_size.value(); return element_size.value();
} }
TF_BUILTIN(TypedArrayLoadElementAsTagged, TypedArrayBuiltinsAssembler) {
TVARIABLE(Object, result);
TNode<JSTypedArray> array = CAST(Parameter(Descriptor::kArray));
TNode<Smi> kind = CAST(Parameter(Descriptor::kKind));
TNode<Smi> index_node = CAST(Parameter(Descriptor::kIndex));
TNode<RawPtrT> data_pointer = UncheckedCast<RawPtrT>(LoadDataPtr(array));
TNode<Int32T> elements_kind = SmiToInt32(kind);
DispatchTypedArrayByElementsKind(
elements_kind, [&](ElementsKind el_kind, int, int) {
result = CAST(LoadFixedTypedArrayElementAsTagged(
data_pointer, index_node, el_kind, SMI_PARAMETERS));
});
Return(result.value());
}
TF_BUILTIN(TypedArrayStoreElementFromTagged, TypedArrayBuiltinsAssembler) {
TNode<Context> context = CAST(Parameter(Descriptor::kContext));
TNode<JSTypedArray> array = CAST(Parameter(Descriptor::kArray));
TNode<Smi> kind = CAST(Parameter(Descriptor::kKind));
TNode<Smi> index_node = CAST(Parameter(Descriptor::kIndex));
TNode<Object> value = CAST(Parameter(Descriptor::kValue));
TNode<FixedTypedArrayBase> elements = CAST(LoadElements(array));
TNode<Int32T> elements_kind = SmiToInt32(kind);
DispatchTypedArrayByElementsKind(
elements_kind, [&](ElementsKind el_kind, int, int) {
StoreFixedTypedArrayElementFromTagged(context, elements, index_node,
value, el_kind, SMI_PARAMETERS);
});
Return(UndefinedConstant());
}
TNode<Object> TypedArrayBuiltinsAssembler::GetDefaultConstructor( TNode<Object> TypedArrayBuiltinsAssembler::GetDefaultConstructor(
TNode<Context> context, TNode<JSTypedArray> exemplar) { TNode<Context> context, TNode<JSTypedArray> exemplar) {
TVARIABLE(IntPtrT, context_slot); TVARIABLE(IntPtrT, context_slot);
......
...@@ -141,6 +141,12 @@ class TypedArrayBuiltinsAssembler : public CodeStubAssembler { ...@@ -141,6 +141,12 @@ class TypedArrayBuiltinsAssembler : public CodeStubAssembler {
// Returns true iff number is NaN. // Returns true iff number is NaN.
// TOOD(szuend): Remove when UncheckedCasts are supported in Torque. // TOOD(szuend): Remove when UncheckedCasts are supported in Torque.
TNode<BoolT> NumberIsNaN(TNode<Number> number); TNode<BoolT> NumberIsNaN(TNode<Number> number);
// TODO(szuend): Remove when UncheckedCasts are supported in Torque.
TNode<FixedTypedArrayBase> UncheckedCastFixedArrayBaseToFixedTypedArrayBase(
TNode<FixedArrayBase> array) {
return CAST(array);
}
}; };
} // namespace internal } // namespace internal
......
This diff is collapsed.
...@@ -97,6 +97,7 @@ let constructorsWithArrays = [ ...@@ -97,6 +97,7 @@ let constructorsWithArrays = [
ctor: Float64Array, ctor: Float64Array,
array: [2 ** 53, 2 ** 53 - 1, 1, 0, -1, -(2 ** 53 - 1), -(2 ** 53)] array: [2 ** 53, 2 ** 53 - 1, 1, 0, -1, -(2 ** 53 - 1), -(2 ** 53)]
}, },
{ctor: Uint8ClampedArray, array: [255, 254, 4, 3, 2, 1, 0]},
{ {
ctor: BigUint64Array, ctor: BigUint64Array,
array: [2n ** 64n - 1n, 2n ** 64n - 2n, 4n, 3n, 2n, 1n, 0n] array: [2n ** 64n - 1n, 2n ** 64n - 2n, 4n, 3n, 2n, 1n, 0n]
......
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