Commit e7be15c7 authored by Jakob Kummerow's avatar Jakob Kummerow Committed by Commit Bot

[wasm-gc][builtins] Migrate WasmAllocateArrayWithRtt to Torque

This is useful in particular as preparation for calling
this builtin from Liftoff code (where we don't have access
to a Context).

Bug: v8:7748
Change-Id: Ie1a10a0487a99a1e6b75693da1554d7af28e7924
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2593256Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
Auto-Submit: Jakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#71792}
parent 33fb2319
......@@ -428,6 +428,9 @@ const kNameDictionaryInitialCapacity:
const kOrderedNameDictionaryInitialCapacity:
constexpr int32 generates 'OrderedNameDictionary::kInitialCapacity';
const kWasmArrayHeaderSize:
constexpr int32 generates 'WasmArray::kHeaderSize';
const kDictModePrototypes:
constexpr bool generates 'V8_DICT_MODE_PROTOTYPES_BOOL';
......
......@@ -814,7 +814,6 @@ namespace internal {
ASM(WasmDebugBreak, Dummy) \
TFC(WasmFloat32ToNumber, WasmFloat32ToNumber) \
TFC(WasmFloat64ToNumber, WasmFloat64ToNumber) \
TFS(WasmAllocateArrayWithRtt, kMap, kLength, kElementSize) \
TFC(WasmI32AtomicWait32, WasmI32AtomicWait32) \
TFC(WasmI64AtomicWait32, WasmI64AtomicWait32) \
TFS(WasmAllocatePair, kValue1, kValue2) \
......
......@@ -107,27 +107,6 @@ TF_BUILTIN(WasmI64AtomicWait32, WasmBuiltinsAssembler) {
Return(Unsigned(SmiToInt32(result_smi)));
}
TF_BUILTIN(WasmAllocateArrayWithRtt, WasmBuiltinsAssembler) {
auto map = Parameter<Map>(Descriptor::kMap);
auto length = Parameter<Smi>(Descriptor::kLength);
auto element_size = Parameter<Smi>(Descriptor::kElementSize);
TNode<IntPtrT> untagged_length = SmiUntag(length);
// instance_size = WasmArray::kHeaderSize
// + RoundUp(element_size * length, kObjectAlignment)
TNode<IntPtrT> raw_size = IntPtrMul(SmiUntag(element_size), untagged_length);
TNode<IntPtrT> rounded_size =
WordAnd(IntPtrAdd(raw_size, IntPtrConstant(kObjectAlignmentMask)),
IntPtrConstant(~kObjectAlignmentMask));
TNode<IntPtrT> instance_size =
IntPtrAdd(IntPtrConstant(WasmArray::kHeaderSize), rounded_size);
TNode<WasmArray> result = UncheckedCast<WasmArray>(
Allocate(instance_size, kAllowLargeObjectAllocation));
StoreMap(result, map);
StoreObjectFieldNoWriteBarrier(result, WasmArray::kLengthOffset,
TruncateIntPtrToInt32(untagged_length));
Return(result);
}
TF_BUILTIN(WasmAllocatePair, WasmBuiltinsAssembler) {
TNode<WasmInstanceObject> instance = LoadInstanceFromFrame();
TNode<HeapObject> value1 = Parameter<HeapObject>(Descriptor::kValue1);
......
......@@ -35,7 +35,7 @@ extern runtime WasmAllocateRtt(Context, Smi, Map): Map;
namespace unsafe {
extern macro TimesTaggedSize(intptr): intptr;
extern macro Allocate(intptr): HeapObject;
extern macro Allocate(intptr, constexpr AllocationFlag): HeapObject;
}
namespace wasm {
......@@ -239,11 +239,27 @@ builtin WasmAllocateRtt(implicit context: Context)(
builtin WasmAllocateStructWithRtt(rtt: Map): HeapObject {
const instanceSize: intptr =
unsafe::TimesTaggedSize(Convert<intptr>(rtt.instance_size_in_words));
const result: HeapObject = unsafe::Allocate(instanceSize);
const result: HeapObject = unsafe::Allocate(
instanceSize, AllocationFlag::kAllowLargeObjectAllocation);
*UnsafeConstCast(&result.map) = rtt;
return result;
}
builtin WasmAllocateArrayWithRtt(
rtt: Map, length: uint32, elementSize: uint32): HeapObject {
// instanceSize = RoundUp(elementSize * length, kObjectAlignment)
// + WasmArray::kHeaderSize
const instanceSize: intptr =
torque_internal::AlignTagged(
Convert<intptr>(length) * Convert<intptr>(elementSize)) +
Convert<intptr>(kWasmArrayHeaderSize);
const result: HeapObject = unsafe::Allocate(
instanceSize, AllocationFlag::kAllowLargeObjectAllocation);
*UnsafeConstCast(&result.map) = rtt;
%RawDownCast<WasmArray>(result).length = length;
return result;
}
// Redeclaration with different typing (value is an Object, not JSAny).
extern transitioning runtime
CreateDataProperty(implicit context: Context)(JSReceiver, JSAny, Object);
......
......@@ -5642,11 +5642,9 @@ Node* WasmGraphBuilder::ArrayNewWithRtt(uint32_t array_index,
length, gasm_->Uint32Constant(wasm::kV8MaxWasmArrayLength)),
position);
wasm::ValueType element_type = type->element_type();
Node* a = CALL_BUILTIN(
WasmAllocateArrayWithRtt, rtt, BuildChangeUint31ToSmi(length),
graph()->NewNode(mcgraph()->common()->NumberConstant(
element_type.element_size_bytes())),
LOAD_INSTANCE_FIELD(NativeContext, MachineType::TaggedPointer()));
Node* a = CALL_BUILTIN(WasmAllocateArrayWithRtt, rtt, length,
graph()->NewNode(mcgraph()->common()->Int32Constant(
element_type.element_size_bytes())));
auto loop = gasm_->MakeLoopLabel(MachineRepresentation::kWord32);
auto done = gasm_->MakeLabel();
Node* start_offset = gasm_->Int32Constant(
......
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