Skip to content
Permalink
Browse files
[WASM-References] Add support for memory.copy, memory.init and data.drop
https://bugs.webkit.org/show_bug.cgi?id=219943

Patch by Dmitry Bezhetskov <dbezhetskov@igalia.com> on 2020-12-17
Reviewed by Yusuke Suzuki.

JSTests:

Added ref-types spec tests for memory.copy, memory.init and data.drop:
https://github.com/WebAssembly/reference-types/tree/master/test/core.
Renamed table_instructions_parse_unreachable test into just
parse_unreachable to prevent confusion.

* wasm.yaml:
* wasm/references-spec-tests/memory_copy.wast.js: Added.
* wasm/references-spec-tests/memory_init.wast.js: Added.
* wasm/references/memory_copy.js: Added.
(async test):
* wasm/references/memory_copy_shared.js: Added.
(async test):
* wasm/references/parse_unreachable.js: Renamed from JSTests/wasm/references/table_instructions_parse_unreachable.js.
(invalidMemoryCopyUnreachable):
(invalidMemoryInitUnreachable):
(invalidDataDropUnreachable):
* wasm/wasm.json:

Source/JavaScriptCore:

Add support for memory.copy [dstAddress, srcAddress, length] -> []
that copies one  memory segment to another memory segment.
The memory.copy calls C memcpy function to utilize all possible optimization for copy.
This instruction speedup copying data segments in wasm because without it we need to use a lot
load/store instructions with loops in wasm.

Add support for memory.init data_segment_index [dstAddress, srcAddress, length] -> []
that copies data from a passive data segment into a memory segment.
This instruction is the same as memory.copy but for read-only data segments.
It also utilize C memcpy under the hood.

Add support for data.drop data_segment_index [] -> []
that resize given data segment to zero.
Data.drop makes redundant data segment and prevents usage of it in the next.
BTW, it is just a hint for the host runtime so we don't have to change data segment.

Add support for Data count section.
This section just stores the number of data segments.
We need this to validate memory.init instruction's data index because
Code section comes before Data section.

These instructions are needed to support reference types proposal and bulk proposal.

* bytecode/BytecodeList.rb:
* llint/WebAssembly.asm:
* wasm/WasmAirIRGenerator.cpp:
(JSC::Wasm::AirIRGenerator::addMemoryCopy):
(JSC::Wasm::AirIRGenerator::addMemoryInit):
(JSC::Wasm::AirIRGenerator::addDataDrop):
* wasm/WasmB3IRGenerator.cpp:
(JSC::Wasm::B3IRGenerator::addMemoryInit):
(JSC::Wasm::B3IRGenerator::addMemoryCopy):
(JSC::Wasm::B3IRGenerator::addDataDrop):
* wasm/WasmFormat.cpp:
(JSC::Wasm::Segment::create):
* wasm/WasmFormat.h:
(JSC::Wasm::Segment::isActive const):
(JSC::Wasm::Segment::isPassive const):
* wasm/WasmFunctionParser.h:
(JSC::Wasm::FunctionParser<Context>::parseDataSegmentIndex):
(JSC::Wasm::FunctionParser<Context>::parseMemoryCopyImmediates):
(JSC::Wasm::FunctionParser<Context>::parseMemoryInitImmediates):
(JSC::Wasm::FunctionParser<Context>::parseExpression):
(JSC::Wasm::FunctionParser<Context>::parseUnreachableExpression):
* wasm/WasmInstance.cpp:
(JSC::Wasm::Instance::Instance):
(JSC::Wasm::Instance::memoryInit):
(JSC::Wasm::Instance::dataDrop):
* wasm/WasmInstance.h:
* wasm/WasmLLIntGenerator.cpp:
(JSC::Wasm::LLIntGenerator::addMemoryInit):
(JSC::Wasm::LLIntGenerator::addDataDrop):
(JSC::Wasm::LLIntGenerator::addMemoryCopy):
* wasm/WasmMemory.cpp:
(JSC::Wasm::Memory::copy):
(JSC::Wasm::Memory::init):
* wasm/WasmMemory.h:
* wasm/WasmModuleInformation.h:
(JSC::Wasm::ModuleInformation::dataSegmentsCount const):
* wasm/WasmOperations.cpp:
(JSC::Wasm::JSC_DEFINE_JIT_OPERATION):
* wasm/WasmOperations.h:
* wasm/WasmSectionParser.cpp:
(JSC::Wasm::SectionParser::parseElement):
(JSC::Wasm::SectionParser::parseI32InitExpr):
(JSC::Wasm::SectionParser::parseI32InitExprForElementSection):
(JSC::Wasm::SectionParser::parseI32InitExprForDataSection):
(JSC::Wasm::SectionParser::parseDataSegmentCoreSpec):
(JSC::Wasm::SectionParser::parseDataSegmentReferenceTypesSpec):
(JSC::Wasm::SectionParser::parseGlobalType):
(JSC::Wasm::SectionParser::parseData):
(JSC::Wasm::SectionParser::parseDataCount):
* wasm/WasmSectionParser.h:
* wasm/WasmSections.h:
(JSC::Wasm::validateOrder):
* wasm/WasmSlowPaths.cpp:
(JSC::LLInt::WASM_SLOW_PATH_DECL):
* wasm/WasmSlowPaths.h:
* wasm/js/WebAssemblyModuleRecord.cpp:
(JSC::WebAssemblyModuleRecord::evaluate):
* wasm/wasm.json:

Canonical link: https://commits.webkit.org/232571@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@270948 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
dbezhetskov authored and webkit-commit-queue committed Dec 17, 2020
1 parent f464ad7 commit bae0f9de6be734bd716139fe2675f1128a36de9c
Showing 31 changed files with 14,903 additions and 57 deletions.
@@ -1,3 +1,28 @@
2020-12-17 Dmitry Bezhetskov <dbezhetskov@igalia.com>

[WASM-References] Add support for memory.copy, memory.init and data.drop
https://bugs.webkit.org/show_bug.cgi?id=219943

Reviewed by Yusuke Suzuki.

Added ref-types spec tests for memory.copy, memory.init and data.drop:
https://github.com/WebAssembly/reference-types/tree/master/test/core.
Renamed table_instructions_parse_unreachable test into just
parse_unreachable to prevent confusion.

* wasm.yaml:
* wasm/references-spec-tests/memory_copy.wast.js: Added.
* wasm/references-spec-tests/memory_init.wast.js: Added.
* wasm/references/memory_copy.js: Added.
(async test):
* wasm/references/memory_copy_shared.js: Added.
(async test):
* wasm/references/parse_unreachable.js: Renamed from JSTests/wasm/references/table_instructions_parse_unreachable.js.
(invalidMemoryCopyUnreachable):
(invalidMemoryInitUnreachable):
(invalidDataDropUnreachable):
* wasm/wasm.json:

2020-12-15 Yusuke Suzuki <ysuzuki@apple.com>

[JSC] Accept arbitrary module namespace identifier names
@@ -58,6 +58,10 @@
cmd: runWebAssemblyReferenceSpecTest :normal
- path: wasm/references-spec-tests/memory_fill.wast.js
cmd: runWebAssemblyReferenceSpecTest :normal
- path: wasm/references-spec-tests/memory_copy.wast.js
cmd: runWebAssemblyReferenceSpecTest :normal
- path: wasm/references-spec-tests/memory_init.wast.js
cmd: runWebAssemblyReferenceSpecTest :normal

- path: wasm/multi-value-spec-tests/block.wast.js
cmd: runWebAssemblySpecTest :normal

0 comments on commit bae0f9d

Please sign in to comment.