Improve SC comments

This commit is contained in:
Andy Wang 2022-08-25 00:07:17 +01:00
parent bb8212484f
commit f4ba8b1160
No known key found for this signature in database
GPG Key ID: 181B49F9F38F3374

View File

@ -319,6 +319,7 @@ fn fetch_store<R: rand::Rng + ?Sized>(
keep_searching = if store_elem.timestamp <= clocks.clock[store_elem.store_index] {
// CoWR: if a store happens-before the current load,
// then we can't read-from anything earlier in modification order.
// C++20 §6.9.2.2 [intro.races] paragraph 18
log::info!("Stopping due to coherent write-read");
false
} else if store_elem.loads.borrow().iter().any(|(&load_index, &load_timestamp)| {
@ -326,24 +327,27 @@ fn fetch_store<R: rand::Rng + ?Sized>(
}) {
// CoRR: if there was a load from this store which happened-before the current load,
// then we cannot read-from anything earlier in modification order.
// C++20 §6.9.2.2 [intro.races] paragraph 16
log::info!("Stopping due to coherent read-read");
false
} else if store_elem.timestamp <= clocks.fence_seqcst[store_elem.store_index] {
// The current load, which may be sequenced-after an SC fence, can only read-from
// the last store sequenced-before an SC fence in another thread (or any stores
// later than that SC fence)
// The current load, which may be sequenced-after an SC fence, cannot read-before
// the last store sequenced-before an SC fence in another thread.
// C++17 §32.4 [atomics.order] paragraph 6
log::info!("Stopping due to coherent load sequenced after sc fence");
false
} else if store_elem.timestamp <= clocks.write_seqcst[store_elem.store_index]
&& store_elem.is_seqcst
{
// The current non-SC load can only read-from the latest SC store (or any stores later than that
// SC store)
// The current non-SC load, which may be sequenced-after an SC fence,
// cannot read-before the last SC store executed before the fence.
// C++17 §32.4 [atomics.order] paragraph 4
log::info!("Stopping due to needing to load from the last SC store");
false
} else if is_seqcst && store_elem.timestamp <= clocks.read_seqcst[store_elem.store_index] {
// The current SC load can only read-from the last store sequenced-before
// the last SC fence (or any stores later than the SC fence)
// The current SC load cannot read-before the last store sequenced-before
// the last SC fence.
// C++17 §32.4 [atomics.order] paragraph 5
log::info!("Stopping due to sc load needing to load from the last SC store before an SC fence");
false
} else {true};