fix(compiler): a block table entry put in beside its older self takes that one out of the set and every jump cache, where a jump cache kept entering the older block and BTYPEs and the older entry came back

This commit is contained in:
Tyler Smith committed 2026-11-19 16:17:49 -05:00
1 parent e3b2455e46
commit 6a1fe6e337
3 files changed
+69 -4

No files matched your search

+15 -3
View File
@@ -1628,6 +1628,12 @@ impl LookupTable {
/// a lookup keeps reaching put each other out, round after round,
/// while a third that nothing reaches stayed: a random victim leaves
/// that third the one out after a few rounds.
///
/// The entry's older self beside it, which a resident put there, leaves
/// the set, its place free for the resident, and its PC the jump caches
/// ([`Self::put`]). Kept, it would come back when the new entry leaves,
/// and a jump cache entry filled from it would go on entering the block
/// and BTYPEs it named while the probes take the new entry's.
pub fn insert(&mut self, slot: usize, entry: LookupEntry) {
if self.grouping == Grouping::Pc {
self.note_rekey(slot, &entry);
@@ -1636,9 +1642,15 @@ impl LookupTable {
if resident == entry {
return;
}
if resident.key != 0 && (resident.pc != entry.pc || resident.key != entry.key) {
let beside = self.entry(neighbour(slot));
let keep_resident = if beside.key == 0 {
let beside = self.entry(neighbour(slot));
let older_beside = beside.key != 0 && beside.pc == entry.pc && beside.key == entry.key;
let other_resident =
resident.key != 0 && (resident.pc != entry.pc || resident.key != entry.key);
if older_beside && !other_resident {
self.put(neighbour(slot), LookupEntry::default());
}
if other_resident {
let keep_resident = if beside.key == 0 || older_beside {
true
} else {
self.victims ^= self.victims << 13;
@@ -370,3 +370,53 @@ fn empty_and_replaced_entries_take_the_probe() {
world.table.clear();
assert_eq!(held(), 0);
}
/// An entry another PC's put beside its slot, then replaced there with the
/// slot empty again or held: the older entry leaves its set and the jump
/// caches, so a branch tail of a BTYPE the new entry refuses exits as the
/// probe does, where the cache's entry of the older one entered, and the
/// older one never comes back when the new one leaves.
#[test]
fn an_older_entry_beside_its_replacement_leaves_with_its_cache_entry() {
const PC: u64 = 0x4_0000_0200;
let key = block_key(0x4000_0000, 1);
let branch = (PC, ExitKind::Indirect as u64 | (RAN as u64) << 20);
for slot_held in [false, true] {
let mut world = World::new();
let slot = world.table.slot(PC, key);
// Another PC whose entry takes the same slot.
let other = (1..1 << 20)
.map(|step| PC + 0x1000 * step)
.find(|&pc| world.table.slot(pc, key) == slot)
.expect("a PC of the same slot");
let resident = LookupEntry {
pc: other,
key,
entry: world.blocks.0 as u64 + 64 * 7,
block: 7,
targets: 0b1111,
};
world.map(PC, key, 2, 0b1111);
// The other PC's entry puts it beside the slot.
world.table.insert(slot, resident);
assert_eq!(world.table.entry(neighbour(slot)).pc, PC);
// Filled by the BTYPE 2 probe from the entry beside, which accepts
// BTYPE 2, and taken from the cache.
assert_eq!(world.run(32, PC), (0x7702, 99));
assert_eq!(world.run(32, PC), (0x7702, 99));
if !slot_held {
world.table.forget_block(other, key, 7);
}
// The same block again, refusing BTYPE 2.
world.map(PC, key, 2, 0b0011);
assert_eq!(world.run(32, PC), branch, "slot held {slot_held}");
assert_eq!(world.table.entry(slot).targets, 0b0011);
let beside = world.table.entry(neighbour(slot));
assert_eq!(beside.pc, if slot_held { other } else { 0 });
// The new entry leaves with its block; nothing of the PC is left.
world.table.set(slot, LookupEntry::default());
let held = world.table.find(slot, PC, key);
assert!(!(held.pc == PC && held.key == key), "slot held {slot_held}");
assert_eq!(world.run(0, PC), exit(PC, ExitKind::Return));
}
}
@@ -306,11 +306,14 @@ fn stamped_tails_transfer_as_their_cell_tails() {
0 => &CONTEXTS[..],
_ => &contexts[1..],
};
// The cell probe then exits, or takes the table's entry of the key
// the ITLB holds now, which may be another block or the same one,
// counted as a table probe's.
let evicted = translated != Some(cell.key)
&& stamped_in
.iter()
.any(|&context| keys.get(&(page, context)) == Some(&cell.key))
&& rb == exit
&& (rb == exit || rb.1 == 99)
&& linked.is_some_and(|linked| linked.entry == cell.entry)
&& (ra == (0x7700 + u64::from(cell.block), 99)
// Or no budget: the stamped tail spent it, as a transfer.