From 8c50fd5fdcf7e14fc5ab3acf1191e12afa4116ab Mon Sep 17 00:00:00 2001 From: Keith Winstein Date: Mon, 15 Aug 2022 14:39:34 -0700 Subject: Support multi-memory in all memory ops and in apply/resolve-names (#1962) --- src/interp/binary-reader-interp.cc | 63 ++++++++++++++++++++++++++------------ 1 file changed, 44 insertions(+), 19 deletions(-) (limited to 'src/interp/binary-reader-interp.cc') diff --git a/src/interp/binary-reader-interp.cc b/src/interp/binary-reader-interp.cc index 5429a88a..e1696ce2 100644 --- a/src/interp/binary-reader-interp.cc +++ b/src/interp/binary-reader-interp.cc @@ -150,22 +150,28 @@ class BinaryReaderInterp : public BinaryReaderNop { Result OnOpcode(Opcode Opcode) override; Result OnAtomicLoadExpr(Opcode opcode, + Index memidx, Address alignment_log2, Address offset) override; Result OnAtomicStoreExpr(Opcode opcode, + Index memidx, Address alignment_log2, Address offset) override; Result OnAtomicRmwExpr(Opcode opcode, + Index memidx, Address alignment_log2, Address offset) override; Result OnAtomicRmwCmpxchgExpr(Opcode opcode, + Index memidx, Address alignment_log2, Address offset) override; Result OnAtomicWaitExpr(Opcode opcode, + Index memidx, Address alignment_log2, Address offset) override; Result OnAtomicFenceExpr(uint32_t consistency_model) override; Result OnAtomicNotifyExpr(Opcode opcode, + Index memidx, Address alignment_log2, Address offset) override; Result OnBinaryExpr(Opcode opcode) override; @@ -247,9 +253,11 @@ class BinaryReaderInterp : public BinaryReaderNop { uint64_t value) override; Result OnSimdShuffleOpExpr(Opcode opcode, v128 value) override; Result OnLoadSplatExpr(Opcode opcode, + Index memidx, Address alignment_log2, Address offset) override; Result OnLoadZeroExpr(Opcode opcode, + Index memidx, Address alignment_log2, Address offset) override; @@ -333,7 +341,6 @@ class BinaryReaderInterp : public BinaryReaderNop { std::vector global_types_; // Includes imported and defined. std::vector tag_types_; // Includes imported and defined. - static const Index kMemoryIndex0 = 0; std::string_view filename_; }; @@ -902,6 +909,7 @@ Result BinaryReaderInterp::OnSimdLoadLaneExpr(Opcode opcode, Address offset, uint64_t value) { CHECK_RESULT(validator_.OnSimdLoadLane(GetLocation(), opcode, + Var(memidx, GetLocation()), GetAlignment(alignment_log2), value)); istream_.Emit(opcode, memidx, offset, static_cast(value)); return Result::Ok; @@ -913,6 +921,7 @@ Result BinaryReaderInterp::OnSimdStoreLaneExpr(Opcode opcode, Address offset, uint64_t value) { CHECK_RESULT(validator_.OnSimdStoreLane(GetLocation(), opcode, + Var(memidx, GetLocation()), GetAlignment(alignment_log2), value)); istream_.Emit(opcode, memidx, offset, static_cast(value)); return Result::Ok; @@ -925,56 +934,68 @@ Result BinaryReaderInterp::OnSimdShuffleOpExpr(Opcode opcode, v128 value) { } Result BinaryReaderInterp::OnLoadSplatExpr(Opcode opcode, + Index memidx, Address align_log2, Address offset) { - CHECK_RESULT( - validator_.OnLoadSplat(GetLocation(), opcode, GetAlignment(align_log2))); - istream_.Emit(opcode, kMemoryIndex0, offset); + CHECK_RESULT(validator_.OnLoadSplat(GetLocation(), opcode, + Var(memidx, GetLocation()), + GetAlignment(align_log2))); + istream_.Emit(opcode, memidx, offset); return Result::Ok; } Result BinaryReaderInterp::OnLoadZeroExpr(Opcode opcode, + Index memidx, Address align_log2, Address offset) { - CHECK_RESULT( - validator_.OnLoadZero(GetLocation(), opcode, GetAlignment(align_log2))); - istream_.Emit(opcode, kMemoryIndex0, offset); + CHECK_RESULT(validator_.OnLoadZero(GetLocation(), opcode, + Var(memidx, GetLocation()), + GetAlignment(align_log2))); + istream_.Emit(opcode, memidx, offset); return Result::Ok; } Result BinaryReaderInterp::OnAtomicLoadExpr(Opcode opcode, + Index memidx, Address align_log2, Address offset) { - CHECK_RESULT( - validator_.OnAtomicLoad(GetLocation(), opcode, GetAlignment(align_log2))); - istream_.Emit(opcode, kMemoryIndex0, offset); + CHECK_RESULT(validator_.OnAtomicLoad(GetLocation(), opcode, + Var(memidx, GetLocation()), + GetAlignment(align_log2))); + istream_.Emit(opcode, memidx, offset); return Result::Ok; } Result BinaryReaderInterp::OnAtomicStoreExpr(Opcode opcode, + Index memidx, Address align_log2, Address offset) { CHECK_RESULT(validator_.OnAtomicStore(GetLocation(), opcode, + Var(memidx, GetLocation()), GetAlignment(align_log2))); - istream_.Emit(opcode, kMemoryIndex0, offset); + istream_.Emit(opcode, memidx, offset); return Result::Ok; } Result BinaryReaderInterp::OnAtomicRmwExpr(Opcode opcode, + Index memidx, Address align_log2, Address offset) { - CHECK_RESULT( - validator_.OnAtomicRmw(GetLocation(), opcode, GetAlignment(align_log2))); - istream_.Emit(opcode, kMemoryIndex0, offset); + CHECK_RESULT(validator_.OnAtomicRmw(GetLocation(), opcode, + Var(memidx, GetLocation()), + GetAlignment(align_log2))); + istream_.Emit(opcode, memidx, offset); return Result::Ok; } Result BinaryReaderInterp::OnAtomicRmwCmpxchgExpr(Opcode opcode, + Index memidx, Address align_log2, Address offset) { CHECK_RESULT(validator_.OnAtomicRmwCmpxchg(GetLocation(), opcode, + Var(memidx, GetLocation()), GetAlignment(align_log2))); - istream_.Emit(opcode, kMemoryIndex0, offset); + istream_.Emit(opcode, memidx, offset); return Result::Ok; } @@ -1368,11 +1389,13 @@ Result BinaryReaderInterp::OnUnreachableExpr() { } Result BinaryReaderInterp::OnAtomicWaitExpr(Opcode opcode, + Index memidx, Address align_log2, Address offset) { - CHECK_RESULT( - validator_.OnAtomicWait(GetLocation(), opcode, GetAlignment(align_log2))); - istream_.Emit(opcode, kMemoryIndex0, offset); + CHECK_RESULT(validator_.OnAtomicWait(GetLocation(), opcode, + Var(memidx, GetLocation()), + GetAlignment(align_log2))); + istream_.Emit(opcode, memidx, offset); return Result::Ok; } @@ -1383,11 +1406,13 @@ Result BinaryReaderInterp::OnAtomicFenceExpr(uint32_t consistency_model) { } Result BinaryReaderInterp::OnAtomicNotifyExpr(Opcode opcode, + Index memidx, Address align_log2, Address offset) { CHECK_RESULT(validator_.OnAtomicNotify(GetLocation(), opcode, + Var(memidx, GetLocation()), GetAlignment(align_log2))); - istream_.Emit(opcode, kMemoryIndex0, offset); + istream_.Emit(opcode, memidx, offset); return Result::Ok; } -- cgit v1.2.3