Use portable-atomic on platforms without u64 atomics#23
Use portable-atomic on platforms without u64 atomics#23linkmauve wants to merge 1 commit intonot-fl3:masterfrom
Conversation
This has been tested on powerpc-unknown-linux-gnu, which supports
atomics only up to u32. Without this commit, building quad-rand would
fail with:
error[E0432]: unresolved import `core::sync::atomic::AtomicU64`
--> src/lib.rs:5:26
|
5 | use core::sync::atomic::{AtomicU64, Ordering};
| ^^^^^^^^^
| |
| no `AtomicU64` in `sync::atomic`
| help: a similar name exists in the module: `AtomicU32`
| rand = { version = "0.8", optional = true } | ||
|
|
||
| [target.'cfg(not(target_has_atomic = "64"))'.dependencies] | ||
| portable-atomic = "1" |
There was a problem hiding this comment.
To be honest, for quad-rand I would rather use two AtomicU32. portable-atomic is a really big crate and we use so little of it. Even with default-features = false cargo will always download all this code, and iirc it even downloads feature-gated crates.
There was a problem hiding this comment.
Do you suggest lowering RandGenerator::state to an AtomicU32 and changing the algorithm, or using two of them and decomposing the operation into non-atomic operations?
I don’t directly use quad-rand, but it is a dependency of kira which I’m using in my game engine, so I don’t have much opinion on that matter.
Edit: My bad, I had misread your message. I’m not sure I know the maths to emulate u64 wrapping add and multiply using u32, and besides that would render the whole operation non-atomic. Maybe using a Mutex<u64> would be nicer?
There was a problem hiding this comment.
I doubt it would be possible to keep it atomic if AtomicU64 is not supported?
This has been tested on
powerpc-unknown-linux-gnu, which supports atomics only up tou32. Without this commit, building quad-rand would fail with: