-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Semantics of bulk memory operations #225
Comments
Currently the specification is just unordered byte writes (it would be equivalent to have one big tearing unordered write). This is a deliberate choice which means that any racing read may independently non-deterministically see an arbitrary mixture of "before" bytes and "after" bytes, effectively blessing [almost?] any reasonable implementation as conformant (including optimised strategies involving vectors etc). Because we have a full eager bounds check on the entire range of the bulk instruction before any writes take place, this non-determinism is only visible to racing reads (analogy - C undefined behaviour), not to any correctly synchronized code, or any code that synchronously inspects the memory after an OOB trap. We did previously agree that if any future feature is able to interrupt a bulk instruction midway after the initial bounds check (e.g. dynamic page write protection), the specified result would be a memory state where each byte write of the bulk instruction may have independently non-deterministically happened or not happened - we haven't had to put this into practice yet! It's true that calling out to a fully abstract C |
Thanks for clarifying.
So the intended implementer guidance is "reason at the level of the ISA"? There's currently a discrepancy between |
Yes, for maximum performance. |
To me it looks like Relaxed_Memmove itself contains an UB from C++ point of view. Does the C++ standard guaranty that atomic and T are the same thing and can be casted to each other like this?
|
Yep, good eye. This is UB, though V8 does depend on it everywhere. I think since C++20's (In my mind, and this isn't a very strong argument, this is like how everyone depends on type punning.) |
The semantics of bulk memory operations on shared linear memory seems to be currently underspecified. If the memory model is mostly the same as JS's, I assume these should be unordered atomic.
AFAICT V8's current implementation is also unsafe in that it just calls out to C
memmove
andmemcpy
under the hood, which are non-atomic.@conrad-watt should know best.
The text was updated successfully, but these errors were encountered: