Transposition Table Layout B (64-Byte Cache Line)
Cache-aligned 64-byte buckets with two 24-byte atomic slots, 8-bit key prefilter tag, and tabulation torn-read rejection.
Why does BalouChess do this?
Different move orders constantly reach the exact same chess position. The transposition table remembers previously searched positions — their best move, search bound, depth, and raw static evaluation — so BalouChess can cut off redundant subtrees immediately.
Today a single search thread uses the table. Its format is already safe for several threads without locks, as the planned multi-core search will need: two threads writing to the same slot at once could otherwise mix half of one entry with half of another. BalouChess aligns every bucket to a single 64-byte CPU cache line (Layout B) and verifies an atomic 64-bit check word across the words so torn reads are detected and discarded.
[X-RAY CARD 02 // 64-BYTE LAYOUT-B CACHE LINE INSPECTOR]
Lock-Free 64-Byte Bucket & Torn-Write Detector
64-Byte CPU Cache Line (2 × 24 B Slots + 16 B Alignment Reserve) (64 B)
Data Layout, Invariants & Common Pitfalls
Memory & State Layout
Each 64-byte cache-line-aligned bucket holds 2 × 24-byte slots plus 16 padding bytes (engine, SPEC 004 §8). Each 24-byte slot consists of three 64-bit atomic words: data (16-bit move, lossless 15-bit signed static eval up to ±16,383 cp, 33-bit SearchValue including mate/TB ply distance), meta (16-bit depth, 16-bit age, 2-bit bound/empty tag, reserved feature bits, and an 8-bit key prefilter tag in bits 56..63), and a 64-bit verification word protecting the full key across both payload words.
Formal Invariants
- Memory-safe lock-free access (engine, SPEC 004/R2, R3): crates/tables/src/transposition enforces #![forbid(unsafe_code)] using 64-bit atomics; any torn mixture of two concurrent writes passes verification with probability no higher than a random 64-bit key collision, and any surviving move is re-checked via Position::is_legal (engine, SPEC 004/R4).
- Strict type-level neural quarantine (engine, SPEC 004/R9): only crates/search can write to the transposition table, accepting SearchValue and Bound exclusively — NetWdl values from neural hints cannot compile into a table store.
Typical Pitfalls & Edge Cases
- Mate score ply-relative corruption (engine, SPEC 003/R3): a mate in N plies from the root is a mate in (N - ply) plies from the current node; forgetting to normalize mate distances on store and un-normalize on probe produces phantom mates when reached at a different ply.
- Graph History Interaction (engine, SPEC 003/R4, engine, SPEC 004/R12): PositionKey encodes the board, not the repetition path or 50-move counter; BalouChess always checks draw-by-repetition and 50-move draw in the node before trusting any transposition table cutoff.