Title bytes under flights' writes compared with AVX2 on threads of their own, the pairs sent up made on them; helpers that work ahead are not kept on the fast cores

VICTORY_UNDER_WIDE=0, VICTORY_UNDER_THREADS (6), VICTORY_FAST_CORES=3 (as before: all of them), VICTORY_WIDE_SPIN=<us> (0: off).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
localandClaude Opus 5.5 committed 2026-11-25 14:23:12 -06:00
1 parent 95037baf2a
commit b6202840aa
6 files changed
+306 -82

No files matched your search

+22 -4
View File
@@ -186,6 +186,9 @@ pub(super) struct Own {
copies: Vec<Copy>,
}
/// Runs whose pairs are one piece of work.
const RUNS_AT_A_TIME: usize = 4096;
/// Takes what `dirty` sends up out of the CPU sides.
pub(super) fn take(host: &Host, dirty: &[(std::sync::Arc<Shadow>, Vec<(usize, usize)>)]) -> Option<Own> {
let began = std::time::Instant::now();
@@ -210,15 +213,29 @@ pub(super) fn take(host: &Host, dirty: &[(std::sync::Arc<Shadow>, Vec<(usize, us
}
let memory = memory(host, at)?;
let mut moves: Vec<(usize, usize, usize)> = Vec::new();
let mut work: Vec<(usize, &[(usize, usize)], usize)> = Vec::new();
for ((shadow, ranges), copy) in dirty.iter().zip(&copies) {
let from = shadow.card_data() as usize;
moves.extend(copy.runs.iter().map(|&(a, to, n)| (from + a, memory.data + to as usize, n)));
let mut to = (memory.data + copy.pairs.0 as usize) as *mut [u32; 2];
// (80,000 runs of some words a frame: in pieces of work.)
let mut to = memory.data + copy.pairs.0 as usize;
for ranges in ranges.chunks(RUNS_AT_A_TIME) {
let words: usize = ranges.iter().filter(|r| short(r)).map(|r| (r.1 - r.0) / 4).sum();
if words > 0 {
work.push((from, ranges, to));
to += words * 8;
}
}
}
let one = |i: usize| {
let (from, ranges, to) = work[i];
let mut to = to as *mut [u32; 2];
for &(a, b) in ranges.iter().filter(|r| short(r)) {
for offset in (a..b).step_by(4) {
// SAFETY: inside the copy's mapping (its CPU side, which
// this thread alone writes in these ranges) and inside the
// memory, which has room for every pair.
// the thread that asked, and waits, alone writes in these
// ranges) and inside the memory, which has room for every
// pair, a piece of work's behind the last one's.
unsafe {
let word = ((from + offset) as *const u32).read_unaligned();
to.write([offset as u32, word]);
@@ -226,7 +243,8 @@ pub(super) fn take(host: &Host, dirty: &[(std::sync::Arc<Shadow>, Vec<(usize, us
}
}
}
}
};
crate::land::each_under(work.len(), &one);
STATS[0].fetch_add(moves.iter().map(|m| m.2 as u64).sum(), Ordering::Relaxed);
STATS[1].fetch_add(moves.len() as u64, Ordering::Relaxed);
STATS[2].fetch_add(copies.iter().map(|c| u64::from(c.pairs.1)).sum(), Ordering::Relaxed);
+7 -1
View File
@@ -24,9 +24,15 @@ static MOVED: Mutex<Option<HashMap<(u64, u64), Moved>>> = Mutex::new(None);
pub(super) fn moved(way: usize, span: (u64, u64), ranges: impl Iterator<Item = (usize, usize)>) {
let mut all = MOVED.lock().unwrap_or_else(|e| e.into_inner());
let m = all.get_or_insert_with(Default::default).entry(span).or_default();
// (Thousands of runs lie in one piece, one after the other.)
let mut last = u32::MAX;
for (from, to) in ranges.filter(|r| r.0 < r.1) {
m.bytes[way] += (to - from) as u64;
m.pieces[way].extend((from >> 16) as u32..=((to - 1) >> 16) as u32);
let (first, end) = ((from >> 16) as u32, ((to - 1) >> 16) as u32);
if (first, end) != (last, last) {
m.pieces[way].extend(first..=end);
}
last = end;
}
}