Skip to content

Commit d69ee20

Browse files
gtreptarv-auditor
andauthored
Support memory.copy (#676)
* Add memory.copy to the syntax * Implement memory.copy * Set Version: 0.1.84 * Use `replaceAt` for fill instruction, to be consistent with copy. --------- Co-authored-by: devops <[email protected]>
1 parent d58b104 commit d69ee20

File tree

6 files changed

+54
-5
lines changed

6 files changed

+54
-5
lines changed

package/version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.83
1+
0.1.84

pykwasm/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
44

55
[tool.poetry]
66
name = "pykwasm"
7-
version = "0.1.83"
7+
version = "0.1.84"
88
description = ""
99
authors = [
1010
"Runtime Verification, Inc. <[email protected]>",

pykwasm/src/pykwasm/kdist/wasm-semantics/wasm-text.md

+1
Original file line numberDiff line numberDiff line change
@@ -1142,6 +1142,7 @@ The `align` parameter is for optimization only and is not allowed to influence t
11421142
rule #t2aInstr<_>(memory.size) => memory.size
11431143
rule #t2aInstr<_>(memory.grow) => memory.grow
11441144
rule #t2aInstr<_>(memory.fill) => memory.fill
1145+
rule #t2aInstr<_>(memory.copy) => memory.copy
11451146
11461147
syntax Int ::= #getOffset ( MemArg ) [function, total]
11471148
// -----------------------------------------------------------

pykwasm/src/pykwasm/kdist/wasm-semantics/wasm.md

+50-2
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ The sorts `EmptyStmt` and `EmptyStmts` are administrative so that the empty list
9595
| "memory.size" [symbol(aSize)]
9696
| "memory.grow" [symbol(aGrow)]
9797
| "memory.fill" [symbol(aFill)]
98+
| "memory.copy" [symbol(aCopy)]
9899
// -----------------------------------
99100
100101
syntax TypeUse ::= TypeDecls
@@ -1577,7 +1578,7 @@ The maximum of table size is 2^32 bytes.
15771578
`fill` fills a contiguous section of memory with a value.
15781579
When the section specified goes beyond the bounds of the memory region, that causes a trap.
15791580
If the section has length 0, nothing happens.
1580-
The spec states that this is really a sequence of `i32.store8` instructions, but we use `#setBytesRange` here.
1581+
The spec states that this is really a sequence of `i32.store8` instructions, but we use `replaceAt` here.
15811582
[Memory Fill](https://webassembly.github.io/spec/core/exec/instructions.html#xref-syntax-instructions-syntax-instr-memory-mathsf-memory-fill)
15821583

15831584
```k
@@ -1614,7 +1615,54 @@ The spec states that this is really a sequence of `i32.store8` instructions, but
16141615
</moduleInst>
16151616
<memInst>
16161617
<mAddr> ADDR </mAddr>
1617-
<mdata> DATA => #setBytesRange(DATA, D, padRightBytes(.Bytes, N, VAL)) </mdata>
1618+
<mdata> DATA => replaceAt(DATA, D, padRightBytes(.Bytes, N, VAL)) </mdata>
1619+
...
1620+
</memInst>
1621+
requires notBool N ==Int 0
1622+
```
1623+
1624+
`copy` will copy a section of memory from one location to another.
1625+
The source and destination segments may overlap.
1626+
Similar to `fill`, we perform the entire copy in one internal operation as opposed to
1627+
performing a series of load and store operations as stated in the spec.
1628+
[Memory Copy](https://webassembly.github.io/spec/core/exec/instructions.html#xref-syntax-instructions-syntax-instr-memory-mathsf-memory-copy)
1629+
1630+
```k
1631+
syntax Instr ::= "copyTrap" Int Int Int
1632+
| "copy" Int Int Int
1633+
// ---------------------------------------
1634+
rule <instrs> memory.copy => copyTrap N S D ... </instrs>
1635+
<valstack> < i32 > N : < i32 > S : < i32 > D : VALSTACK => VALSTACK </valstack>
1636+
1637+
rule <instrs> copyTrap N S D => trap ... </instrs>
1638+
<curModIdx> CUR </curModIdx>
1639+
<moduleInst>
1640+
<modIdx> CUR </modIdx>
1641+
<memAddrs> 0 |-> ADDR </memAddrs>
1642+
...
1643+
</moduleInst>
1644+
<memInst>
1645+
<mAddr> ADDR </mAddr>
1646+
<msize> SIZE </msize>
1647+
...
1648+
</memInst>
1649+
requires D +Int N >Int SIZE *Int #pageSize()
1650+
orBool S +Int N >Int SIZE *Int #pageSize()
1651+
1652+
rule <instrs> copyTrap N S D => copy N S D ... </instrs> [owise]
1653+
1654+
rule <instrs> copy 0 _S _D => .K ... </instrs>
1655+
1656+
rule <instrs> copy N S D => .K ... </instrs>
1657+
<curModIdx> CUR </curModIdx>
1658+
<moduleInst>
1659+
<modIdx> CUR </modIdx>
1660+
<memAddrs> 0 |-> ADDR </memAddrs>
1661+
...
1662+
</moduleInst>
1663+
<memInst>
1664+
<mAddr> ADDR </mAddr>
1665+
<mdata> DATA => replaceAt(DATA, D, #getBytesRange(DATA, S, N)) </mdata>
16181666
...
16191667
</memInst>
16201668
requires notBool N ==Int 0

pykwasm/src/pykwasm/kwasm_ast.py

+1
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,7 @@ def I64_LOAD32_S(offset: int) -> KInner:
581581
MEMORY_GROW = KApply('aGrow', [])
582582
MEMORY_SIZE = KApply('aSize', [])
583583
MEMORY_FILL = KApply('aFill', [])
584+
MEMORY_COPY = KApply('aCopy', [])
584585

585586
#######################
586587
# Global Instructions #

tests/conformance/unparseable.txt

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ if.wast
1212
imports.wast
1313
loop.wast
1414
memory.wast
15-
memory_copy.wast
1615
memory_init.wast
1716
select.wast
1817
tokens.wast

0 commit comments

Comments
 (0)