-
Notifications
You must be signed in to change notification settings - Fork 152
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
Generate atomic module outside of MSP430 #693
Conversation
(rust-highfive has picked a reviewer for you, use r? to override) |
|
We don't use signed integers as raw registers. what about riscv? they can be with/without atomic extention or can have 64 bits |
I didn't know we even supported 64-bit registers. I think I can detect it using I'm not sure how to detect the atomic extension. Maybe I can mention it in the documentation and tell users not to use the atomic flag without the extension. |
I left this comment on the previous PR but it's probably more useful here:
Maybe it's possible to add msp430 to atomic-polyfill so one crate can be used by all architectures (@Dirbaio?). That said, are you sure this is a valid way to operate on MMIO? At least in ARMv7-M, the spec says "LDREX and STREX operations must be performed only on memory with the Normal memory attribute", which doesn't include Device memory for MMIO. In practice on Cortex-M4 it seems like the usual implementation of the global monitor doesn't care about the memory type, so it may end up working despite the spec. The accesses also don't get marked as volatile, so their interaction with the Rust memory model is a bit harder to be sure about, and the compiler might be within its rights to completely optimise out some accesses, either now or in the future. There's some ongoing discussion in these issues. Overall I think this probably needs a bit more thought before it's generated for other platforms, around whether it even makes sense to polyfill atomics on platforms without them (armv6-m for example) and whether it's even legitimate to just stick some AtomicU32 types onto the MMIO memory map. |
For this PR I'm aiming to only add atomic register modification for platforms with instruction-level atomic support. This is why I disabled the Are the concerns about MMIO memory type still relevant in this case? I'm not familiar with ARM so I don't know. As for volatile accesses, according to this issue Rust doesn't support memory accesses with both volatile and atomic semantics, though I believe it's achievable using inline ASM with the right flags (like in |
Ok it turns out that |
@adamgreig what should we do with this PR? Merge or make it draft? |
I'm gonna make it into a draft and wait for the next release of |
I modified the atomic code to match the newest version of |
bors r+ |
Currently the
--nightly
flag generates atomic register modification code for MSP430. This PR expands this code generation to all architectures.