Skip to content

Commit 857d969

Browse files
committed
Refactor store buffer search conditions
1 parent e215eda commit 857d969

File tree

1 file changed

+30
-42
lines changed

1 file changed

+30
-42
lines changed

src/weak_memory.rs

+30-42
Original file line numberDiff line numberDiff line change
@@ -248,59 +248,47 @@ impl<'mir, 'tcx: 'mir> StoreBuffer {
248248
if !keep_searching {
249249
return false;
250250
}
251-
// CoWR: if a store happens-before the current load,
252-
// then we can't read-from anything earlier in modification order.
253-
if store_elem.timestamp <= clocks.clock[store_elem.store_index] {
254-
log::info!("Stopped due to coherent write-read");
255-
keep_searching = false;
256-
return true;
257-
}
258251

259-
// CoRR: if there was a load from this store which happened-before the current load,
260-
// then we cannot read-from anything earlier in modification order.
261-
if store_elem.loads.borrow().iter().any(|(&load_index, &load_timestamp)| {
252+
keep_searching = if store_elem.timestamp <= clocks.clock[store_elem.store_index] {
253+
// CoWR: if a store happens-before the current load,
254+
// then we can't read-from anything earlier in modification order.
255+
log::info!("Stopping due to coherent write-read");
256+
false
257+
} else if store_elem.loads.borrow().iter().any(|(&load_index, &load_timestamp)| {
262258
load_timestamp <= clocks.clock[load_index]
263259
}) {
264-
log::info!("Stopped due to coherent read-read");
265-
keep_searching = false;
266-
return true;
267-
}
268-
269-
// The current load, which may be sequenced-after an SC fence, can only read-from
270-
// the last store sequenced-before an SC fence in another thread (or any stores
271-
// later than that SC fence)
272-
if store_elem.timestamp <= clocks.fence_seqcst[store_elem.store_index] {
273-
log::info!("Stopped due to coherent load sequenced after sc fence");
274-
keep_searching = false;
275-
return true;
276-
}
277-
278-
// The current non-SC load can only read-from the latest SC store (or any stores later than that
279-
// SC store)
280-
if store_elem.timestamp <= clocks.write_seqcst[store_elem.store_index]
260+
// CoRR: if there was a load from this store which happened-before the current load,
261+
// then we cannot read-from anything earlier in modification order.
262+
log::info!("Stopping due to coherent read-read");
263+
false
264+
} else if store_elem.timestamp <= clocks.fence_seqcst[store_elem.store_index] {
265+
// The current load, which may be sequenced-after an SC fence, can only read-from
266+
// the last store sequenced-before an SC fence in another thread (or any stores
267+
// later than that SC fence)
268+
log::info!("Stopping due to coherent load sequenced after sc fence");
269+
false
270+
} else if store_elem.timestamp <= clocks.write_seqcst[store_elem.store_index]
281271
&& store_elem.is_seqcst
282272
{
283-
log::info!("Stopped due to needing to load from the last SC store");
284-
keep_searching = false;
285-
return true;
286-
}
287-
288-
// The current SC load can only read-from the last store sequenced-before
289-
// the last SC fence (or any stores later than the SC fence)
290-
if is_seqcst && store_elem.timestamp <= clocks.read_seqcst[store_elem.store_index] {
291-
log::info!("Stopped due to sc load needing to load from the last SC store before an SC fence");
292-
keep_searching = false;
293-
return true;
294-
}
273+
// The current non-SC load can only read-from the latest SC store (or any stores later than that
274+
// SC store)
275+
log::info!("Stopping due to needing to load from the last SC store");
276+
false
277+
} else if is_seqcst && store_elem.timestamp <= clocks.read_seqcst[store_elem.store_index] {
278+
// The current SC load can only read-from the last store sequenced-before
279+
// the last SC fence (or any stores later than the SC fence)
280+
log::info!("Stopping due to sc load needing to load from the last SC store before an SC fence");
281+
false
282+
} else {true};
295283

296284
true
297285
})
298286
.filter(|&store_elem| {
299-
if is_seqcst {
287+
if is_seqcst && store_elem.is_seqcst {
300288
// An SC load needs to ignore all but last store maked SC (stores not marked SC are not
301289
// affected)
302-
let include = !(store_elem.is_seqcst && found_sc);
303-
found_sc |= store_elem.is_seqcst;
290+
let include = !found_sc;
291+
found_sc = true;
304292
include
305293
} else {
306294
true

0 commit comments

Comments
 (0)