You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copying and clearing large memory regions is very common, and making these
operations fast is architecture dependent. Although this can be done in the MVP
via i32.load and i32.store, this requires more bytes of code and forces VMs
to recognize the loops as well. The following operators can be added to improve
performance:
move_memory: Copy data from a source memory region to destination region;
these regions may overlap: the copy is performed as if the source region was
first copied to a temporary buffer, then the temporary buffer is copied to
the destination region
set_memory: Set all bytes in a memory region to a given byte
We expect that WebAssembly producers will use these operations when the region
size is known to be large, and will use loads/stores otherwise.
I'm a little concerned about how the temp buffer interacts with shared memory and observability of reads and writes since, in practice, we'll want to avoid using such a buffer. Specifically, the agent that performs the copying creates an order s.t. all reads from the source and writes to the temp buffer are ordered before all reads from the temp buffer and writes to the destination. Another agent can be writing to the source and reading from the target to see what happens; almost certainly that agent can observe that the ordering implied by the temp buffer is violated.
Now, that violation might be allowed by the memory model anyway, since move_memory performs all racy reads and writes. (What memory model? I hear you ask :-) So no big deal, maybe.
Still, I have this nagging thought that we should perhaps spec move_memory by cases (not overlapping; overlapping with src <= target; overlapping with src > target) to avoid unnecessary confusion. Also it would clarify the performance aspect of the instruction somewhat better, since the redundant copy makes it seem more expensive than it is.
This still uses a temp buffer, but I think it makes it clearer that it is just a spec implementation detail. Probably could add a note to that effect as well.
Activity
binji commentedon Jul 24, 2017
cc @jfbastien
[-]Bulk memory operations[/-][+]🛤 Bulk memory operations[/+]lars-t-hansen commentedon Aug 7, 2017
I'm a little concerned about how the temp buffer interacts with shared memory and observability of reads and writes since, in practice, we'll want to avoid using such a buffer. Specifically, the agent that performs the copying creates an order s.t. all reads from the source and writes to the temp buffer are ordered before all reads from the temp buffer and writes to the destination. Another agent can be writing to the source and reading from the target to see what happens; almost certainly that agent can observe that the ordering implied by the temp buffer is violated.
Now, that violation might be allowed by the memory model anyway, since
move_memoryperforms all racy reads and writes. (What memory model? I hear you ask :-) So no big deal, maybe.Still, I have this nagging thought that we should perhaps spec
move_memoryby cases (not overlapping; overlapping with src <= target; overlapping with src > target) to avoid unnecessary confusion. Also it would clarify the performance aspect of the instruction somewhat better, since the redundant copy makes it seem more expensive than it is.binji commentedon Aug 7, 2017
I wrote up a quick gist w/ some spec text here: https://gist.github.com/binji/acc43b94c0a747e51dfafa1b5b099c9a
This still uses a temp buffer, but I think it makes it clearer that it is just a spec implementation detail. Probably could add a note to that effect as well.
binji commentedon Oct 16, 2018
Moved to WebAssembly/proposals#18.