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

[typedarray] Change Torque sort implementation

This CL changes how TypedArray.p.sort is implemented in Torque, mainly
to address the binary memory size of the builtin.

With this CL the memory comes down from 53611 to 4215 (as reported
by --print-builtin-size on a x64.release build).
With the following performance impact
on the relevant benchmarks:

Benchmark  Original (JS)   Torque (initial)    This CL

IntTypes            83.9              263.7      202.3
BigIntTypes         32.1               54.6       47.2
FloatTypes          99.3              138.7      109.3

This is achieved by pushing the Load/Store dispatch based on
the elements kind into separate builtins that are executed
for each load/store. This results in only one version of the
sorting algorithm instead of one version per elements kind.

R=jgruber@chromium.org

Bug: chromium:837282
Change-Id: I7fe2da3cbfd01531d070128126a0d56d3dd6bdcc
Reviewed-on: https://chromium-review.googlesource.com/1033744
Commit-Queue: Simon Zünd <szuend@google.com>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#52937}
parent 28279bd8
......@@ -219,6 +219,7 @@ extern implicit operator 'convert<>' macro NumberConstant(const_int32): Number;
extern operator 'convert<>' macro ChangeInt32ToTagged(int32): Number;
extern operator 'convert<>' macro TruncateWordToWord32(intptr): int32;
extern operator 'convert<>' macro SmiTag(intptr): Smi;
extern operator 'convert<>' macro SmiFromInt32(int32): Smi;
extern operator 'convert<>' macro SmiUntag(Smi): intptr;
......@@ -290,10 +291,3 @@ macro HasPropertyObject(
extern macro IsCallable(HeapObject): bit;
extern macro TaggedIsCallable(Object): bit;
extern macro IsDetachedBuffer(JSArrayBuffer): bit;
type ParameterMode;
const kSmiParameters: ParameterMode = 'ParameterMode::SMI_PARAMETERS';
extern macro LoadFixedTypedArrayElementAsTagged(
RawPtr, Smi, ElementsKind, ParameterMode): Object;
extern macro StoreFixedTypedArrayElementFromTagged(
Context, RawPtr, Smi, Object, ElementsKind, ParameterMode);
......@@ -1175,6 +1175,8 @@ namespace internal {
TFJ(TypedArrayOf, SharedFunctionInfo::kDontAdaptArgumentsSentinel) \
/* ES6 %TypedArray%.from */ \
TFJ(TypedArrayFrom, SharedFunctionInfo::kDontAdaptArgumentsSentinel) \
TFS(TypedArrayLoadElementAsTagged, kArray, kKind, kIndex) \
TFS(TypedArrayStoreElementFromTagged, kArray, kKind, kIndex, kValue) \
\
/* Wasm */ \
ASM(WasmCompileLazy) \
......
......@@ -858,6 +858,42 @@ TNode<IntPtrT> TypedArrayBuiltinsAssembler::GetTypedArrayElementSize(
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<RawPtrT> data_pointer = UncheckedCast<RawPtrT>(LoadDataPtr(array));
TNode<Int32T> elements_kind = SmiToInt32(kind);
DispatchTypedArrayByElementsKind(
elements_kind, [&](ElementsKind el_kind, int, int) {
StoreFixedTypedArrayElementFromTagged(context, data_pointer, index_node,
value, el_kind, SMI_PARAMETERS);
});
Return(UndefinedConstant());
}
TNode<Object> TypedArrayBuiltinsAssembler::GetDefaultConstructor(
TNode<Context> context, TNode<JSTypedArray> exemplar) {
TVARIABLE(IntPtrT, context_slot);
......
This diff is collapsed.
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