@@ -95,6 +95,7 @@ The sorts `EmptyStmt` and `EmptyStmts` are administrative so that the empty list
95
95
| "memory.size" [symbol(aSize)]
96
96
| "memory.grow" [symbol(aGrow)]
97
97
| "memory.fill" [symbol(aFill)]
98
+ | "memory.copy" [symbol(aCopy)]
98
99
// -----------------------------------
99
100
100
101
syntax TypeUse ::= TypeDecls
@@ -1577,7 +1578,7 @@ The maximum of table size is 2^32 bytes.
1577
1578
` fill ` fills a contiguous section of memory with a value.
1578
1579
When the section specified goes beyond the bounds of the memory region, that causes a trap.
1579
1580
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.
1581
1582
[ Memory Fill] ( https://webassembly.github.io/spec/core/exec/instructions.html#xref-syntax-instructions-syntax-instr-memory-mathsf-memory-fill )
1582
1583
1583
1584
``` k
@@ -1614,7 +1615,54 @@ The spec states that this is really a sequence of `i32.store8` instructions, but
1614
1615
</moduleInst>
1615
1616
<memInst>
1616
1617
<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>
1618
1666
...
1619
1667
</memInst>
1620
1668
requires notBool N ==Int 0
0 commit comments