-
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
Behavior of t.atomic.rmw.cmpxchg
instructions
#195
Comments
Ah, there are unfortunate mistakes in the draft spec text here. The overview correctly describes the intended behaviour, which is the same as the C++ |
Hi @conrad-watt , Another question is that according to the overview:
But take the test suite for example:
When invoking the Thanks. |
Oh dear. You've identified an interesting discrepancy, and it looks like there is real implementation divergence here. The culprit is the line in the overview which governs how value comparison works. It states that for Running the following test, it appears that Chrome and Firefox implement the overview semantics, while Safari implements the test suite semantics.
|
Well... now we have to work out which is the preferable semantics. Thanks for discovering this @q82419 :) @dtig who would be the right person to ask regarding V8's code generation? Is the current V8 semantics implemented by wrapping the expected value to the packed width as a separate platform asm instruction, or is there an asm instruction that directly implements sub-32-bit |
@Constellation it looks like WebKit's behaviour is the odd one out here, although the fault lies with the reference interpreter for implementing this behaviour in the first place (as seen in the tests added here, which pass in the reference interpreter but should fail according to the overview). In principle, would it be possible to change the behaviour here to align with V8 and SpiderMonkey? (we would also change the reference interpreter and relevant tests). |
@conrad-watt |
Please refer to this issue: WebAssembly/threads#195 Signed-off-by: YiYing He <[email protected]>
Please refer to this issue: WebAssembly/threads#195 Signed-off-by: YiYing He <[email protected]>
Please refer to this issue: WebAssembly/threads#195 Signed-off-by: YiYing He <[email protected]>
Please refer to this issue: WebAssembly/threads#195 Signed-off-by: YiYing He <[email protected]>
To bump this: the spec, interpreter, and tests in upstream-rebuild, and the spec render at https://webassembly.github.io/threads/ (see #198), should now reflect the following:
Please let me know if any remaining artefacts fail to reflect the above. I'll flag these issues up again at the in-person meeting, since there really was an unfortunate divergence here. |
https://bugs.webkit.org/show_bug.cgi?id=263292 rdar://117102231 Reviewed by NOBODY (OOPS!). In WebAssembly/threads#195, it was documented that JSC implements cmpxchg_u without wrapping the expected value. Previously, the spec tests and reference interpreter followed this interpretation, but the spec text, SpiderMonkey and v8 did the wrapping. The spec tests were updated, and this new behaviour is simpler anyway, so let's just do it. * JSTests/wasm/spec-tests/atomic.wast.js: Added. * JSTests/wasm/spec-tests/binary-leb128.wast.js: * JSTests/wasm/spec-tests/binary.wast.js: * JSTests/wasm/spec-tests/br_table.wast.js: * JSTests/wasm/spec-tests/elem.wast.js: * JSTests/wasm/spec-tests/float_literals.wast.js: * JSTests/wasm/threads-spec-tests/atomic-signed.wast.js: * Source/JavaScriptCore/llint/WebAssembly64.asm: * Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::emitAtomicCompareExchange): * Source/JavaScriptCore/wasm/WasmBBQJIT.cpp: (JSC::Wasm::BBQJIT::emitAtomicCompareExchange):
https://bugs.webkit.org/show_bug.cgi?id=263292 rdar://117102231 Reviewed by NOBODY (OOPS!). In WebAssembly/threads#195, it was documented that JSC implements cmpxchg_u without wrapping the expected value. Previously, the spec tests and reference interpreter followed this interpretation, but the spec text, SpiderMonkey and v8 did the wrapping. The spec tests were updated, and this new behaviour is simpler anyway, so let's just do it. * JSTests/wasm/spec-tests/atomic.wast.js: Added. * JSTests/wasm/spec-tests/binary-leb128.wast.js: * JSTests/wasm/spec-tests/binary.wast.js: * JSTests/wasm/spec-tests/br_table.wast.js: * JSTests/wasm/spec-tests/elem.wast.js: * JSTests/wasm/spec-tests/float_literals.wast.js: * JSTests/wasm/threads-spec-tests/atomic-signed.wast.js: * Source/JavaScriptCore/llint/WebAssembly32_64.asm: * Source/JavaScriptCore/llint/WebAssembly64.asm: * Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::emitAtomicCompareExchange): * Source/JavaScriptCore/wasm/WasmBBQJIT.cpp: (JSC::Wasm::BBQJIT::emitAtomicCompareExchange):
https://bugs.webkit.org/show_bug.cgi?id=263292 rdar://117102231 Reviewed by Justin Michaud and Yusuke Suzuki. In WebAssembly/threads#195, it was documented that JSC implements cmpxchg_u without wrapping the expected value. Previously, the spec tests and reference interpreter followed this interpretation, but the spec text, SpiderMonkey and v8 did the wrapping. The spec tests were updated, and this new behaviour is simpler anyway, so let's just do it. * JSTests/wasm/spec-tests/atomic.wast.js: Added. * JSTests/wasm/spec-tests/binary-leb128.wast.js: * JSTests/wasm/spec-tests/binary.wast.js: * JSTests/wasm/spec-tests/br_table.wast.js: * JSTests/wasm/spec-tests/elem.wast.js: * JSTests/wasm/spec-tests/float_literals.wast.js: * JSTests/wasm/threads-spec-tests/atomic-signed.wast.js: * Source/JavaScriptCore/llint/WebAssembly32_64.asm: * Source/JavaScriptCore/llint/WebAssembly64.asm: * Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::emitAtomicCompareExchange): * Source/JavaScriptCore/wasm/WasmBBQJIT.cpp: (JSC::Wasm::BBQJIT::emitAtomicCompareExchange): Canonical link: https://commits.webkit.org/270828@main
Please refer to this issue: WebAssembly/threads#195 Signed-off-by: YiYing He <[email protected]>
Please refer to this issue: WebAssembly/threads#195 Signed-off-by: YiYing He <[email protected]>
Please refer to this issue: WebAssembly/threads#195 Signed-off-by: YiYing He <[email protected]>
Please refer to this issue: WebAssembly/threads#195 Signed-off-by: YiYing He <[email protected]>
Please refer to this issue: WebAssembly/threads#195 Signed-off-by: YiYing He <[email protected]>
Hi,
As the 17. and 18. steps in the spec:
And the 21. step will write the
c
back to the memory.Where c1 is the origin value on the memory, c2 is the expected value, c3 is the value to replace.
Maybe I can realize this as following simply:
But the closest function in C++
std::atomic<T>::compare_exchange_strong
has the different behavior.The
atomic_rmw
instructions are similar to the member functions ofstd::atomic<T>
in C++ STL, such asfetch_add()
,fetch_xor
, etc.Is it necessary to have the same behavior between
cmpxchg
instructions andstd::atomic<T>::compare_exchange_strong
in C++?Thanks.
The text was updated successfully, but these errors were encountered: