Commit e121d235 authored by Dan Elphick's avatar Dan Elphick Committed by Commit Bot

[cleanup] Move TypedArray functions out of CodeStubAssembler

Move CodeStubAssembler::StoreJSTypedArrayElementFromTagged,
SetJSTypedArrayOnHeapDataPtr and SetJSTypedArrayOffHeapDataPtr into
TypedArrayBuiltinsAssembler.

Bug: v8:9396
Change-Id: I16e6aa82d0de9bd1d29a9e2c095032f2c6dd5e29
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1817611Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Commit-Queue: Dan Elphick <delphick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63930}
parent 95b8b10b
...@@ -2868,9 +2868,6 @@ extern macro IsPrototypeTypedArrayPrototype(implicit context: Context)(Map): ...@@ -2868,9 +2868,6 @@ extern macro IsPrototypeTypedArrayPrototype(implicit context: Context)(Map):
bool; bool;
extern operator '.data_ptr' macro LoadJSTypedArrayDataPtr(JSTypedArray): RawPtr; extern operator '.data_ptr' macro LoadJSTypedArrayDataPtr(JSTypedArray): RawPtr;
extern macro SetJSTypedArrayOnHeapDataPtr(
JSTypedArray, ByteArray, uintptr): void;
extern macro SetJSTypedArrayOffHeapDataPtr(JSTypedArray, RawPtr, uintptr): void;
extern operator '.elements_kind' macro LoadMapElementsKind(Map): ElementsKind; extern operator '.elements_kind' macro LoadMapElementsKind(Map): ElementsKind;
extern operator '.elements_kind' macro LoadElementsKind(JSTypedArray): extern operator '.elements_kind' macro LoadElementsKind(JSTypedArray):
......
...@@ -536,6 +536,76 @@ TNode<BoolT> TypedArrayBuiltinsAssembler::IsSharedArrayBuffer( ...@@ -536,6 +536,76 @@ TNode<BoolT> TypedArrayBuiltinsAssembler::IsSharedArrayBuffer(
return IsSetWord32<JSArrayBuffer::IsSharedBit>(bitfield); return IsSetWord32<JSArrayBuffer::IsSharedBit>(bitfield);
} }
void TypedArrayBuiltinsAssembler::SetJSTypedArrayOnHeapDataPtr(
TNode<JSTypedArray> holder, TNode<ByteArray> base, TNode<UintPtrT> offset) {
offset = UintPtrAdd(UintPtrConstant(ByteArray::kHeaderSize - kHeapObjectTag),
offset);
if (COMPRESS_POINTERS_BOOL) {
TNode<IntPtrT> full_base = Signed(BitcastTaggedToWord(base));
TNode<Int32T> compressed_base = TruncateIntPtrToInt32(full_base);
// TODO(v8:9706): Add a way to directly use kRootRegister value.
TNode<IntPtrT> isolate_root =
IntPtrSub(full_base, ChangeInt32ToIntPtr(compressed_base));
// Add JSTypedArray::ExternalPointerCompensationForOnHeapArray() to offset.
DCHECK_EQ(
isolate()->isolate_root(),
JSTypedArray::ExternalPointerCompensationForOnHeapArray(isolate()));
// See JSTypedArray::SetOnHeapDataPtr() for details.
offset = Unsigned(IntPtrAdd(offset, isolate_root));
}
StoreObjectField(holder, JSTypedArray::kBasePointerOffset, base);
StoreObjectFieldNoWriteBarrier<UintPtrT>(
holder, JSTypedArray::kExternalPointerOffset, offset);
}
void TypedArrayBuiltinsAssembler::SetJSTypedArrayOffHeapDataPtr(
TNode<JSTypedArray> holder, TNode<RawPtrT> base, TNode<UintPtrT> offset) {
StoreObjectFieldNoWriteBarrier(holder, JSTypedArray::kBasePointerOffset,
SmiConstant(0));
base = RawPtrAdd(base, Signed(offset));
StoreObjectFieldNoWriteBarrier<RawPtrT>(
holder, JSTypedArray::kExternalPointerOffset, base);
}
void TypedArrayBuiltinsAssembler::StoreJSTypedArrayElementFromTagged(
TNode<Context> context, TNode<JSTypedArray> typed_array,
TNode<Smi> index_node, TNode<Object> value, ElementsKind elements_kind) {
TNode<RawPtrT> data_ptr = LoadJSTypedArrayDataPtr(typed_array);
switch (elements_kind) {
case UINT8_ELEMENTS:
case UINT8_CLAMPED_ELEMENTS:
case INT8_ELEMENTS:
case UINT16_ELEMENTS:
case INT16_ELEMENTS:
StoreElement(data_ptr, elements_kind, index_node, SmiToInt32(CAST(value)),
SMI_PARAMETERS);
break;
case UINT32_ELEMENTS:
case INT32_ELEMENTS:
StoreElement(data_ptr, elements_kind, index_node,
TruncateTaggedToWord32(context, value), SMI_PARAMETERS);
break;
case FLOAT32_ELEMENTS:
StoreElement(data_ptr, elements_kind, index_node,
TruncateFloat64ToFloat32(LoadHeapNumberValue(CAST(value))),
SMI_PARAMETERS);
break;
case FLOAT64_ELEMENTS:
StoreElement(data_ptr, elements_kind, index_node,
LoadHeapNumberValue(CAST(value)), SMI_PARAMETERS);
break;
case BIGUINT64_ELEMENTS:
case BIGINT64_ELEMENTS:
StoreElement(data_ptr, elements_kind, index_node,
UncheckedCast<BigInt>(value), SMI_PARAMETERS);
break;
default:
UNREACHABLE();
}
}
// ES #sec-get-%typedarray%.prototype.set // ES #sec-get-%typedarray%.prototype.set
TF_BUILTIN(TypedArrayPrototypeSet, TypedArrayBuiltinsAssembler) { TF_BUILTIN(TypedArrayPrototypeSet, TypedArrayBuiltinsAssembler) {
const char* method_name = "%TypedArray%.prototype.set"; const char* method_name = "%TypedArray%.prototype.set";
......
...@@ -111,6 +111,18 @@ class TypedArrayBuiltinsAssembler : public CodeStubAssembler { ...@@ -111,6 +111,18 @@ class TypedArrayBuiltinsAssembler : public CodeStubAssembler {
TNode<Word32T> elements_kind, const TypedArraySwitchCase& case_function); TNode<Word32T> elements_kind, const TypedArraySwitchCase& case_function);
TNode<BoolT> IsSharedArrayBuffer(TNode<JSArrayBuffer> buffer); TNode<BoolT> IsSharedArrayBuffer(TNode<JSArrayBuffer> buffer);
void SetJSTypedArrayOnHeapDataPtr(TNode<JSTypedArray> holder,
TNode<ByteArray> base,
TNode<UintPtrT> offset);
void SetJSTypedArrayOffHeapDataPtr(TNode<JSTypedArray> holder,
TNode<RawPtrT> base,
TNode<UintPtrT> offset);
void StoreJSTypedArrayElementFromTagged(TNode<Context> context,
TNode<JSTypedArray> typed_array,
TNode<Smi> index_node,
TNode<Object> value,
ElementsKind elements_kind);
}; };
} // namespace internal } // namespace internal
......
...@@ -58,9 +58,10 @@ namespace typed_array_createtypedarray { ...@@ -58,9 +58,10 @@ namespace typed_array_createtypedarray {
typedArray.byte_length = byteLength; typedArray.byte_length = byteLength;
typedArray.length = length; typedArray.length = length;
if constexpr (isOnHeap) { if constexpr (isOnHeap) {
SetJSTypedArrayOnHeapDataPtr(typedArray, elements, byteOffset); typed_array::SetJSTypedArrayOnHeapDataPtr(
typedArray, elements, byteOffset);
} else { } else {
SetJSTypedArrayOffHeapDataPtr( typed_array::SetJSTypedArrayOffHeapDataPtr(
typedArray, buffer.backing_store, byteOffset); typedArray, buffer.backing_store, byteOffset);
assert( assert(
typedArray.data_ptr == typedArray.data_ptr ==
......
...@@ -71,12 +71,17 @@ namespace typed_array { ...@@ -71,12 +71,17 @@ namespace typed_array {
ElementsKind): bool; ElementsKind): bool;
extern macro LoadFixedTypedArrayElementAsTagged( extern macro LoadFixedTypedArrayElementAsTagged(
RawPtr, Smi, constexpr ElementsKind): Numeric; RawPtr, Smi, constexpr ElementsKind): Numeric;
extern macro StoreJSTypedArrayElementFromTagged( extern macro TypedArrayBuiltinsAssembler::StoreJSTypedArrayElementFromTagged(
Context, JSTypedArray, Smi, JSAny, constexpr ElementsKind); Context, JSTypedArray, Smi, JSAny, constexpr ElementsKind);
type LoadFn = builtin(Context, JSTypedArray, Smi) => JSAny; type LoadFn = builtin(Context, JSTypedArray, Smi) => JSAny;
type StoreFn = builtin(Context, JSTypedArray, Smi, JSAny) => JSAny; type StoreFn = builtin(Context, JSTypedArray, Smi, JSAny) => JSAny;
extern macro TypedArrayBuiltinsAssembler::SetJSTypedArrayOnHeapDataPtr(
JSTypedArray, ByteArray, uintptr): void;
extern macro TypedArrayBuiltinsAssembler::SetJSTypedArrayOffHeapDataPtr(
JSTypedArray, RawPtr, uintptr): void;
// AttachedJSTypedArray guards that the array's buffer is not detached. // AttachedJSTypedArray guards that the array's buffer is not detached.
transient type AttachedJSTypedArray extends JSTypedArray; transient type AttachedJSTypedArray extends JSTypedArray;
...@@ -198,7 +203,7 @@ namespace typed_array { ...@@ -198,7 +203,7 @@ namespace typed_array {
builtin StoreFixedElement<T: type>( builtin StoreFixedElement<T: type>(
context: Context, typedArray: JSTypedArray, index: Smi, context: Context, typedArray: JSTypedArray, index: Smi,
value: JSAny): JSAny { value: JSAny): JSAny {
StoreJSTypedArrayElementFromTagged( typed_array::StoreJSTypedArrayElementFromTagged(
context, typedArray, index, value, KindForArrayType<T>()); context, typedArray, index, value, KindForArrayType<T>());
return Undefined; return Undefined;
} }
......
...@@ -2265,40 +2265,6 @@ TNode<RawPtrT> CodeStubAssembler::LoadJSTypedArrayDataPtr( ...@@ -2265,40 +2265,6 @@ TNode<RawPtrT> CodeStubAssembler::LoadJSTypedArrayDataPtr(
return RawPtrAdd(external_pointer, base_pointer); return RawPtrAdd(external_pointer, base_pointer);
} }
void CodeStubAssembler::SetJSTypedArrayOffHeapDataPtr(
TNode<JSTypedArray> holder, TNode<RawPtrT> base, TNode<UintPtrT> offset) {
StoreObjectFieldNoWriteBarrier(holder, JSTypedArray::kBasePointerOffset,
SmiConstant(0));
base = RawPtrAdd(base, Signed(offset));
StoreObjectFieldNoWriteBarrier<RawPtrT>(
holder, JSTypedArray::kExternalPointerOffset, base);
}
void CodeStubAssembler::SetJSTypedArrayOnHeapDataPtr(TNode<JSTypedArray> holder,
TNode<ByteArray> base,
TNode<UintPtrT> offset) {
offset = UintPtrAdd(UintPtrConstant(ByteArray::kHeaderSize - kHeapObjectTag),
offset);
if (COMPRESS_POINTERS_BOOL) {
TNode<IntPtrT> full_base = Signed(BitcastTaggedToWord(base));
TNode<Int32T> compressed_base = TruncateIntPtrToInt32(full_base);
// TODO(v8:9706): Add a way to directly use kRootRegister value.
TNode<IntPtrT> isolate_root =
IntPtrSub(full_base, ChangeInt32ToIntPtr(compressed_base));
// Add JSTypedArray::ExternalPointerCompensationForOnHeapArray() to offset.
DCHECK_EQ(
isolate()->isolate_root(),
JSTypedArray::ExternalPointerCompensationForOnHeapArray(isolate()));
// See JSTypedArray::SetOnHeapDataPtr() for details.
offset = Unsigned(IntPtrAdd(offset, isolate_root));
}
StoreObjectField(holder, JSTypedArray::kBasePointerOffset, base);
StoreObjectFieldNoWriteBarrier<UintPtrT>(
holder, JSTypedArray::kExternalPointerOffset, offset);
}
TNode<BigInt> CodeStubAssembler::LoadFixedBigInt64ArrayElementAsTagged( TNode<BigInt> CodeStubAssembler::LoadFixedBigInt64ArrayElementAsTagged(
SloppyTNode<RawPtrT> data_pointer, SloppyTNode<IntPtrT> offset) { SloppyTNode<RawPtrT> data_pointer, SloppyTNode<IntPtrT> offset) {
if (Is64()) { if (Is64()) {
...@@ -2579,43 +2545,6 @@ TNode<Numeric> CodeStubAssembler::LoadFixedTypedArrayElementAsTagged( ...@@ -2579,43 +2545,6 @@ TNode<Numeric> CodeStubAssembler::LoadFixedTypedArrayElementAsTagged(
return var_result.value(); return var_result.value();
} }
void CodeStubAssembler::StoreJSTypedArrayElementFromTagged(
TNode<Context> context, TNode<JSTypedArray> typed_array,
TNode<Smi> index_node, TNode<Object> value, ElementsKind elements_kind) {
TNode<RawPtrT> data_ptr = LoadJSTypedArrayDataPtr(typed_array);
switch (elements_kind) {
case UINT8_ELEMENTS:
case UINT8_CLAMPED_ELEMENTS:
case INT8_ELEMENTS:
case UINT16_ELEMENTS:
case INT16_ELEMENTS:
StoreElement(data_ptr, elements_kind, index_node, SmiToInt32(CAST(value)),
SMI_PARAMETERS);
break;
case UINT32_ELEMENTS:
case INT32_ELEMENTS:
StoreElement(data_ptr, elements_kind, index_node,
TruncateTaggedToWord32(context, value), SMI_PARAMETERS);
break;
case FLOAT32_ELEMENTS:
StoreElement(data_ptr, elements_kind, index_node,
TruncateFloat64ToFloat32(LoadHeapNumberValue(CAST(value))),
SMI_PARAMETERS);
break;
case FLOAT64_ELEMENTS:
StoreElement(data_ptr, elements_kind, index_node,
LoadHeapNumberValue(CAST(value)), SMI_PARAMETERS);
break;
case BIGUINT64_ELEMENTS:
case BIGINT64_ELEMENTS:
StoreElement(data_ptr, elements_kind, index_node,
UncheckedCast<BigInt>(value), SMI_PARAMETERS);
break;
default:
UNREACHABLE();
}
}
template <typename TIndex> template <typename TIndex>
TNode<MaybeObject> CodeStubAssembler::LoadFeedbackVectorSlot( TNode<MaybeObject> CodeStubAssembler::LoadFeedbackVectorSlot(
TNode<FeedbackVector> feedback_vector, TNode<TIndex> slot, TNode<FeedbackVector> feedback_vector, TNode<TIndex> slot,
......
...@@ -1429,12 +1429,6 @@ class V8_EXPORT_PRIVATE CodeStubAssembler ...@@ -1429,12 +1429,6 @@ class V8_EXPORT_PRIVATE CodeStubAssembler
TNode<BigInt> BigIntFromInt32Pair(TNode<IntPtrT> low, TNode<IntPtrT> high); TNode<BigInt> BigIntFromInt32Pair(TNode<IntPtrT> low, TNode<IntPtrT> high);
TNode<BigInt> BigIntFromUint32Pair(TNode<UintPtrT> low, TNode<UintPtrT> high); TNode<BigInt> BigIntFromUint32Pair(TNode<UintPtrT> low, TNode<UintPtrT> high);
void StoreJSTypedArrayElementFromTagged(TNode<Context> context,
TNode<JSTypedArray> typed_array,
TNode<Smi> index_node,
TNode<Object> value,
ElementsKind elements_kind);
// Context manipulation // Context manipulation
TNode<Object> LoadContextElement(SloppyTNode<Context> context, TNode<Object> LoadContextElement(SloppyTNode<Context> context,
int slot_index); int slot_index);
...@@ -3537,12 +3531,6 @@ class V8_EXPORT_PRIVATE CodeStubAssembler ...@@ -3537,12 +3531,6 @@ class V8_EXPORT_PRIVATE CodeStubAssembler
// JSTypedArray helpers // JSTypedArray helpers
TNode<UintPtrT> LoadJSTypedArrayLength(TNode<JSTypedArray> typed_array); TNode<UintPtrT> LoadJSTypedArrayLength(TNode<JSTypedArray> typed_array);
TNode<RawPtrT> LoadJSTypedArrayDataPtr(TNode<JSTypedArray> typed_array); TNode<RawPtrT> LoadJSTypedArrayDataPtr(TNode<JSTypedArray> typed_array);
void SetJSTypedArrayOnHeapDataPtr(TNode<JSTypedArray> holder,
TNode<ByteArray> base,
TNode<UintPtrT> offset);
void SetJSTypedArrayOffHeapDataPtr(TNode<JSTypedArray> holder,
TNode<RawPtrT> base,
TNode<UintPtrT> offset);
template <typename TIndex> template <typename TIndex>
TNode<IntPtrT> ElementOffsetFromIndex(TNode<TIndex> index, ElementsKind kind, TNode<IntPtrT> ElementOffsetFromIndex(TNode<TIndex> index, ElementsKind kind,
......
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